]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
DbQuotaDriver allows negative quotas to be set.
authorStephen Ma <stephen.ma@hp.com>
Sat, 11 May 2013 03:24:55 +0000 (20:24 -0700)
committerStephen Ma <stephen.ma@hp.com>
Wed, 29 May 2013 14:47:43 +0000 (07:47 -0700)
Bug 1178886

Change-Id: I06ece65c2d77b8258bb871bb396edc5c145c383a

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

index 6ae86062ceea83f67ab8eb29702f965f41f8e06a..84dae73267c3b6847d85d403c9cfcba03842ca07 100644 (file)
@@ -15,6 +15,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import sys
+
 from oslo.config import cfg
 import webob
 
@@ -52,6 +54,8 @@ class QuotaSetsController(wsgi.Controller):
             attr_dict[quota_resource] = {'allow_post': False,
                                          'allow_put': True,
                                          'convert_to': convert_to_int,
+                                         'validate': {'type:range':
+                                                      [-1, sys.maxsize]},
                                          'is_visible': True}
         self._update_extended_attributes = False
 
@@ -98,7 +102,7 @@ class QuotaSetsController(wsgi.Controller):
         body = base.Controller.prepare_request_body(
             request.context, body, False, self._resource_name,
             EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION])
-        for key, value in body[self._resource_name].iteritems():
+        for key, value in body[self._resource_name].items():
             self._driver.update_quota_limit(request.context, id, key, value)
         return {self._resource_name: self._get_quotas(request, id)}
 
index 488fea3a39ca37555123c70ca8b91b4a29c123b3..5dc2ce411939b5477cc03c5ab04d6e6e3ca9d7f2 100644 (file)
@@ -175,6 +175,36 @@ class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
                            expect_errors=True)
         self.assertEqual(400, res.status_int)
 
+    def test_update_quotas_with_negative_integer_returns_400(self):
+        tenant_id = 'tenant_id1'
+        env = {'quantum.context': context.Context('', tenant_id,
+                                                  is_admin=True)}
+        quotas = {'quota': {'network': -2}}
+        res = self.api.put(_get_path('quotas', id=tenant_id, fmt=self.fmt),
+                           self.serialize(quotas), extra_environ=env,
+                           expect_errors=True)
+        self.assertEqual(400, res.status_int)
+
+    def test_update_quotas_to_unlimited(self):
+        tenant_id = 'tenant_id1'
+        env = {'quantum.context': context.Context('', tenant_id,
+                                                  is_admin=True)}
+        quotas = {'quota': {'network': -1}}
+        res = self.api.put(_get_path('quotas', id=tenant_id, fmt=self.fmt),
+                           self.serialize(quotas), extra_environ=env,
+                           expect_errors=False)
+        self.assertEqual(200, res.status_int)
+
+    def test_update_quotas_exceeding_current_limit(self):
+        tenant_id = 'tenant_id1'
+        env = {'quantum.context': context.Context('', tenant_id,
+                                                  is_admin=True)}
+        quotas = {'quota': {'network': 120}}
+        res = self.api.put(_get_path('quotas', id=tenant_id, fmt=self.fmt),
+                           self.serialize(quotas), extra_environ=env,
+                           expect_errors=False)
+        self.assertEqual(200, res.status_int)
+
     def test_update_quotas_with_non_support_resource_returns_400(self):
         tenant_id = 'tenant_id1'
         env = {'quantum.context': context.Context('', tenant_id,
@@ -251,26 +281,12 @@ class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
                                  tenant_id,
                                  network=4)
 
-    def test_quotas_limit_check_with_over_quota(self):
-        tenant_id = 'tenant_id1'
-        env = {'quantum.context': context.Context('', tenant_id,
-                                                  is_admin=True)}
-        quotas = {'quota': {'network': 5}}
-        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)
-        with testtools.ExpectedException(exceptions.OverQuota):
-            quota.QUOTAS.limit_check(context.Context('', tenant_id),
-                                     tenant_id,
-                                     network=6)
-
     def test_quotas_limit_check_with_invalid_quota_value(self):
         tenant_id = 'tenant_id1'
         with testtools.ExpectedException(exceptions.InvalidQuotaValue):
             quota.QUOTAS.limit_check(context.Context('', tenant_id),
                                      tenant_id,
-                                     network=-1)
+                                     network=-2)
 
     def test_quotas_get_tenant_from_request_context(self):
         tenant_id = 'tenant_id1'