# 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
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
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
: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):
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
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',
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
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
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
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."""
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()
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
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
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
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
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
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
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)}