From 118cf73533676c9bc20d4ec42d036a5125e819af Mon Sep 17 00:00:00 2001 From: Artem Goncharov <Artem.goncharov@gmail.com> Date: Fri, 14 May 2021 19:06:50 +0200 Subject: [PATCH] Switch BS type access operations in cloud layer Switch type access operations of the cloud layer to the proxy. Change-Id: I403a3fffc7bd5a6050eef586873c2cded89bb164 --- openstack/cloud/_block_storage.py | 38 +++---------------- .../tests/unit/cloud/test_volume_access.py | 26 +++++-------- 2 files changed, 14 insertions(+), 50 deletions(-) diff --git a/openstack/cloud/_block_storage.py b/openstack/cloud/_block_storage.py index 506fd7df9..e8ea09fa2 100644 --- a/openstack/cloud/_block_storage.py +++ b/openstack/cloud/_block_storage.py @@ -49,14 +49,7 @@ class BlockStorageCloudMixin(_normalize.Normalizer): :returns: A list of volume ``munch.Munch``. """ - resp = self.block_storage.get( - '/types', - params=dict(is_public='None')) - data = proxy._json_response( - resp, - error_message='Error fetching volume_type list') - return self._normalize_volume_types( - self._get_and_munchify('volume_types', data)) + return list(self.block_storage.types()) def get_volume(self, name_or_id, filters=None): """Get a volume by name or ID. @@ -734,14 +727,8 @@ class BlockStorageCloudMixin(_normalize.Normalizer): raise exc.OpenStackCloudException( "VolumeType not found: %s" % name_or_id) - resp = self.block_storage.get( - '/types/{id}/os-volume-type-access'.format(id=volume_type.id)) - data = proxy._json_response( - resp, - error_message="Unable to get volume type access" - " {name}".format(name=name_or_id)) return self._normalize_volume_type_accesses( - self._get_and_munchify('volume_type_access', data)) + self.block_storage.get_type_access(volume_type)) def add_volume_type_access(self, name_or_id, project_id): """Grant access on a volume_type to a project. @@ -757,15 +744,8 @@ class BlockStorageCloudMixin(_normalize.Normalizer): if not volume_type: raise exc.OpenStackCloudException( "VolumeType not found: %s" % name_or_id) - payload = {'project': project_id} - resp = self.block_storage.post( - '/types/{id}/action'.format(id=volume_type.id), - json=dict(addProjectAccess=payload)) - proxy._json_response( - resp, - error_message="Unable to authorize {project} " - "to use volume type {name}".format( - name=name_or_id, project=project_id)) + + self.block_storage.add_type_access(volume_type, project_id) def remove_volume_type_access(self, name_or_id, project_id): """Revoke access on a volume_type to a project. @@ -779,15 +759,7 @@ class BlockStorageCloudMixin(_normalize.Normalizer): if not volume_type: raise exc.OpenStackCloudException( "VolumeType not found: %s" % name_or_id) - payload = {'project': project_id} - resp = self.block_storage.post( - '/types/{id}/action'.format(id=volume_type.id), - json=dict(removeProjectAccess=payload)) - proxy._json_response( - resp, - error_message="Unable to revoke {project} " - "to use volume type {name}".format( - name=name_or_id, project=project_id)) + self.block_storage.remove_type_access(volume_type, project_id) def set_volume_quotas(self, name_or_id, **kwargs): """ Set a volume quota in a project diff --git a/openstack/tests/unit/cloud/test_volume_access.py b/openstack/tests/unit/cloud/test_volume_access.py index ec83ea4c5..f4f9ffffe 100644 --- a/openstack/tests/unit/cloud/test_volume_access.py +++ b/openstack/tests/unit/cloud/test_volume_access.py @@ -32,8 +32,7 @@ class TestVolumeAccess(base.TestCase): dict(method='GET', uri=self.get_mock_url( 'volumev2', 'public', - append=['types'], - qs_elements=['is_public=None']), + append=['types']), json={'volume_types': [volume_type]})]) self.assertTrue(self.cloud.list_volume_types()) self.assert_calls() @@ -46,8 +45,7 @@ class TestVolumeAccess(base.TestCase): dict(method='GET', uri=self.get_mock_url( 'volumev2', 'public', - append=['types'], - qs_elements=['is_public=None']), + append=['types']), json={'volume_types': [volume_type]})]) volume_type_got = self.cloud.get_volume_type(volume_type['name']) self.assertEqual(volume_type_got.id, volume_type['id']) @@ -64,8 +62,7 @@ class TestVolumeAccess(base.TestCase): dict(method='GET', uri=self.get_mock_url( 'volumev2', 'public', - append=['types'], - qs_elements=['is_public=None']), + append=['types']), json={'volume_types': [volume_type]}), dict(method='GET', uri=self.get_mock_url( @@ -90,8 +87,7 @@ class TestVolumeAccess(base.TestCase): dict(method='GET', uri=self.get_mock_url( 'volumev2', 'public', - append=['types'], - qs_elements=['is_public=None']), + append=['types']), json={'volume_types': [volume_type]}), dict(method='GET', uri=self.get_mock_url( @@ -102,7 +98,7 @@ class TestVolumeAccess(base.TestCase): dict(method='GET', uri=self.get_mock_url( 'volumev2', 'public', - append=['types'], qs_elements=['is_public=None']), + append=['types']), json={'volume_types': [volume_type]}), dict(method='POST', uri=self.get_mock_url( @@ -116,8 +112,7 @@ class TestVolumeAccess(base.TestCase): dict(method='GET', uri=self.get_mock_url( 'volumev2', 'public', - append=['types'], - qs_elements=['is_public=None']), + append=['types']), json={'volume_types': [volume_type]}), dict(method='GET', uri=self.get_mock_url( @@ -147,8 +142,7 @@ class TestVolumeAccess(base.TestCase): dict(method='GET', uri=self.get_mock_url( 'volumev2', 'public', - append=['types'], - qs_elements=['is_public=None']), + append=['types']), json={'volume_types': [volume_type]}), dict(method='POST', uri=self.get_mock_url( @@ -162,8 +156,7 @@ class TestVolumeAccess(base.TestCase): dict(method='GET', uri=self.get_mock_url( 'volumev2', 'public', - append=['types'], - qs_elements=['is_public=None']), + append=['types']), json={'volume_types': [volume_type]}), dict(method='GET', uri=self.get_mock_url( @@ -187,8 +180,7 @@ class TestVolumeAccess(base.TestCase): dict(method='GET', uri=self.get_mock_url( 'volumev2', 'public', - append=['types'], - qs_elements=['is_public=None']), + append=['types']), json={'volume_types': [volume_type]})]) with testtools.ExpectedException( openstack.cloud.OpenStackCloudException,