Allow xen commands to have a timeout
authorMichele Tartara <mtartara@google.com>
Fri, 7 Mar 2014 09:46:02 +0000 (10:46 +0100)
committerMichele Tartara <mtartara@google.com>
Fri, 7 Mar 2014 10:07:59 +0000 (11:07 +0100)
Modify the function that runs Xen commands so that it is possible to specify an
optional timeout after which the command is killed.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/hypervisor/hv_xen.py

index cb0c061..88f71d1 100644 (file)
@@ -360,13 +360,21 @@ class XenHypervisor(hv_base.BaseHypervisor):
 
     return cmd
 
-  def _RunXen(self, args):
+  def _RunXen(self, args, timeout=None):
     """Wrapper around L{utils.process.RunCmd} to run Xen command.
 
+    If a timeout (in seconds) is specified, the command will be terminated after
+    that number of seconds.
+
     @see: L{utils.process.RunCmd}
 
     """
-    cmd = [self._GetCommand()]
+    cmd = []
+
+    if timeout is not None:
+      cmd.extend(["timeout", str(timeout)])
+
+    cmd.extend([self._GetCommand()])
     cmd.extend(args)
 
     return self._run_cmd_fn(cmd)