CSIT-514: Kill Qemu when it does not respond 27/4927/11
authorTibor Frank <tifrank@cisco.com>
Mon, 30 Jan 2017 10:38:17 +0000 (11:38 +0100)
committerPeter Mikus <pmikus@cisco.com>
Thu, 16 Feb 2017 06:04:59 +0000 (06:04 +0000)
Change-Id: Id13c7fd51e693a273637c80cb35a159434be4826
Signed-off-by: Tibor Frank <tifrank@cisco.com>
resources/libraries/python/QemuUtils.py
resources/libraries/python/ssh.py
resources/tools/topo_installation.py

index 37a8863..a4e14d2 100644 (file)
@@ -18,7 +18,7 @@ import json
 
 from robot.api import logger
 
-from resources.libraries.python.ssh import SSH
+from resources.libraries.python.ssh import SSH, SSHTimeout
 from resources.libraries.python.constants import Constants
 from resources.libraries.python.topology import NodeType
 
@@ -519,7 +519,7 @@ class QemuUtils(object):
         # Wait until VM boot
         try:
             self._wait_until_vm_boot()
-        except RuntimeError:
+        except (RuntimeError, SSHTimeout):
             self.qemu_kill()
             self.qemu_clear_socks()
             raise
index 90ac0be..3a2c1b6 100644 (file)
@@ -29,6 +29,11 @@ __all__ = ["exec_cmd", "exec_cmd_no_error"]
 # TODO: load priv key
 
 
+class SSHTimeout(Exception):
+    """This exception is raised when a timeout occurs."""
+    pass
+
+
 class SSH(object):
     """Contains methods for managing and using SSH connections."""
 
@@ -118,7 +123,7 @@ class SSH(object):
         :type timeout: int
         :return return_code, stdout, stderr
         :rtype: tuple(int, str, str)
-        :raise socket.timeout: If command is not finished in timeout time.
+        :raise SSHTimeout: If command is not finished in timeout time.
         """
         start = time()
         stdout = StringIO.StringIO()
@@ -144,7 +149,7 @@ class SSH(object):
                 stderr.write(chan.recv_stderr(self.__MAX_RECV_BUF))
 
             if time() - start > timeout:
-                raise socket.timeout(
+                raise SSHTimeout(
                     'Timeout exception.\n'
                     'Current contents of stdout buffer: {0}\n'
                     'Current contents of stderr buffer: {1}\n'
index 5dbaaaa..3a98396 100755 (executable)
@@ -22,6 +22,7 @@ from yaml import load
 
 from resources.libraries.python.ssh import SSH
 
+
 def ssh_no_error(ssh, cmd, sudo=False):
     """Execute a command over ssh channel, and log and exit if the command
     fails.
@@ -47,6 +48,7 @@ def ssh_no_error(ssh, cmd, sudo=False):
 
     return stdo
 
+
 def ssh_ignore_error(ssh, cmd, sudo=False):
     """Execute a command over ssh channel, ignore errors.
 
@@ -70,6 +72,7 @@ def ssh_ignore_error(ssh, cmd, sudo=False):
 
     return stdo
 
+
 def main():
     """Copy and installation of VPP packages."""
 

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.