libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] 09/21: Add a test case for it.
Date Sat, 04 Apr 2020 20:45:11 GMT
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch 2.8.x
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit c9c906aeedc5d3c8f7ba783c3b3e7fef8d4551a5
Author: Tomaz Muraus <tomaz@tomaz.me>
AuthorDate: Wed Apr 1 12:32:41 2020 +0200

    Add a test case for it.
---
 libcloud/compute/ssh.py                  |  6 +++---
 libcloud/test/compute/test_deployment.py | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/libcloud/compute/ssh.py b/libcloud/compute/ssh.py
index 1fad910..cd702c3 100644
--- a/libcloud/compute/ssh.py
+++ b/libcloud/compute/ssh.py
@@ -68,15 +68,15 @@ class SSHCommandTimeoutError(Exception):
         # type: (str, float) -> None
         self.cmd = cmd
         self.timeout = timeout
-        message = 'Command didn\'t finish in %s seconds' % (timeout)
-        super(SSHCommandTimeoutError, self).__init__(message)
+        self.message = 'Command didn\'t finish in %s seconds' % (timeout)
+        super(SSHCommandTimeoutError, self).__init__(self.message)
 
     def __repr__(self):
         return ('<SSHCommandTimeoutError: cmd="%s",timeout=%s)>' %
                 (self.cmd, self.timeout))
 
     def __str__(self):
-        return self.message
+        return self.__repr__()
 
 
 class BaseSSHClient(object):
diff --git a/libcloud/test/compute/test_deployment.py b/libcloud/test/compute/test_deployment.py
index 54cb666..93d2d2f 100644
--- a/libcloud/test/compute/test_deployment.py
+++ b/libcloud/test/compute/test_deployment.py
@@ -34,6 +34,7 @@ from libcloud.compute.base import NodeAuthPassword
 from libcloud.compute.types import NodeState, DeploymentError, LibcloudError
 from libcloud.compute.ssh import BaseSSHClient
 from libcloud.compute.ssh import have_paramiko
+from libcloud.compute.ssh import SSHCommandTimeoutError
 from libcloud.compute.drivers.rackspace import RackspaceFirstGenNodeDriver as Rackspace
 
 from libcloud.test import MockHttp, XML_HEADERS
@@ -409,6 +410,23 @@ class DeploymentTests(unittest.TestCase):
         else:
             self.fail('Exception was not thrown')
 
+    def test_run_deployment_script_ssh_command_timeout_fatal_exception(self):
+        # We shouldn't retry on SSHCommandTimeoutError error since it's fatal
+        task = Mock()
+        task.run = Mock()
+        task.run.side_effect = SSHCommandTimeoutError('ls -la', 10)
+        ssh_client = Mock()
+
+        try:
+            self.driver._run_deployment_script(task=task,
+                                               node=self.node,
+                                               ssh_client=ssh_client,
+                                               max_tries=5)
+        except SSHCommandTimeoutError as e:
+            self.assertTrue(e.message.find('Command didn\'t finish') != -1)
+        else:
+            self.fail('Exception was not thrown')
+
     @patch('libcloud.compute.base.SSHClient')
     @patch('libcloud.compute.ssh')
     def test_deploy_node_success(self, mock_ssh_module, _):


Mime
View raw message