diff options
author | Peter Mikus <pmikus@cisco.com> | 2019-04-24 11:31:30 +0000 |
---|---|---|
committer | Vratko Polak <vrpolak@cisco.com> | 2019-05-06 10:30:11 +0000 |
commit | e001fdea995835f1ef75a5e21607ba02d78e4068 (patch) | |
tree | 03392169d3d404c55531940aa658fd73db2e54b1 /resources/libraries/python/ssh.py | |
parent | 1c54bfd3bdfafe2764394f6540fd35f708bf2239 (diff) |
CSIT-1493 VPP restart handling code
Change-Id: Ibe52125089f39e0ff17ec607a3ed00c61d52ab8c
Signed-off-by: Peter Mikus <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/python/ssh.py')
-rw-r--r-- | resources/libraries/python/ssh.py | 22 |
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 |