aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/ssh.py
diff options
context:
space:
mode:
Diffstat (limited to 'resources/libraries/python/ssh.py')
-rw-r--r--resources/libraries/python/ssh.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py
index 966d1b0448..9c7adc44e1 100644
--- a/resources/libraries/python/ssh.py
+++ b/resources/libraries/python/ssh.py
@@ -452,10 +452,14 @@ def exec_cmd(node, cmd, timeout=600, sudo=False, disconnect=False):
def exec_cmd_no_error(
- node, cmd, timeout=600, sudo=False, message=None, disconnect=False):
+ node, cmd, timeout=600, sudo=False, message=None, disconnect=False,
+ retries=0):
"""Convenience function to ssh/exec/return out & err.
Verifies that return code is zero.
+ Supports retries, timeout is related to each try separately then. There is
+ sleep(1) before each retry.
+ Disconnect (if enabled) is applied after each try.
:param node: DUT node.
:param cmd: Command to be executed.
@@ -463,21 +467,27 @@ def exec_cmd_no_error(
:param sudo: Sudo privilege execution flag. Default: False.
:param message: Error message in case of failure. Default: None.
:param disconnect: Close the opened SSH connection if True.
+ :param retries: How many times to retry on failure.
:type node: dict
:type cmd: str or OptionString
:type timeout: int
:type sudo: bool
:type message: str
:type disconnect: bool
+ :type retries: int
:returns: Stdout, Stderr.
:rtype: tuple(str, str)
:raises RuntimeError: If bash return code is not 0.
"""
- ret_code, stdout, stderr = exec_cmd(
- node, cmd, timeout=timeout, sudo=sudo, disconnect=disconnect)
- msg = ('Command execution failed: "{cmd}"\n{stderr}'.
- format(cmd=cmd, stderr=stderr) if message is None else message)
- if ret_code != 0:
+ for _ in range(retries + 1):
+ ret_code, stdout, stderr = exec_cmd(
+ node, cmd, timeout=timeout, sudo=sudo, disconnect=disconnect)
+ if ret_code == 0:
+ break
+ sleep(1)
+ else:
+ msg = ('Command execution failed: "{cmd}"\n{stderr}'.
+ format(cmd=cmd, stderr=stderr) if message is None else message)
raise RuntimeError(msg)
return stdout, stderr