common.py: allow specifying number of attempts in exec_cmd 01/15001/2
authorJosep Puigdemont <josep.puigdemont@enea.com>
Fri, 6 May 2016 01:28:26 +0000 (03:28 +0200)
committerJosep Puigdemont <josep.puigdemont@gmail.com>
Wed, 15 Jun 2016 14:42:19 +0000 (14:42 +0000)
commit874ca3f24d349ee844bb7339dda34eddb2e91c73
tree944a5e9127817bbb9b5d65521311b5297fe611b5
parentf9e8c1a361d3673df9fcde83e46d265ed49fa499
common.py: allow specifying number of attempts in exec_cmd

Some commands executed by exec_cmd may fail because of a temporary
cause, and it may be desirable to retry the same command several times
until it succeeds. One example of this are the ipmitool commands, which
may fail temorarily on some targets if they get too many requests
simultaneously.

In this patch three new optional parameters are introduced to the
function signature, which do not break backward compatibility:
  attempts: which indicates how many times the command should be run if
            it returns a non-zero value*, and defaults to 1 (as today).
  delay:    which indicates the delay in seconds between attempts, and
            defaults to 5 seconds.
  verbose:  It will print the remaining attempts left for the current
            command if set to True.

* It may be desirable to add yet another parameter to indicate what
  return value should be considered an error, but non-zero for now
  seems a reasonable default.

Signed-off-by: Josep Puigdemont <josep.puigdemont@enea.com>
deploy/common.py