]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Load quota resources dynamically
authorGary Kotton <gkotton@redhat.com>
Wed, 6 Mar 2013 11:48:40 +0000 (11:48 +0000)
committerGary Kotton <gkotton@redhat.com>
Wed, 6 Mar 2013 19:00:35 +0000 (19:00 +0000)
Fixes bug 1149287

Change-Id: Ie02c7091f326c39f92e6a906c19e937e50227658

quantum/extensions/quotasv2.py
quantum/tests/unit/test_quota_per_tenant_ext.py

index 87015d39ba6f32a8669517d8875fcf818dc0096c..e68b791e6b50af0dc50b1f57f9dc8ad3a0e330a4 100644 (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)
index 5b1285d6685909054047d9b39605929c40a51852..d86b0e6b1ed23542e77b297fd8d513db776c3ab9 100644 (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',