aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2017-01-30 11:38:17 +0100
committerPeter Mikus <pmikus@cisco.com>2017-02-16 06:04:59 +0000
commit4d9b95cde48fe1b9abf70a5c7c2edcdb3199776d (patch)
tree491731ba190c6f2976c2a3b9d1bafca8109ada55
parente5a63c071996f351d6037ba8a08ff8eecf32ca39 (diff)
CSIT-514: Kill Qemu when it does not respond
Change-Id: Id13c7fd51e693a273637c80cb35a159434be4826 Signed-off-by: Tibor Frank <tifrank@cisco.com>
-rw-r--r--resources/libraries/python/QemuUtils.py4
-rw-r--r--resources/libraries/python/ssh.py9
-rwxr-xr-xresources/tools/topo_installation.py3
3 files changed, 12 insertions, 4 deletions
diff --git a/resources/libraries/python/QemuUtils.py b/resources/libraries/python/QemuUtils.py
index 37a8863a2e..a4e14d2427 100644
--- a/resources/libraries/python/QemuUtils.py
+++ b/resources/libraries/python/QemuUtils.py
@@ -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
diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py
index 90ac0be2dc..3a2c1b661a 100644
--- a/resources/libraries/python/ssh.py
+++ b/resources/libraries/python/ssh.py
@@ -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'
diff --git a/resources/tools/topo_installation.py b/resources/tools/topo_installation.py
index 5dbaaaa2f8..3a983962ad 100755
--- a/resources/tools/topo_installation.py
+++ b/resources/tools/topo_installation.py
@@ -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."""