Merge "Switch quota_set cloud layer BS methods to proxy" into feature/r1

This commit is contained in:
Zuul 2021-12-28 13:38:14 +00:00 committed by Gerrit Code Review
commit b23de23ee7
4 changed files with 46 additions and 36 deletions

View File

@ -609,6 +609,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
res = self._get_resource( res = self._get_resource(
_quota_set.QuotaSet, None, project_id=project.id) _quota_set.QuotaSet, None, project_id=project.id)
if not query:
query = {}
return res.delete(self, **query) return res.delete(self, **query)
def update_quota_set(self, quota_set, query=None, **attrs): 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` :rtype: :class:`~openstack.block_storage.v2.quota_set.QuotaSet`
""" """
res = self._get_resource(_quota_set.QuotaSet, quota_set, **attrs) res = self._get_resource(_quota_set.QuotaSet, quota_set, **attrs)
if not query:
query = {}
return res.commit(self, **query) return res.commit(self, **query)
def get_volume_metadata(self, volume): def get_volume_metadata(self, volume):

View File

@ -1079,6 +1079,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
res = self._get_resource( res = self._get_resource(
_quota_set.QuotaSet, None, project_id=project.id) _quota_set.QuotaSet, None, project_id=project.id)
if not query:
query = {}
return res.delete(self, **query) return res.delete(self, **query)
def update_quota_set(self, quota_set, query=None, **attrs): 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` :rtype: :class:`~openstack.block_storage.v3.quota_set.QuotaSet`
""" """
res = self._get_resource(_quota_set.QuotaSet, quota_set, **attrs) res = self._get_resource(_quota_set.QuotaSet, quota_set, **attrs)
if not query:
query = {}
return res.commit(self, **query) return res.commit(self, **query)
def _get_cleanup_dependencies(self): def _get_cleanup_dependencies(self):

View File

@ -15,6 +15,7 @@
# openstack.resource.Resource.list and openstack.resource2.Resource.list # openstack.resource.Resource.list and openstack.resource2.Resource.list
import types # noqa import types # noqa
from openstack.block_storage.v3 import quota_set as _qs
from openstack.cloud import _normalize from openstack.cloud import _normalize
from openstack.cloud import _utils from openstack.cloud import _utils
from openstack.cloud import exc from openstack.cloud import exc
@ -649,17 +650,12 @@ class BlockStorageCloudMixin(_normalize.Normalizer):
quota does not exist. quota does not exist.
""" """
proj = self.get_project(name_or_id) proj = self.identity.find_project(
if not proj: name_or_id, ignore_missing=False)
raise exc.OpenStackCloudException("project does not exist")
kwargs['tenant_id'] = proj.id self.block_storage.update_quota_set(
resp = self.block_storage.put( _qs.QuotaSet(project_id=proj.id),
'/os-quota-sets/{tenant_id}'.format(tenant_id=proj.id), **kwargs)
json={'quota_set': kwargs})
proxy._json_response(
resp,
error_message="No valid quota or resource")
def get_volume_quotas(self, name_or_id): def get_volume_quotas(self, name_or_id):
""" Get volume quotas for a project """ Get volume quotas for a project
@ -669,16 +665,11 @@ class BlockStorageCloudMixin(_normalize.Normalizer):
:returns: Munch object with the quotas :returns: Munch object with the quotas
""" """
proj = self.get_project(name_or_id) proj = self.identity.find_project(
if not proj: name_or_id, ignore_missing=False)
raise exc.OpenStackCloudException("project does not exist")
resp = self.block_storage.get( return self.block_storage.get_quota_set(
'/os-quota-sets/{tenant_id}'.format(tenant_id=proj.id)) proj)
data = proxy._json_response(
resp,
error_message="cinder client call failed")
return self._get_and_munchify('quota_set', data)
def delete_volume_quotas(self, name_or_id): def delete_volume_quotas(self, name_or_id):
""" Delete volume quotas for a project """ Delete volume quotas for a project
@ -689,12 +680,8 @@ class BlockStorageCloudMixin(_normalize.Normalizer):
:returns: dict with the quotas :returns: dict with the quotas
""" """
proj = self.get_project(name_or_id) proj = self.identity.find_project(
if not proj: name_or_id, ignore_missing=False)
raise exc.OpenStackCloudException("project does not exist")
resp = self.block_storage.delete( return self.block_storage.revert_quota_set(
'/os-quota-sets/{tenant_id}'.format(tenant_id=proj.id)) proj)
return proxy._json_response(
resp,
error_message="cinder client call failed")

View File

@ -128,9 +128,14 @@ class TestQuotas(base.TestCase):
self.assert_calls() self.assert_calls()
def test_cinder_update_quotas(self): def test_cinder_update_quotas(self):
project = self.mock_for_keystone_projects(project_count=1, project = self._get_project_data()
list_get=True)[0]
self.register_uris([ 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(), self.get_cinder_discovery_mock_dict(),
dict(method='PUT', dict(method='PUT',
uri=self.get_mock_url( uri=self.get_mock_url(
@ -139,28 +144,38 @@ class TestQuotas(base.TestCase):
json=dict(quota_set={'volumes': 1}), json=dict(quota_set={'volumes': 1}),
validate=dict( validate=dict(
json={'quota_set': { json={'quota_set': {
'volumes': 1, 'volumes': 1}}))])
'tenant_id': project.project_id}}))])
self.cloud.set_volume_quotas(project.project_id, volumes=1) self.cloud.set_volume_quotas(project.project_id, volumes=1)
self.assert_calls() self.assert_calls()
def test_cinder_get_quotas(self): def test_cinder_get_quotas(self):
project = self.mock_for_keystone_projects(project_count=1, project = self._get_project_data()
list_get=True)[0]
self.register_uris([ 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(), self.get_cinder_discovery_mock_dict(),
dict(method='GET', dict(method='GET',
uri=self.get_mock_url( uri=self.get_mock_url(
'volumev3', 'public', '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}))]) json=dict(quota_set={'snapshots': 10, 'volumes': 20}))])
self.cloud.get_volume_quotas(project.project_id) self.cloud.get_volume_quotas(project.project_id)
self.assert_calls() self.assert_calls()
def test_cinder_delete_quotas(self): def test_cinder_delete_quotas(self):
project = self.mock_for_keystone_projects(project_count=1, project = self._get_project_data()
list_get=True)[0]
self.register_uris([ 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(), self.get_cinder_discovery_mock_dict(),
dict(method='DELETE', dict(method='DELETE',
uri=self.get_mock_url( uri=self.get_mock_url(