libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [1/2] libcloud git commit: Fix case where node does not exist on OpenStack
Date Mon, 26 Sep 2016 04:50:02 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 4b3d0b1e3 -> 7695cf270


Fix case where node does not exist on OpenStack

  - Add case where the node does not exist on OS
  - Fix code that tries to return None if the node does not exist


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

Branch: refs/heads/trunk
Commit: 2374e8af432267c87db3328f2ed27529175d534e
Parents: 4b3d0b1
Author: Allard Hoeve <allardhoeve@gmail.com>
Authored: Fri Sep 23 10:46:23 2016 +0200
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Mon Sep 26 14:49:37 2016 +1000

----------------------------------------------------------------------
 CHANGES.rst                             |  5 +++++
 libcloud/compute/drivers/openstack.py   | 10 +++++++---
 libcloud/test/compute/test_openstack.py |  7 +++++++
 3 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2374e8af/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index eb027da..669c8a0 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -13,6 +13,11 @@ Compute
   (GITHUB-857)
   [Allard Hoeve]
 
+- When fetching the node details of a non-existing node, OpenStack would raise a
+  `BaseHTTPError` instead of returning `None`, as was intended. Fixed tests and code.
+  (GITHUB-864)
+  [Allard Hoeve]
+
 Container
 ~~~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2374e8af/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 88622d2..5357cad 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -15,6 +15,7 @@
 """
 OpenStack driver
 """
+from libcloud.common.exceptions import BaseHTTPError
 from libcloud.utils.iso8601 import parse_date
 
 try:
@@ -322,9 +323,12 @@ class OpenStackNodeDriver(NodeDriver, OpenStackDriverMixin):
             node_id = node_id.id
 
         uri = '/servers/%s' % (node_id)
-        resp = self.connection.request(uri, method='GET')
-        if resp.status == httplib.NOT_FOUND:
-            return None
+        try:
+            resp = self.connection.request(uri, method='GET')
+        except BaseHTTPError as e:
+            if e.code == httplib.NOT_FOUND:
+                return None
+            raise
 
         return self._to_node_from_obj(resp.object)
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2374e8af/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 1a0cdab..86dacaf 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1129,6 +1129,10 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
         self.assertEqual(node.id, '12064')
         self.assertEqual(node.name, 'lc-test')
 
+    def test_ex_get_node_details_returns_none_if_node_does_not_exist(self):
+        node = self.driver.ex_get_node_details('does-not-exist')
+        self.assertIsNone(node)
+
     def test_ex_get_size(self):
         size_id = '7'
         size = self.driver.ex_get_size(size_id)
@@ -1562,6 +1566,9 @@ class OpenStack_1_1_MockHttp(MockHttpTestCase):
         body = self.fixtures.load('_servers_detail_ERROR_STATE.json')
         return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
 
+    def _v2_1337_servers_does_not_exist(self, *args, **kwargs):
+        return httplib.NOT_FOUND, None, {}, httplib.responses[httplib.NOT_FOUND]
+
     def _v1_1_slug_flavors_detail(self, method, url, body, headers):
         body = self.fixtures.load('_flavors_detail.json')
         return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])


Mime
View raw message