libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vd...@apache.org
Subject [08/23] libcloud git commit: Add cinder support LIBCLOUD-874
Date Tue, 04 Dec 2018 08:54:23 GMT
Add cinder support LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: 2d9e862382735e6818c01b0972758b12a6297f31
Parents: 3c93d26
Author: micafer <micafer1@upv.es>
Authored: Mon Sep 24 16:10:39 2018 +0200
Committer: Rick van de Loo <rickvandeloo@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 14 +++----
 libcloud/test/common/test_openstack_identity.py |  9 +++--
 .../compute/fixtures/openstack/_v2_0__auth.json | 22 ++++++++++
 libcloud/test/compute/test_openstack.py         | 42 ++++++++++++++++++++
 4 files changed, 76 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2d9e8623/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index fba9a8a..9bd80cc 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -3015,11 +3015,11 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
 
     def list_volumes(self):
         return self._to_volumes(
-            self.connection.request('/volumes/detail').object)
+            self.volumev2_connection.request('/volumes/detail').object)
 
     def ex_get_volume(self, volumeId):
         return self._to_volume(
-            self.connection.request('/volumes/%s' % volumeId).object)
+            self.volumev2_connection.request('/volumes/%s' % volumeId).object)
 
     def create_volume(self, size, name, location=None, snapshot=None,
                       ex_volume_type=None):
@@ -3066,18 +3066,18 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         if snapshot:
             volume['snapshot_id'] = snapshot.id
 
-        resp = self.connection.request('/volumes',
+        resp = self.volumev2_connection.request('/volumes',
                                        method='POST',
                                        data={'volume': volume})
         return self._to_volume(resp.object)
 
     def destroy_volume(self, volume):
-        return self.connection.request('/volumes/%s' % volume.id,
+        return self.volumev2_connection.request('/volumes/%s' % volume.id,
                                        method='DELETE').success()
 
     def ex_list_snapshots(self):
         return self._to_snapshots(
-            self.connection.request('/snapshots/detail').object)
+            self.volumev2_connection.request('/snapshots/detail').object)
 
     def create_volume_snapshot(self, volume, name=None, ex_description=None,
                                ex_force=True):
@@ -3108,12 +3108,12 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         if ex_description is not None:
             data['snapshot']['description'] = ex_description
 
-        return self._to_snapshot(self.connection.request('/snapshots',
+        return self._to_snapshot(self.volumev2_connection.request('/snapshots',
                                                          method='POST',
                                                          data=data).object)
 
     def destroy_volume_snapshot(self, snapshot):
-        resp = self.connection.request('/snapshots/%s' % snapshot.id,
+        resp = self.volumev2_connection.request('/snapshots/%s' % snapshot.id,
                                        method='DELETE')
         return resp.status == httplib.ACCEPTED
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2d9e8623/libcloud/test/common/test_openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/test/common/test_openstack_identity.py b/libcloud/test/common/test_openstack_identity.py
index 3ed77bb..c93cee3 100644
--- a/libcloud/test/common/test_openstack_identity.py
+++ b/libcloud/test/common/test_openstack_identity.py
@@ -544,7 +544,7 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
         catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                           auth_version='2.0')
         entries = catalog.get_entries()
-        self.assertEqual(len(entries), 8)
+        self.assertEqual(len(entries), 9)
 
         entry = [e for e in entries if e.service_name == 'cloudServers'][0]
         self.assertEqual(entry.service_type, 'compute')
@@ -611,7 +611,8 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
                                           auth_version='2.0')
         service_types = catalog.get_service_types()
         self.assertEqual(service_types, ['compute', 'image', 'network',
-                                         'object-store', 'rax:object-cdn'])
+                                         'object-store', 'rax:object-cdn',
+                                         'volumev2'])
 
         service_types = catalog.get_service_types(region='ORD')
         self.assertEqual(service_types, ['rax:object-cdn'])
@@ -625,8 +626,8 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
                                           auth_version='2.0')
 
         service_names = catalog.get_service_names()
-        self.assertEqual(service_names, ['cloudFiles', 'cloudFilesCDN',
-                                         'cloudServers',
+        self.assertEqual(service_names, ['cinder', 'cloudFiles',
+                                         'cloudFilesCDN', 'cloudServers',
                                          'cloudServersOpenStack',
                                          'cloudServersPreprod',
                                          'glance',

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2d9e8623/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
index 79c6776..d2bd3c3 100644
--- a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
+++ b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
@@ -123,6 +123,28 @@
             {
                 "endpoints": [
                     {
+                        "region": "RegionOne",
+                        "tenantId": "1337",
+                        "publicURL": "https://test_endpoint.com/v2/1337",
+                        "versionInfo": "https://test_endpoint.com/v2/",
+                        "versionList": "https://test_endpoint.com/",
+                        "versionId": "2"
+                    },
+                    {
+                        "region": "fr1",
+                        "tenantId": "1337",
+                        "publicURL": "https://test_endpoint.com/v2/1337",
+                        "versionInfo": "https://test_endpoint.com/v2/",
+                        "versionList": "https://test_endpoint.com/",
+                        "versionId": "2"
+                    }
+                ],
+                "name": "cinder",
+                "type": "volumev2"
+            },
+            {
+                "endpoints": [
+                    {
                         "region": "DFW",
                         "tenantId": "613469",
                         "publicURL": "https://dfw.servers.api.rackspacecloud.com/v2/1337",

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2d9e8623/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index faf8fe4..9dc39ee 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1576,6 +1576,11 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
         # normally authentication happens lazily, but we force it here
         self.driver.network_connection._populate_hosts_and_request_paths()
 
+        self.driver_klass.volumev2_connectionCls.conn_class = OpenStack_2_0_MockHttp
+        self.driver_klass.volumev2_connectionCls.auth_url = "https://auth.api.example.com"
+        # normally authentication happens lazily, but we force it here
+        self.driver.volumev2_connection._populate_hosts_and_request_paths()
+
     def test_ex_force_auth_token_passed_to_connection(self):
         base_url = 'https://servers.api.rackspacecloud.com/v1.1/slug'
         kwargs = {
@@ -1861,6 +1866,43 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
             'created_at': '2013-06-21T12:39:02.000000',
         })
 
+    def test_create_volume_passes_location_to_request_only_if_not_none(self):
+        with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+            self.driver.create_volume(1, 'test', location='mylocation')
+            name, args, kwargs = mock_request.mock_calls[0]
+            self.assertEqual(kwargs["data"]["volume"]["availability_zone"], "mylocation")
+
+    def test_create_volume_does_not_pass_location_to_request_if_none(self):
+        with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+            self.driver.create_volume(1, 'test')
+            name, args, kwargs = mock_request.mock_calls[0]
+            self.assertFalse("availability_zone" in kwargs["data"]["volume"])
+
+    def test_create_volume_passes_volume_type_to_request_only_if_not_none(self):
+        with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+            self.driver.create_volume(1, 'test', ex_volume_type='myvolumetype')
+            name, args, kwargs = mock_request.mock_calls[0]
+            self.assertEqual(kwargs["data"]["volume"]["volume_type"], "myvolumetype")
+
+    def test_create_volume_does_not_pass_volume_type_to_request_if_none(self):
+        with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+            self.driver.create_volume(1, 'test')
+            name, args, kwargs = mock_request.mock_calls[0]
+            self.assertFalse("volume_type" in kwargs["data"]["volume"])
+
+    def test_ex_create_snapshot_does_not_post_optional_parameters_if_none(self):
+        volume = self.driver.list_volumes()[0]
+        with patch.object(self.driver, '_to_snapshot'):
+            with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+                self.driver.create_volume_snapshot(volume,
+                                                   name=None,
+                                                   ex_description=None,
+                                                   ex_force=True)
+
+        name, args, kwargs = mock_request.mock_calls[0]
+        self.assertFalse("display_name" in kwargs["data"]["snapshot"])
+        self.assertFalse("display_description" in kwargs["data"]["snapshot"])
+
 
 class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
     should_list_locations = False


Mime
View raw message