]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Treat all negative quota values as -1
authorSudipta Biswas <sbiswas7@in.ibm.com>
Thu, 2 Apr 2015 09:36:35 +0000 (15:06 +0530)
committerSudipta Biswas <sbiswas7@in.ibm.com>
Thu, 2 Apr 2015 11:56:51 +0000 (17:26 +0530)
Currently if the quota_port, quota_network, quota_subnet values
in the neutron.conf are set to a negative value not equal to -1,
neutron reports the values as is to consumers like Nova.
Nova treats -1 as the infinite quota indicator and doesn't expect
neutron to return any other non-negative value.

The fix allows the flexibility of having any negative number for the
quota parameters in the neutron.conf file and allows the nova boot
to succeed subsequently. The fix would report any negative value
as -1 for port, subnet and network.

Change-Id: Ib9a7136b0bfd01bdf04a5d0937854590029b1010
Closes-Bug: 1438738
Co-Authored-By: Salvatore Orlando <salv.orlando@gmail.com>
neutron/quota.py
neutron/tests/unit/test_quota_ext.py

index ae718cb929979b966db5b6a0857601be1cd9eeb0..3cf8e11d944c35a74fbf7d4e3cf214deefc0b4e9 100644 (file)
@@ -156,9 +156,12 @@ class BaseResource(object):
     @property
     def default(self):
         """Return the default value of the quota."""
-        return getattr(cfg.CONF.QUOTAS,
-                       self.flag,
-                       cfg.CONF.QUOTAS.default_quota)
+        # Any negative value will be interpreted as an infinite quota,
+        # and stored as -1 for compatibility with current behaviour
+        value = getattr(cfg.CONF.QUOTAS,
+                        self.flag,
+                        cfg.CONF.QUOTAS.default_quota)
+        return max(value, -1)
 
 
 class CountableResource(BaseResource):
index 608d9fb8a9e8e5de08673cd12641b6e9ac9e5c80..257445bd717cc689e1715872c0294c20616486d2 100644 (file)
@@ -79,6 +79,16 @@ class QuotaExtensionTestCase(testlib_api.WebTestCase):
         attributes.RESOURCE_ATTRIBUTE_MAP = self.saved_attr_map
         super(QuotaExtensionTestCase, self).tearDown()
 
+    def _test_quota_default_values(self, expected_values):
+        tenant_id = 'tenant_id1'
+        env = {'neutron.context': context.Context('', tenant_id)}
+        res = self.api.get(_get_path('quotas', id=tenant_id, fmt=self.fmt),
+                           extra_environ=env)
+        quota = self.deserialize(res)
+        for resource, expected_value in expected_values.items():
+            self.assertEqual(expected_value,
+                             quota['quota'][resource])
+
 
 class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
     fmt = 'json'
@@ -97,15 +107,24 @@ class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
         self.assertEqual(200, res.status_int)
 
     def test_quotas_default_values(self):
-        tenant_id = 'tenant_id1'
-        env = {'neutron.context': context.Context('', tenant_id)}
-        res = self.api.get(_get_path('quotas', id=tenant_id, fmt=self.fmt),
-                           extra_environ=env)
-        quota = self.deserialize(res)
-        self.assertEqual(10, quota['quota']['network'])
-        self.assertEqual(10, quota['quota']['subnet'])
-        self.assertEqual(50, quota['quota']['port'])
-        self.assertEqual(-1, quota['quota']['extra1'])
+        self._test_quota_default_values(
+            {'network': 10,
+             'subnet': 10,
+             'port': 50,
+             'extra1': -1})
+
+    def test_quotas_negative_default_value(self):
+        cfg.CONF.set_override(
+            'quota_port', -666, group='QUOTAS')
+        cfg.CONF.set_override(
+            'quota_network', -10, group='QUOTAS')
+        cfg.CONF.set_override(
+            'quota_subnet', -50, group='QUOTAS')
+        self._test_quota_default_values(
+            {'network': -1,
+             'subnet': -1,
+             'port': -1,
+             'extra1': -1})
 
     def test_show_quotas_with_admin(self):
         tenant_id = 'tenant_id1'
@@ -337,15 +356,20 @@ class QuotaExtensionCfgTestCase(QuotaExtensionTestCase):
         super(QuotaExtensionCfgTestCase, self).setUp()
 
     def test_quotas_default_values(self):
-        tenant_id = 'tenant_id1'
-        env = {'neutron.context': context.Context('', tenant_id)}
-        res = self.api.get(_get_path('quotas', id=tenant_id, fmt=self.fmt),
-                           extra_environ=env)
-        quota = self.deserialize(res)
-        self.assertEqual(10, quota['quota']['network'])
-        self.assertEqual(10, quota['quota']['subnet'])
-        self.assertEqual(50, quota['quota']['port'])
-        self.assertEqual(-1, quota['quota']['extra1'])
+        self._test_quota_default_values(
+            {'network': 10,
+             'subnet': 10,
+             'port': 50,
+             'extra1': -1})
+
+    def test_quotas_negative_default_value(self):
+        cfg.CONF.set_override(
+            'quota_port', -666, group='QUOTAS')
+        self._test_quota_default_values(
+            {'network': 10,
+             'subnet': 10,
+             'port': -1,
+             'extra1': -1})
 
     def test_show_quotas_with_admin(self):
         tenant_id = 'tenant_id1'