Fix retry counter delays
Change-Id: Ia56e21d301730f4ad5be777b512405f1b7ca4305
diff --git a/tcp_tests/managers/execute_commands.py b/tcp_tests/managers/execute_commands.py
index 3c01867..29e2f4b 100644
--- a/tcp_tests/managers/execute_commands.py
+++ b/tcp_tests/managers/execute_commands.py
@@ -64,18 +64,20 @@
# skip_fail = step.get('skip_fail', False)
msg = "[ {0} #{1} ] {2}".format(label, n + 1, description)
- LOG.info("\n\n{0}\n{1}".format(msg, '=' * len(msg)))
if action_cmd:
- self.execute_command(step)
+ self.execute_command(step, msg)
+ return
elif action_do:
- self.command2(step)
- elif action_upload:
+ self.command2(step, msg)
+ return
+ LOG.info("\n\n{0}\n{1}".format(msg, '=' * len(msg)))
+ if action_upload:
self.action_upload(step)
elif action_download:
self.action_download(step)
- def execute_command(self, step):
+ def execute_command(self, step, msg):
# Required fields
cmd = step.get('cmd')
node_name = step.get('node_name')
@@ -90,7 +92,13 @@
for x in range(retry_count, 0, -1):
time.sleep(3)
- result = remote.execute(cmd, verbose=True)
+
+ retry_msg = ' (try {0} of {1}, skip_fail={2})'.format(
+ retry_count - x + 1, retry_count, skip_fail)
+ LOG.info("\n\n{0}\n{1}".format(
+ msg + retry_msg, '=' * len(msg + retry_msg)))
+
+ result = remote.execute('set -ex; ' + cmd, verbose=True)
# Workaround of exit code 0 from salt in case of failures
failed = 0
@@ -106,16 +114,11 @@
if result.exit_code != 0:
time.sleep(retry_delay)
- LOG.info(
- " === RETRY ({0}/{1}) ========================="
- .format(x - 1, retry_count))
elif failed != 0:
LOG.error(
" === SALT returned exit code = 0 while "
"there are failed modules! ===")
- LOG.info(
- " === RETRY ({0}/{1}) ======================="
- .format(x - 1, retry_count))
+ time.sleep(retry_delay)
else:
break
@@ -124,7 +127,7 @@
raise Exception("Step '{0}' failed"
.format(description))
- def command2(self, step):
+ def command2(self, step, msg):
# Required fields
do = step['do']
target = step['target']
@@ -145,6 +148,11 @@
for x in range(retry_count, 0, -1):
time.sleep(3)
+ retry_msg = ' (try {0} of {1}, skip_fail={2})'.format(
+ retry_count - x + 1, retry_count, skip_fail)
+ LOG.info("\n\n{0}\n{1}".format(
+ msg + retry_msg, '=' * len(msg + retry_msg)))
+
method = getattr(self._salt, self._salt._map[do])
command_ret = method(tgt=target, state=state or states,
args=args, kwargs=kwargs)
@@ -163,8 +171,6 @@
LOG.error("States finished with failures.\n{}".format(
all_fails))
time.sleep(retry_delay)
- LOG.info(" === RETRY ({0}/{1}) ========================="
- .format(x - 1, retry_count))
else:
break