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
This commit is contained in:
parent
efdc8c2a2b
commit
ee24cbffe4
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user