You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2020/08/04 18:34:21 UTC

[libcloud] branch trunk updated (8a6cd1e -> b9c5997)

This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git.


    from 8a6cd1e  Try to reconnect if we receive "ssh connection not active" error during deployment step run.
     new 7d29765  Add changelog entry.
     new 514776f  Fix lint.
     new f4a7d65  Fix lint.
     new a13fb0e  Add a test case which verifies _run_deployment_script() correctly tries to reconnect in case "SSH session not active" exception is thrown.
     new 109eeca  Also try to close the connection before re-attempting to re-connect.
     new b9c5997  Update .gitignore.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitignore                               |  1 +
 CHANGES.rst                              |  9 ++++++++
 libcloud/compute/base.py                 | 20 +++++++++++++-----
 libcloud/test/compute/test_deployment.py | 35 ++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 5 deletions(-)


[libcloud] 01/06: Add changelog entry.

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7d297653c596ee2220661424d53af3d720037fe8
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Tue Aug 4 14:37:41 2020 +0200

    Add changelog entry.
---
 CHANGES.rst | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/CHANGES.rst b/CHANGES.rst
index 71cc7a3..735f6a3 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -59,6 +59,15 @@ Compute
   (GITHUB-1470)
   [Eis D. Zaster - @Eis-D-Z]
 
+- Update ``deploy_node()`` method to try to re-connect to the server if we
+  receive "SSH connection not active" error when trying to run a deployment
+  step.
+
+  In some scenarios, connection may get closed by the server for whatever
+  reason before finishing all the deployment steps and in this case only
+  re-connecting would help and result in a successful outcome.
+  [Tomaz Muraus - @Kami]
+
 Changes in Apache Libcloud 3.1.0
 --------------------------------
 


[libcloud] 06/06: Update .gitignore.

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b9c5997aaab13c70d01d2f099de2ae09985fa9d7
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Tue Aug 4 18:51:33 2020 +0200

    Update .gitignore.
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index f75ca81..f75be5b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,4 @@ pip-selfcheck.json
 report.html
 .pytest_cache
 .mypy_cache/
+libcloud/data/pricing.json.sha*


[libcloud] 05/06: Also try to close the connection before re-attempting to re-connect.

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 109eeca34f9b113ac5697a37cc79da9ce4119a11
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Tue Aug 4 18:45:45 2020 +0200

    Also try to close the connection before re-attempting to re-connect.
    
    In most cases this won't be needed, but it's better we try to do that.
---
 libcloud/compute/base.py                 | 17 +++++++++++++----
 libcloud/test/compute/test_deployment.py |  3 ++-
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/libcloud/compute/base.py b/libcloud/compute/base.py
index 9231ad4..9cc48be 100644
--- a/libcloud/compute/base.py
+++ b/libcloud/compute/base.py
@@ -1883,12 +1883,21 @@ class NodeDriver(BaseDriver):
 
                 if "ssh session not active" in str(e).lower():
                     # Sometimes connection gets closed or disconnected half
-                    # way through.
+                    # way through for wahtever reason.
                     # If this happens, we try to re-connect before
                     # re-attempting to run the step.
-                    timeout = int(ssh_client.timeout) if ssh_client.timeout else 10
-                    ssh_client = self._ssh_client_connect(ssh_client=ssh_client,
-                                                          timeout=timeout)
+                    try:
+                        ssh_client.close()
+                    except Exception:
+                        # Non fatal since connection is most likely already
+                        # closed at this point
+                        pass
+
+                    timeout = (int(ssh_client.timeout) if ssh_client.timeout
+                               else 10)
+                    ssh_client = self._ssh_client_connect(
+                        ssh_client=ssh_client,
+                        timeout=timeout)
 
                 if tries >= max_tries:
                     raise LibcloudError(value='Failed after %d tries: %s'
diff --git a/libcloud/test/compute/test_deployment.py b/libcloud/test/compute/test_deployment.py
index 0d7c53a..184128c 100644
--- a/libcloud/test/compute/test_deployment.py
+++ b/libcloud/test/compute/test_deployment.py
@@ -477,6 +477,7 @@ class DeploymentTests(unittest.TestCase):
         ssh_client.timeout = 20
 
         self.assertEqual(ssh_client.connect.call_count, 0)
+        self.assertEqual(ssh_client.close.call_count, 0)
 
         self.driver._run_deployment_script(task=task,
                                            node=self.node,
@@ -484,7 +485,7 @@ class DeploymentTests(unittest.TestCase):
                                            max_tries=5)
 
         self.assertEqual(ssh_client.connect.call_count, 2)
-
+        self.assertEqual(ssh_client.close.call_count, 2 + 1)
 
     @patch('libcloud.compute.base.SSHClient')
     @patch('libcloud.compute.ssh')


[libcloud] 03/06: Fix lint.

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f4a7d65734c43a24faea244a83863d3c9a2ee939
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Tue Aug 4 18:37:04 2020 +0200

    Fix lint.
---
 libcloud/compute/base.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcloud/compute/base.py b/libcloud/compute/base.py
index ff1a570..9231ad4 100644
--- a/libcloud/compute/base.py
+++ b/libcloud/compute/base.py
@@ -1884,9 +1884,9 @@ class NodeDriver(BaseDriver):
                 if "ssh session not active" in str(e).lower():
                     # Sometimes connection gets closed or disconnected half
                     # way through.
-                    # If this happens, we try to re-connect before re-attempting
-                    # to run the step.
-                    timeout = int(ssh_client.timeout) if ssh_client.timeout else None
+                    # If this happens, we try to re-connect before
+                    # re-attempting to run the step.
+                    timeout = int(ssh_client.timeout) if ssh_client.timeout else 10
                     ssh_client = self._ssh_client_connect(ssh_client=ssh_client,
                                                           timeout=timeout)
 


[libcloud] 04/06: Add a test case which verifies _run_deployment_script() correctly tries to reconnect in case "SSH session not active" exception is thrown.

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a13fb0e37356c1f00818eba23f975574b5b65b71
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Tue Aug 4 18:43:39 2020 +0200

    Add a test case which verifies _run_deployment_script() correctly tries
    to reconnect in case "SSH session not active" exception is thrown.
---
 libcloud/test/compute/test_deployment.py | 34 ++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/libcloud/test/compute/test_deployment.py b/libcloud/test/compute/test_deployment.py
index 6750578..0d7c53a 100644
--- a/libcloud/test/compute/test_deployment.py
+++ b/libcloud/test/compute/test_deployment.py
@@ -452,6 +452,40 @@ class DeploymentTests(unittest.TestCase):
         else:
             self.fail('Exception was not thrown')
 
+    def test_run_deployment_script_reconnect_on_ssh_session_not_active(self):
+        # Verify that we try to reconnect if task.run() throws exception with
+        # "SSH client not active" message
+        global exception_counter
+        exception_counter = 0
+
+        def mock_run(*args, **kwargs):
+            # Mock run() method which throws "SSH session not active" exception
+            # during first two calls and on third one it returns None.
+            global exception_counter
+
+            exception_counter += 1
+
+            if exception_counter > 2:
+                return None
+
+            raise Exception("SSH session not active")
+
+        task = Mock()
+        task.run = Mock()
+        task.run = mock_run
+        ssh_client = Mock()
+        ssh_client.timeout = 20
+
+        self.assertEqual(ssh_client.connect.call_count, 0)
+
+        self.driver._run_deployment_script(task=task,
+                                           node=self.node,
+                                           ssh_client=ssh_client,
+                                           max_tries=5)
+
+        self.assertEqual(ssh_client.connect.call_count, 2)
+
+
     @patch('libcloud.compute.base.SSHClient')
     @patch('libcloud.compute.ssh')
     def test_deploy_node_success(self, mock_ssh_module, _):


[libcloud] 02/06: Fix lint.

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 514776fc58f8233f35ce7052e628232b16e3799c
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Tue Aug 4 18:34:47 2020 +0200

    Fix lint.
---
 libcloud/compute/base.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcloud/compute/base.py b/libcloud/compute/base.py
index e688e20..ff1a570 100644
--- a/libcloud/compute/base.py
+++ b/libcloud/compute/base.py
@@ -1886,8 +1886,9 @@ class NodeDriver(BaseDriver):
                     # way through.
                     # If this happens, we try to re-connect before re-attempting
                     # to run the step.
+                    timeout = int(ssh_client.timeout) if ssh_client.timeout else None
                     ssh_client = self._ssh_client_connect(ssh_client=ssh_client,
-                                                        timeout=ssh_client.timeout)
+                                                          timeout=timeout)
 
                 if tries >= max_tries:
                     raise LibcloudError(value='Failed after %d tries: %s'