From ee24cbffe478984ab5f1286da65d94c5d7c2e50b Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Thu, 23 Dec 2021 13:48:22 +0100 Subject: [PATCH] Switch quota_set cloud layer BS methods to proxy - Switch quota_set operations of the cloud layer block_storage to corresponding proxy implementation Change-Id: I58d70fb9ca961adc0e78a781b1be61956680a5b0 --- openstack/block_storage/v2/_proxy.py | 4 +++ openstack/block_storage/v3/_proxy.py | 4 +++ openstack/cloud/_block_storage.py | 41 ++++++++--------------- openstack/tests/unit/cloud/test_quotas.py | 33 +++++++++++++----- 4 files changed, 46 insertions(+), 36 deletions(-) diff --git a/openstack/block_storage/v2/_proxy.py b/openstack/block_storage/v2/_proxy.py index b98601375..358ae1ea7 100644 --- a/openstack/block_storage/v2/_proxy.py +++ b/openstack/block_storage/v2/_proxy.py @@ -609,6 +609,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy): res = self._get_resource( _quota_set.QuotaSet, None, project_id=project.id) + if not query: + query = {} return res.delete(self, **query) def update_quota_set(self, quota_set, query=None, **attrs): @@ -624,6 +626,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy): :rtype: :class:`~openstack.block_storage.v2.quota_set.QuotaSet` """ res = self._get_resource(_quota_set.QuotaSet, quota_set, **attrs) + if not query: + query = {} return res.commit(self, **query) def get_volume_metadata(self, volume): diff --git a/openstack/block_storage/v3/_proxy.py b/openstack/block_storage/v3/_proxy.py index 028e23f93..61232b777 100644 --- a/openstack/block_storage/v3/_proxy.py +++ b/openstack/block_storage/v3/_proxy.py @@ -1079,6 +1079,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy): res = self._get_resource( _quota_set.QuotaSet, None, project_id=project.id) + if not query: + query = {} return res.delete(self, **query) def update_quota_set(self, quota_set, query=None, **attrs): @@ -1094,6 +1096,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy): :rtype: :class:`~openstack.block_storage.v3.quota_set.QuotaSet` """ res = self._get_resource(_quota_set.QuotaSet, quota_set, **attrs) + if not query: + query = {} return res.commit(self, **query) def _get_cleanup_dependencies(self): diff --git a/openstack/cloud/_block_storage.py b/openstack/cloud/_block_storage.py index ccd11b322..b58e24017 100644 --- a/openstack/cloud/_block_storage.py +++ b/openstack/cloud/_block_storage.py @@ -15,6 +15,7 @@ # openstack.resource.Resource.list and openstack.resource2.Resource.list import types # noqa +from openstack.block_storage.v3 import quota_set as _qs from openstack.cloud import _normalize from openstack.cloud import _utils from openstack.cloud import exc @@ -649,17 +650,12 @@ class BlockStorageCloudMixin(_normalize.Normalizer): quota does not exist. """ - proj = self.get_project(name_or_id) - if not proj: - raise exc.OpenStackCloudException("project does not exist") + proj = self.identity.find_project( + name_or_id, ignore_missing=False) - kwargs['tenant_id'] = proj.id - resp = self.block_storage.put( - '/os-quota-sets/{tenant_id}'.format(tenant_id=proj.id), - json={'quota_set': kwargs}) - proxy._json_response( - resp, - error_message="No valid quota or resource") + self.block_storage.update_quota_set( + _qs.QuotaSet(project_id=proj.id), + **kwargs) def get_volume_quotas(self, name_or_id): """ Get volume quotas for a project @@ -669,16 +665,11 @@ class BlockStorageCloudMixin(_normalize.Normalizer): :returns: Munch object with the quotas """ - proj = self.get_project(name_or_id) - if not proj: - raise exc.OpenStackCloudException("project does not exist") + proj = self.identity.find_project( + name_or_id, ignore_missing=False) - resp = self.block_storage.get( - '/os-quota-sets/{tenant_id}'.format(tenant_id=proj.id)) - data = proxy._json_response( - resp, - error_message="cinder client call failed") - return self._get_and_munchify('quota_set', data) + return self.block_storage.get_quota_set( + proj) def delete_volume_quotas(self, name_or_id): """ Delete volume quotas for a project @@ -689,12 +680,8 @@ class BlockStorageCloudMixin(_normalize.Normalizer): :returns: dict with the quotas """ - proj = self.get_project(name_or_id) - if not proj: - raise exc.OpenStackCloudException("project does not exist") + proj = self.identity.find_project( + name_or_id, ignore_missing=False) - resp = self.block_storage.delete( - '/os-quota-sets/{tenant_id}'.format(tenant_id=proj.id)) - return proxy._json_response( - resp, - error_message="cinder client call failed") + return self.block_storage.revert_quota_set( + proj) diff --git a/openstack/tests/unit/cloud/test_quotas.py b/openstack/tests/unit/cloud/test_quotas.py index 9671b2e67..f338e94d7 100644 --- a/openstack/tests/unit/cloud/test_quotas.py +++ b/openstack/tests/unit/cloud/test_quotas.py @@ -107,9 +107,14 @@ class TestQuotas(base.TestCase): self.assert_calls() def test_cinder_update_quotas(self): - project = self.mock_for_keystone_projects(project_count=1, - list_get=True)[0] + project = self._get_project_data() + self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + 'identity', 'public', + append=['v3', 'projects', project.project_id]), + json={'project': project.json_response['project']}), self.get_cinder_discovery_mock_dict(), dict(method='PUT', uri=self.get_mock_url( @@ -118,28 +123,38 @@ class TestQuotas(base.TestCase): json=dict(quota_set={'volumes': 1}), validate=dict( json={'quota_set': { - 'volumes': 1, - 'tenant_id': project.project_id}}))]) + 'volumes': 1}}))]) self.cloud.set_volume_quotas(project.project_id, volumes=1) self.assert_calls() def test_cinder_get_quotas(self): - project = self.mock_for_keystone_projects(project_count=1, - list_get=True)[0] + project = self._get_project_data() + self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + 'identity', 'public', + append=['v3', 'projects', project.project_id]), + json={'project': project.json_response['project']}), self.get_cinder_discovery_mock_dict(), dict(method='GET', uri=self.get_mock_url( 'volumev3', 'public', - append=['os-quota-sets', project.project_id]), + append=['os-quota-sets', project.project_id], + qs_elements=['usage=False']), json=dict(quota_set={'snapshots': 10, 'volumes': 20}))]) self.cloud.get_volume_quotas(project.project_id) self.assert_calls() def test_cinder_delete_quotas(self): - project = self.mock_for_keystone_projects(project_count=1, - list_get=True)[0] + project = self._get_project_data() + self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + 'identity', 'public', + append=['v3', 'projects', project.project_id]), + json={'project': project.json_response['project']}), self.get_cinder_discovery_mock_dict(), dict(method='DELETE', uri=self.get_mock_url(