Deprecate quota_items, register resources upon REST initialization

Register 'core' resources when the respective rest controllers are
instantiated, rather than at module load time.

Since in this way there will not be any need to iterate over
quota_items, the option is being deprecated.

This patch does not supply unit tests as the already-existing
routine for registering a resource from quota_items is being
deprecated as well (and was not covered by any unit test beforehand).

DocImpact

Change-Id: Icdb744adfd86d38363239a454ccf04f3c6b9c158
Closes-Bug: #1453322
This commit is contained in:
Salvatore Orlando 2015-05-08 17:03:55 -07:00
parent 0699836be6
commit a6b6e5597f
4 changed files with 22 additions and 3 deletions

View File

@ -586,6 +586,7 @@
# quota_driver = neutron.db.quota_db.DbQuotaDriver
# Resource name(s) that are supported in quota features
# This option is deprecated for removal in the M release, please refrain from using it
# quota_items = network,subnet,port
# Default number of resource allowed per tenant. A negative value means

View File

@ -26,6 +26,7 @@ from neutron.api.v2 import attributes
from neutron.api.v2 import base
from neutron import manager
from neutron import policy
from neutron import quota
from neutron import wsgi
@ -104,6 +105,7 @@ class APIRouter(wsgi.Router):
_map_resource(RESOURCES[resource], resource,
attributes.RESOURCE_ATTRIBUTE_MAP.get(
RESOURCES[resource], dict()))
quota.QUOTAS.register_resource_by_name(resource)
for resource in SUB_RESOURCES:
_map_resource(SUB_RESOURCES[resource]['collection_name'], resource,

View File

@ -30,12 +30,15 @@ LOG = logging.getLogger(__name__)
QUOTA_DB_MODULE = 'neutron.db.quota_db'
QUOTA_DB_DRIVER = 'neutron.db.quota_db.DbQuotaDriver'
QUOTA_CONF_DRIVER = 'neutron.quota.ConfDriver'
default_quota_items = ['network', 'subnet', 'port']
quota_opts = [
cfg.ListOpt('quota_items',
default=['network', 'subnet', 'port'],
default=default_quota_items,
deprecated_for_removal=True,
help=_('Resource name(s) that are supported in quota '
'features')),
'features. This option is now deprecated for '
'removal.')),
cfg.IntOpt('default_quota',
default=-1,
help=_('Default number of resource allowed per tenant. '
@ -330,8 +333,17 @@ def _count_resource(context, plugin, resources, tenant_id):
def register_resources_from_config():
# This operation is now deprecated. All the neutron core and extended
# resource for which quota limits are enforced explicitly register
# themselves with the quota engine.
versionutils.report_deprecated_feature(
LOG, _LW("Registering resources to apply quota limits to using the "
"quota_items option is deprecated as of Liberty."
"Resource REST controllers should take care of registering "
"resources with the quota engine."))
resources = []
for resource_item in cfg.CONF.QUOTAS.quota_items:
for resource_item in (set(cfg.CONF.QUOTAS.quota_items) -
set(default_quota_items)):
resources.append(CountableResource(resource_item, _count_resource,
'quota_' + resource_item))
QUOTAS.register_resources(resources)

View File

@ -22,6 +22,7 @@ from webob import exc
import webtest
from neutron.api import extensions
from neutron.api.v2 import router
from neutron.common import config
from neutron.common import constants
from neutron.common import exceptions
@ -68,6 +69,9 @@ class QuotaExtensionTestCase(testlib_api.WebTestCase):
app = config.load_paste_app('extensions_test_app')
ext_middleware = extensions.ExtensionMiddleware(app, ext_mgr=ext_mgr)
self.api = webtest.TestApp(ext_middleware)
# Initialize the router for the core API in order to ensure core quota
# resources are registered
router.APIRouter()
def tearDown(self):
self.api = None