libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [3/4] libcloud git commit: Test retries in destroy_node
Date Wed, 08 Nov 2017 03:36:44 GMT
Test retries in destroy_node

Signed-off-by: Quentin Pradet <quentinp@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/55b16c85
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/55b16c85
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/55b16c85

Branch: refs/heads/trunk
Commit: 55b16c8582478b88f5d8b4cf7cfbcd9562a78ecf
Parents: aaaa101
Author: Lucas Di Pentima <ldipentima@veritasgenetics.com>
Authored: Mon Nov 6 19:22:09 2017 -0300
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Wed Nov 8 07:32:06 2017 +0400

----------------------------------------------------------------------
 libcloud/test/compute/test_azure_arm.py | 38 ++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/55b16c85/libcloud/test/compute/test_azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_azure_arm.py b/libcloud/test/compute/test_azure_arm.py
index a32917d..bd8cfa0 100644
--- a/libcloud/test/compute/test_azure_arm.py
+++ b/libcloud/test/compute/test_azure_arm.py
@@ -166,6 +166,44 @@ class AzureNodeDriverTests(LibcloudTestCase):
         self.assertTrue(ret)
 
     @mock.patch('time.sleep', return_value=None)
+    def test_destroy_node__retry(self, time_sleep_mock):
+        def error(e, **kwargs):
+            raise e(**kwargs)
+        node = self.driver.list_nodes()[0]
+        AzureMockHttp.responses = [
+            # 202 - The delete will happen asynchronously
+            lambda f: error(BaseHTTPError, code=202, message='Deleting'),
+            # 200 means the node is still here - Try 1
+            lambda f: (httplib.OK, None, {}, 'OK'),
+            # 200 means the node is still here - Try 2
+            lambda f: (httplib.OK, None, {}, 'OK'),
+            # 200 means the node is still here - Try 3
+            lambda f: (httplib.OK, None, {}, 'OK'),
+            # 404 means node is gone - 4th retry: success!
+            lambda f: error(BaseHTTPError, code=404, message='Not found'),
+        ]
+        ret = self.driver.destroy_node(node)
+        self.assertTrue(ret)
+        self.assertEqual(4, time_sleep_mock.call_count)  # Retries
+
+    @mock.patch('time.sleep', return_value=None)
+    def test_destroy_node__destroy_nic_retries(self, time_sleep_mock):
+        def error(e, **kwargs):
+            raise e(**kwargs)
+        node = self.driver.list_nodes()[0]
+        err = BaseHTTPError(code=400, message='[NicInUse] Cannot destroy')
+        with mock.patch.object(self.driver, 'ex_destroy_nic') as m:
+            m.side_effect = [err] * 5 + [True]  # 5 errors before a success
+            ret = self.driver.destroy_node(node)
+            self.assertTrue(ret)
+            self.assertEqual(6, m.call_count)  # 6th call was a success
+
+            m.side_effect = [err] * 10 + [True]  # 10 errors before a success
+            with self.assertRaises(BaseHTTPError):
+                self.driver.destroy_node(node)
+                self.assertEqual(10, m.call_count)  # try 10 times & fail
+
+    @mock.patch('time.sleep', return_value=None)
     def test_destroy_node__async(self, time_sleep_mock):
         def error(e, **kwargs):
             raise e(**kwargs)


Mime
View raw message