]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable Quota DB driver by default
authorAkihiro MOTOKI <motoki@da.jp.nec.com>
Sun, 6 Oct 2013 23:38:07 +0000 (08:38 +0900)
committerMark McClain <mark.mcclain@dreamhost.com>
Tue, 8 Oct 2013 15:00:56 +0000 (11:00 -0400)
Closes-Bug: #1189671

Quota driver is now loaded in lazy mode, i.e. the driver is loaded
the first time the driver is accessed. This is to make unit tests
work. Some unit tests like extension test cases need to use Config
Quota driver (previous default) but QuotaEngine is initialized
when quota.py is imported. Thus the unit tests had no chance to
specify quota_driver.

Change-Id: I9e20961d5a6322361e3c0284b3c2a7ca86755c70

etc/neutron.conf
neutron/quota.py
neutron/tests/unit/nicira/test_networkgw.py
neutron/tests/unit/services/vpn/test_vpnaas_extension.py
neutron/tests/unit/test_api_v2.py
neutron/tests/unit/test_extension_extended_attribute.py
neutron/tests/unit/test_extension_pnet.py
neutron/tests/unit/test_l3_plugin.py
neutron/tests/unit/test_quota_ext.py

index 5abf669175794d9340537f4401b0a9013f2c5a49..bfa13530378ee7488abb3f0e0893cb1d0e89318e 100644 (file)
@@ -288,7 +288,7 @@ notification_driver = neutron.openstack.common.notifier.rpc_notifier
 # quota_security_group_rule = 100
 
 # default driver to use for quota checks
-# quota_driver = neutron.quota.ConfDriver
+# quota_driver = neutron.db.quota_db.DbQuotaDriver
 
 [agent]
 # Use "sudo neutron-rootwrap /etc/neutron/rootwrap.conf" to use the real
index 02a7cebd61dffa5e0b8f864777f8493263cc55de..908b256f2ce0d6179c1e428085126b4e7d1d39f2 100644 (file)
@@ -47,7 +47,7 @@ quota_opts = [
                help=_('Number of ports allowed per tenant, minus for '
                       'unlimited')),
     cfg.StrOpt('quota_driver',
-               default='neutron.quota.ConfDriver',
+               default='neutron.db.quota_db.DbQuotaDriver',
                help=_('Default driver to use for quota checks')),
 ]
 # Register the configuration options
@@ -209,14 +209,18 @@ class QuotaEngine(object):
     def __init__(self, quota_driver_class=None):
         """Initialize a Quota object."""
 
-        if not quota_driver_class:
-            quota_driver_class = cfg.CONF.QUOTAS.quota_driver
-
-        if isinstance(quota_driver_class, basestring):
-            quota_driver_class = importutils.import_object(quota_driver_class)
-
         self._resources = {}
-        self._driver = quota_driver_class
+        self._driver = None
+        self._driver_class = quota_driver_class
+
+    def get_driver(self):
+        if self._driver is None:
+            _driver_class = (self._driver_class or
+                             cfg.CONF.QUOTAS.quota_driver)
+            if isinstance(_driver_class, basestring):
+                _driver_class = importutils.import_object(_driver_class)
+            self._driver = _driver_class
+        return self._driver
 
     def __contains__(self, resource):
         return resource in self._resources
@@ -281,8 +285,8 @@ class QuotaEngine(object):
         :param context: The request context, for access checks.
         """
 
-        return self._driver.limit_check(context, tenant_id,
-                                        self._resources, values)
+        return self.get_driver().limit_check(context, tenant_id,
+                                             self._resources, values)
 
     @property
     def resources(self):
index ab19a6c3ce639e6a5fc86c146cb5e965282daa35..5a4259e5eb5e2a9d2e39294a27a23ec4232cf654 100644 (file)
@@ -32,6 +32,7 @@ from neutron.db import db_base_plugin_v2
 from neutron import manager
 from neutron.plugins.nicira.dbexts import nicira_networkgw_db
 from neutron.plugins.nicira.extensions import nvp_networkgw as networkgw
+from neutron import quota
 from neutron.tests import base
 from neutron.tests.unit import test_api_v2
 from neutron.tests.unit import test_db_plugin
@@ -93,6 +94,10 @@ class NetworkGatewayExtensionTestCase(base.BaseTestCase):
         self.ext_mdw = test_extensions.setup_extensions_middleware(ext_mgr)
         self.api = webtest.TestApp(self.ext_mdw)
 
+        quota.QUOTAS._driver = None
+        cfg.CONF.set_override('quota_driver', 'neutron.quota.ConfDriver',
+                              group='QUOTAS')
+
     def test_network_gateway_create(self):
         nw_gw_id = _uuid()
         data = {self._resource: {'name': 'nw-gw',
index d1f8954534d93bab5ae360b54050e92c1837a1ba..b3acadf575a0881813d03e7dc51229092f626fb5 100644 (file)
@@ -31,6 +31,7 @@ from neutron.extensions import vpnaas
 from neutron import manager
 from neutron.openstack.common import uuidutils
 from neutron.plugins.common import constants
+from neutron import quota
 from neutron.tests.unit import test_api_v2
 from neutron.tests.unit import test_extensions
 from neutron.tests.unit import testlib_api
@@ -88,6 +89,10 @@ class VpnaasExtensionTestCase(testlib_api.WebTestCase):
         self.api = webtest.TestApp(self.ext_mdw)
         super(VpnaasExtensionTestCase, self).setUp()
 
+        quota.QUOTAS._driver = None
+        cfg.CONF.set_override('quota_driver', 'neutron.quota.ConfDriver',
+                              group='QUOTAS')
+
     def tearDown(self):
         self._plugin_patcher.stop()
         self.api = None
index 3268bbac18ce92b4671d553849b6cb96930cc881..61e3eb371a7c6c93b0da620ebc42956fe74dbea9 100644 (file)
@@ -36,6 +36,7 @@ from neutron.manager import NeutronManager
 from neutron.openstack.common.notifier import api as notifer_api
 from neutron.openstack.common import policy as common_policy
 from neutron.openstack.common import uuidutils
+from neutron import quota
 from neutron.tests import base
 from neutron.tests.unit import testlib_api
 
@@ -118,6 +119,10 @@ class APIv2TestBase(base.BaseTestCase):
         api = router.APIRouter()
         self.api = webtest.TestApp(api)
 
+        quota.QUOTAS._driver = None
+        cfg.CONF.set_override('quota_driver', 'neutron.quota.ConfDriver',
+                              group='QUOTAS')
+
 
 class _ArgMatcher(object):
     """An adapter to assist mock assertions, used to custom compare."""
@@ -1377,6 +1382,10 @@ class ExtensionTestCase(base.BaseTestCase):
         api = router.APIRouter()
         self.api = webtest.TestApp(api)
 
+        quota.QUOTAS._driver = None
+        cfg.CONF.set_override('quota_driver', 'neutron.quota.ConfDriver',
+                              group='QUOTAS')
+
     def tearDown(self):
         super(ExtensionTestCase, self).tearDown()
         self._plugin_patcher.stop()
index 92a0c3cecd7cb032ff3593f4435bd3a1d2842e13..6cc32f0a96573a884934c118a3fc81d12cf601cc 100644 (file)
@@ -29,6 +29,7 @@ from neutron.common import config
 from neutron import manager
 from neutron.plugins.common import constants
 from neutron.plugins.openvswitch import ovs_neutron_plugin
+from neutron import quota
 from neutron.tests import base
 from neutron.tests.unit.extensions import extendedattribute as extattr
 from neutron.tests.unit import test_api_v2
@@ -108,6 +109,10 @@ class ExtensionExtendedAttributeTestCase(base.BaseTestCase):
         self.addCleanup(cfg.CONF.reset)
         self.addCleanup(self.restore_attribute_map)
 
+        quota.QUOTAS._driver = None
+        cfg.CONF.set_override('quota_driver', 'neutron.quota.ConfDriver',
+                              group='QUOTAS')
+
     def restore_attribute_map(self):
         # Restore the original RESOURCE_ATTRIBUTE_MAP
         attributes.RESOURCE_ATTRIBUTE_MAP = self.saved_attr_map
index 41080052edafd1672c5f3a87b5198a419fe46276..f69d6b14b1b4f027936d50692ff83b55d74a55d1 100644 (file)
@@ -30,6 +30,7 @@ from neutron import context
 from neutron.extensions import providernet as pnet
 from neutron.manager import NeutronManager
 from neutron.openstack.common import uuidutils
+from neutron import quota
 from neutron.tests.unit import test_api_v2
 from neutron.tests.unit import test_extensions
 from neutron.tests.unit import testlib_api
@@ -87,6 +88,10 @@ class ProvidernetExtensionTestCase(testlib_api.WebTestCase):
         self.addCleanup(self._restore_attribute_map)
         self.api = webtest.TestApp(router.APIRouter())
 
+        quota.QUOTAS._driver = None
+        cfg.CONF.set_override('quota_driver', 'neutron.quota.ConfDriver',
+                              group='QUOTAS')
+
     def _restore_attribute_map(self):
         # Restore the global RESOURCE_ATTRIBUTE_MAP
         attributes.RESOURCE_ATTRIBUTE_MAP = self.saved_attr_map
index 0c7aef7002e5d15d5b52049d8f62a4a59a03ddd7..4f75b576cfa83037542b182c259052954cf636c0 100644 (file)
@@ -46,6 +46,7 @@ from neutron.openstack.common.notifier import api as notifier_api
 from neutron.openstack.common.notifier import test_notifier
 from neutron.openstack.common import uuidutils
 from neutron.plugins.common import constants as service_constants
+from neutron import quota
 from neutron.tests.unit import test_api_v2
 from neutron.tests.unit import test_db_plugin
 from neutron.tests.unit import test_extensions
@@ -114,6 +115,10 @@ class L3NatExtensionTestCase(testlib_api.WebTestCase):
         self.ext_mdw = test_extensions.setup_extensions_middleware(ext_mgr)
         self.api = webtest.TestApp(self.ext_mdw)
 
+        quota.QUOTAS._driver = None
+        cfg.CONF.set_override('quota_driver', 'neutron.quota.ConfDriver',
+                              group='QUOTAS')
+
     def tearDown(self):
         self._plugin_patcher.stop()
         self.api = None
index 9e462edff1d33c0b7dc1f0f5fc348329f773679d..3f572adf6d098f6f7d971360f5ec01a83e2e3558 100644 (file)
@@ -327,6 +327,13 @@ class QuotaExtensionDbTestCaseXML(QuotaExtensionDbTestCase):
 class QuotaExtensionCfgTestCase(QuotaExtensionTestCase):
     fmt = 'json'
 
+    def setUp(self):
+        cfg.CONF.set_override(
+            'quota_driver',
+            'neutron.quota.ConfDriver',
+            group='QUOTAS')
+        super(QuotaExtensionCfgTestCase, self).setUp()
+
     def test_quotas_default_values(self):
         tenant_id = 'tenant_id1'
         env = {'neutron.context': context.Context('', tenant_id)}