From d4b52e26157fc9b2cd92bb0183281c351123dd05 Mon Sep 17 00:00:00 2001 From: chenying Date: Sun, 6 Nov 2016 23:58:16 +0800 Subject: [PATCH] Support Cinder V3 API in Karbor The 3.0 Cinder API includes all v2 core APIs existing prior to the introduction of microversions. The /v3 URL is used to call 3.0 APIs. The 3.0 Cinder API can be supported by Karbor. Change-Id: Idd3fef0f3b185a0592a4f42de1f67c6571ad99ad --- karbor/context.py | 3 ++- karbor/services/protection/clients/cinder.py | 4 ++-- karbor/tests/fullstack/karbor_base.py | 4 ++-- karbor/tests/unit/clients/test_cinder_client.py | 16 ++++++++-------- .../plugins/test_volume_protectable_plugin.py | 16 ++++++++-------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/karbor/context.py b/karbor/context.py index a1cff3cd..3d378b4a 100644 --- a/karbor/context.py +++ b/karbor/context.py @@ -80,7 +80,8 @@ class RequestContext(context.RequestContext): self.service_catalog = [s for s in service_catalog if s.get('type') in ('identity', 'compute', 'object-store', - 'image', 'volume', 'volumev2', 'network')] + 'image', 'volume', 'volumev2', 'network', + 'volumev3')] else: # if list is empty or none self.service_catalog = [] diff --git a/karbor/services/protection/clients/cinder.py b/karbor/services/protection/clients/cinder.py index 1d8d20c6..3ead181d 100644 --- a/karbor/services/protection/clients/cinder.py +++ b/karbor/services/protection/clients/cinder.py @@ -23,7 +23,7 @@ cinder_client_opts = [ cfg.StrOpt(SERVICE + '_endpoint', help='URL of the cinder endpoint.'), cfg.StrOpt(SERVICE + '_catalog_info', - default='volumev2:cinderv2:publicURL', + default='volumev3:cinderv3:publicURL', help='Info to match when looking for cinder in the service ' 'catalog. Format is: separated values of the form: ' ':: - ' @@ -40,7 +40,7 @@ cinder_client_opts = [ cfg.CONF.register_opts(cinder_client_opts, group=SERVICE + '_client') -CINDERCLIENT_VERSION = '2' +CINDERCLIENT_VERSION = '3' def create(context, conf): diff --git a/karbor/tests/fullstack/karbor_base.py b/karbor/tests/fullstack/karbor_base.py index 4f640f6d..366adf5b 100644 --- a/karbor/tests/fullstack/karbor_base.py +++ b/karbor/tests/fullstack/karbor_base.py @@ -66,10 +66,10 @@ def _get_karbor_client_from_creds(): def _get_cinder_client_from_creds(): api_version = "" cloud_config = _get_cloud_config() - keystone_session = cloud_config.get_session_client("volumev2") + keystone_session = cloud_config.get_session_client("volumev3") keystone_auth = cloud_config.get_auth() region_name = cloud_config.get_region_name() - service_type = "volumev2" + service_type = "volumev3" endpoint_type = "publicURL" endpoint = keystone_auth.get_endpoint( keystone_session, diff --git a/karbor/tests/unit/clients/test_cinder_client.py b/karbor/tests/unit/clients/test_cinder_client.py index 77721cd9..e4230f12 100644 --- a/karbor/tests/unit/clients/test_cinder_client.py +++ b/karbor/tests/unit/clients/test_cinder_client.py @@ -21,9 +21,9 @@ class CinderClientTest(base.TestCase): def setUp(self): super(CinderClientTest, self).setUp() service_catalog = [ - {'type': 'volumev2', - 'name': 'cinderv2', - 'endpoints': [{'publicURL': 'http://127.0.0.1:8776/v2/abcd'}], + {'type': 'volumev3', + 'name': 'cinderv3', + 'endpoints': [{'publicURL': 'http://127.0.0.1:8776/v3/abcd'}], }, ] self._context = RequestContext(user_id='admin', @@ -33,15 +33,15 @@ class CinderClientTest(base.TestCase): def test_create_client_by_endpoint(self): cfg.CONF.set_default('cinder_endpoint', - 'http://127.0.0.1:8776/v2', + 'http://127.0.0.1:8776/v3', 'cinder_client') client = cinder.create(self._context, cfg.CONF) - self.assertEqual('volumev2', client.client.service_type) - self.assertEqual('http://127.0.0.1:8776/v2/abcd', + self.assertEqual('volumev3', client.client.service_type) + self.assertEqual('http://127.0.0.1:8776/v3/abcd', client.client.management_url) def test_create_client_by_catalog(self): client = cinder.create(self._context, cfg.CONF) - self.assertEqual('volumev2', client.client.service_type) - self.assertEqual('http://127.0.0.1:8776/v2/abcd', + self.assertEqual('volumev3', client.client.service_type) + self.assertEqual('http://127.0.0.1:8776/v3/abcd', client.client.management_url) diff --git a/karbor/tests/unit/plugins/test_volume_protectable_plugin.py b/karbor/tests/unit/plugins/test_volume_protectable_plugin.py index 412bb488..286477a0 100644 --- a/karbor/tests/unit/plugins/test_volume_protectable_plugin.py +++ b/karbor/tests/unit/plugins/test_volume_protectable_plugin.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from cinderclient.v2 import volumes +from cinderclient.v3 import volumes from collections import namedtuple import mock @@ -31,8 +31,8 @@ class VolumeProtectablePluginTest(base.TestCase): def setUp(self): super(VolumeProtectablePluginTest, self).setUp() service_catalog = [ - {'type': 'volumev2', - 'endpoints': [{'publicURL': 'http://127.0.0.1:8776/v2/abcd'}], + {'type': 'volumev3', + 'endpoints': [{'publicURL': 'http://127.0.0.1:8776/v3/abcd'}], }, ] self._context = RequestContext(user_id='admin', @@ -42,19 +42,19 @@ class VolumeProtectablePluginTest(base.TestCase): def test_create_client_by_endpoint(self): cfg.CONF.set_default('cinder_endpoint', - 'http://127.0.0.1:8776/v2', + 'http://127.0.0.1:8776/v3', 'cinder_client') plugin = VolumeProtectablePlugin(self._context) - self.assertEqual('volumev2', + self.assertEqual('volumev3', plugin._client(self._context).client.service_type) - self.assertEqual('http://127.0.0.1:8776/v2/abcd', + self.assertEqual('http://127.0.0.1:8776/v3/abcd', plugin._client(self._context).client.management_url) def test_create_client_by_catalog(self): plugin = VolumeProtectablePlugin(self._context) - self.assertEqual('volumev2', + self.assertEqual('volumev3', plugin._client(self._context).client.service_type) - self.assertEqual('http://127.0.0.1:8776/v2/abcd', + self.assertEqual('http://127.0.0.1:8776/v3/abcd', plugin._client(self._context).client.management_url) def test_get_resource_type(self):