Merge "Enable Quota DB driver by default"

This commit is contained in:
Jenkins 2013-10-08 06:23:08 +00:00 committed by Gerrit Code Review
commit 5dc5854c32
9 changed files with 56 additions and 11 deletions

View 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

View 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):

View 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',

View 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

View 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()

View 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

View 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

View 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

View 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)}