From: Samir Aguiar Date: Fri, 14 Dec 2018 18:24:16 +0000 (-0200) Subject: Add timeout support to run_cmd X-Git-Tag: v1.4~10^2~2 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=dfa7c024cf56927eb7153e88444ebe1f3cf42d31;p=pyi2ncommon Add timeout support to run_cmd When calling shell commands on a VM we have a default timeout of 60 seconds (in the session functions designed to run remote commands). However, some arnied_wrapper functions such as `wait_for_run` (which calls `arnied_helper --wait-for-program-timeout`) require a larger timeout, so we need to be able to overwrite the default. --- diff --git a/src/arnied_wrapper.py b/src/arnied_wrapper.py index a97242e..d871bb5 100644 --- a/src/arnied_wrapper.py +++ b/src/arnied_wrapper.py @@ -76,7 +76,7 @@ class ConfigError(Exception): pass -def run_cmd(cmd="", ignore_errors=False, vm=None): +def run_cmd(cmd="", ignore_errors=False, vm=None, timeout=60): """ Universal command run wrapper. @@ -84,12 +84,13 @@ def run_cmd(cmd="", ignore_errors=False, vm=None): :param bool ignore_errors: whether not to raise error on command failure :param vm: vm to run on if running on a guest instead of the host :type vm: VM object or None + :param int timeout: amount of seconds to wait for the program to run :returns: command result output :rtype: str :raises: :py:class:`OSError` if command failed and cannot be ignored """ if vm is not None: - status, stdout = vm.session.cmd_status_output(cmd) + status, stdout = vm.session.cmd_status_output(cmd, timeout=timeout) stdout = stdout.encode() stderr = b"" if status != 0: