Add timeout support to run_cmd
authorSamir Aguiar <samirjaguiar@gmail.com>
Fri, 14 Dec 2018 18:24:16 +0000 (16:24 -0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 7 Feb 2019 15:50:39 +0000 (16:50 +0100)
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.

src/arnied_wrapper.py

index a97242e..d871bb5 100644 (file)
@@ -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: