libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [2/6] git commit: Adding condition to handle differences between Rackspace/OpenStack. Changed the response.status comparison to use httplib.NO_CONTENT for ex_delete_snapshot since no data is returned.
Date Thu, 06 Feb 2014 20:14:03 GMT
Adding condition to handle differences between Rackspace/OpenStack. Changed the response.status
comparison to use httplib.NO_CONTENT for ex_delete_snapshot since no data is returned.


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

Branch: refs/heads/trunk
Commit: d97705aeb20c536da9a553ef24045cd2048b98bf
Parents: b064453
Author: Chris DeRamus <chris@divvycloud.com>
Authored: Thu Feb 6 07:36:07 2014 -0500
Committer: Chris DeRamus <chris@divvycloud.com>
Committed: Thu Feb 6 07:51:43 2014 -0500

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 47 +++++++++-----------
 .../_os_snapshots_create_rackspace.json         | 11 +++++
 .../openstack_v1.1/_os_snapshots_rackspace.json | 22 +++++++++
 libcloud/test/compute/test_openstack.py         | 26 ++++++++---
 4 files changed, 74 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/d97705ae/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 8e28759..7889400 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1642,8 +1642,10 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         :rtype:     ``bool``
         """
-        return self.connection.request('/os-snapshots/%s' % snapshot.id,
-                                       method='DELETE').success()
+        resp = self.connection.request('/os-snapshots/%s' % snapshot.id,
+                                       method='DELETE')
+
+        return resp.status == httplib.NO_CONTENT
 
     def _to_security_group_rules(self, obj):
         return [self._to_security_group_rule(security_group_rule) for
@@ -2035,32 +2037,25 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
         if 'snapshot' in api_node:
             api_node = api_node['snapshot']
 
-        # RackSpace vs. OpenStack
-        if 'displayName' in api_node:
-            return VolumeSnapshot(
-                id=api_node['id'],
-                driver=self,
-                size=api_node['size'],
-                extra={
-                    'volume_id': api_node['volumeId'],
-                    'name': api_node['displayName'],
-                    'created': api_node['createdAt'],
-                    'description': api_node['displayDescription'],
-                    'status': api_node['status'],
-                })
+        if 'rackspace' in self.name.lower():
+            extra = {'volume_id': api_node['volumeId'],
+                     'name': api_node['displayName'],
+                     'created': api_node['createdAt'],
+                     'description': api_node['displayDescription'],
+                     'status': api_node['status']}
 
         else:
-            return VolumeSnapshot(
-                id=api_node['id'],
-                driver=self,
-                size=api_node['size'],
-                extra={
-                    'volume_id': api_node['volume_id'],
-                    'name': api_node['display_name'],
-                    'created': api_node['created_at'],
-                    'description': api_node['display_description'],
-                    'status': api_node['status'],
-                })
+            extra = {'volume_id': api_node['volume_id'],
+                     'name': api_node['display_name'],
+                     'created': api_node['created_at'],
+                     'description': api_node['display_description'],
+                     'status': api_node['status']}
+
+        return VolumeSnapshot(
+            id=api_node['id'],
+            driver=self,
+            size=api_node['size'],
+            extra=extra)
 
     def _to_size(self, api_flavor, price=None, bandwidth=None):
         # if provider-specific subclasses can get better values for

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d97705ae/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshots_create_rackspace.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshots_create_rackspace.json
b/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshots_create_rackspace.json
new file mode 100644
index 0000000..8f90319
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshots_create_rackspace.json
@@ -0,0 +1,11 @@
+{
+    "snapshot": {
+        "id": "3fbbcccf-d058-4502-8844-6feeffdf4cb5",
+        "displayName": "snap-001",
+        "displayDescription": "Daily backup",
+        "volumeId": "521752a6-acf6-4b2d-bc7a-119f9148cd8c",
+        "status": "available",
+        "size": 30,
+        "createdAt": "2012-02-29T03:50:07Z"
+     }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d97705ae/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshots_rackspace.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshots_rackspace.json b/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshots_rackspace.json
new file mode 100644
index 0000000..877945b
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshots_rackspace.json
@@ -0,0 +1,22 @@
+{
+    "snapshots": [
+        {
+            "id": "3fbbcccf-d058-4502-8844-6feeffdf4cb5",
+            "displayName": "snap-001",
+            "displayDescription": "Daily backup",
+            "volumeId": "521752a6-acf6-4b2d-bc7a-119f9148cd8c",
+            "status": "available",
+            "size": 30,
+            "createdAt": "2012-02-29T03:50:07Z"
+        },
+        {
+            "id": "e479997c-650b-40a4-9dfe-77655818b0d2",
+            "displayName": "snap-002",
+            "displayDescription": "Weekly backup",
+            "volumeId": "76b8950a-8594-4e5b-8dce-0dfa9c696358",
+            "status": "available",
+            "size": 25,
+            "createdAt": "2012-03-19T01:52:47Z"
+        }
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d97705ae/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 3b6c65f..bdcabee 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1534,12 +1534,16 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
         self.assertEqual(resp['output'], expected_output)
 
     def test_ex_list_snapshots(self):
+        if self.driver_type.type == 'rackspace':
+            OpenStack_2_0_MockHttp.type = 'RACKSPACE'
         snapshots = self.driver.ex_list_snapshots()
         self.assertEqual(len(snapshots), 2)
         self.assertEqual(snapshots[0].extra['name'], 'snap-001')
 
     def test_ex_create_snapshot(self):
         volume = self.driver.list_volumes()[0]
+        if self.driver_type.type == 'rackspace':
+            OpenStack_2_0_MockHttp.type = 'RACKSPACE'
         ret = self.driver.ex_create_snapshot(volume,
                                              'Test Volume',
                                              'This is a test')
@@ -1548,7 +1552,7 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
     def test_ex_delete_snapshot(self):
         snapshot = self.driver.ex_list_snapshots()[0]
         ret = self.driver.ex_delete_snapshot(snapshot)
-        self.assertTrue(ret is True)
+        self.assertTrue(ret)
 
 
 class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
@@ -1871,7 +1875,7 @@ class OpenStack_1_1_MockHttp(MockHttpTestCase):
         raise NotImplementedError()
 
     def _v1_1_slug_servers_72258_action(self, method, url, body, headers):
-        if method == "POST":
+        if method == 'POST':
             body = self.fixtures.load('_servers_suspend.json')
             return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
         else:
@@ -1880,7 +1884,7 @@ class OpenStack_1_1_MockHttp(MockHttpTestCase):
         return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
 
     def _v1_1_slug_servers_12063_action(self, method, url, body, headers):
-        if method == "POST":
+        if method == 'POST':
             body = self.fixtures.load('_servers_unpause.json')
             return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
         else:
@@ -1898,17 +1902,27 @@ class OpenStack_1_1_MockHttp(MockHttpTestCase):
 
 =======
     def _v1_1_slug_os_snapshots(self, method, url, body, headers):
-        if method == "GET":
+        if method == 'GET':
             body = self.fixtures.load('_os_snapshots.json')
-        elif method == "POST":
+        elif method == 'POST':
             body = self.fixtures.load('_os_snapshots_create.json')
         else:
             raise NotImplementedError()
 
         return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
 
+    def _v1_1_slug_os_snapshots_RACKSPACE(self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('_os_snapshots_rackspace.json')
+        elif method == 'POST':
+            body = self.fixtures.load('_os_snapshots_create_rackspace.json')
+        else:
+            raise NotImplementedError()
+
+        return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
     def _v1_1_slug_os_snapshots_3fbbcccf_d058_4502_8844_6feeffdf4cb5(self, method, url, body,
headers):
-        if method == "DELETE":
+        if method == 'DELETE':
             body = ''
         else:
             raise NotImplementedError()


Mime
View raw message