Load quota resources dynamically

Fixes bug 1149287

Change-Id: Ie02c7091f326c39f92e6a906c19e937e50227658
This commit is contained in:
Gary Kotton 2013-03-06 11:48:40 +00:00
parent 4673c9376e
commit 08ee0f9cbb
2 changed files with 27 additions and 7 deletions

View File

@ -35,13 +35,6 @@ EXTENDED_ATTRIBUTES_2_0 = {
RESOURCE_COLLECTION: {}
}
for quota_resource in QUOTAS.resources.iterkeys():
attr_dict = EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION]
attr_dict[quota_resource] = {'allow_post': False,
'allow_put': True,
'convert_to': int,
'is_visible': True}
class QuotaSetsController(wsgi.Controller):
@ -49,10 +42,23 @@ class QuotaSetsController(wsgi.Controller):
self._resource_name = RESOURCE_NAME
self._plugin = plugin
self._driver = importutils.import_class(DB_QUOTA_DRIVER)
self._update_extended_attributes = True
def _update_attributes(self):
for quota_resource in QUOTAS.resources.iterkeys():
attr_dict = EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION]
attr_dict[quota_resource] = {'allow_post': False,
'allow_put': True,
'convert_to': int,
'is_visible': True}
self._update_extended_attributes = False
def _get_body(self, request):
body = self._deserialize(request.body,
request.best_match_content_type())
if self._update_extended_attributes is True:
self._update_attributes()
attr_info = EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION]
req_body = base.Controller.prepare_request_body(
request.context, body, False, self._resource_name, attr_info)

View File

@ -139,6 +139,20 @@ class QuotaExtensionTestCase(testlib_api.WebTestCase):
quota = self.deserialize(res)
self.assertEqual(100, quota['quota']['network'])
def test_update_attributes(self):
tenant_id = 'tenant_id1'
env = {'quantum.context': context.Context('', tenant_id + '2',
is_admin=True)}
quotas = {'quota': {'extra1': 100}}
res = self.api.put(_get_path('quotas', id=tenant_id, fmt=self.fmt),
self.serialize(quotas), extra_environ=env)
self.assertEqual(200, res.status_int)
env2 = {'quantum.context': context.Context('', tenant_id)}
res = self.api.get(_get_path('quotas', id=tenant_id, fmt=self.fmt),
extra_environ=env2)
quota = self.deserialize(res)
self.assertEqual(100, quota['quota']['extra1'])
def test_delete_quotas_with_admin(self):
tenant_id = 'tenant_id1'
env = {'quantum.context': context.Context('', tenant_id + '2',