From: Salvatore Orlando Date: Sat, 9 May 2015 00:03:55 +0000 (-0700) Subject: Deprecate quota_items, register resources upon REST initialization X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a6b6e5597f32dfb0d92dc168d91e83d6daafe227;p=openstack-build%2Fneutron-build.git 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 --- diff --git a/etc/neutron.conf b/etc/neutron.conf index 99a3ca376..ee42954bf 100644 --- a/etc/neutron.conf +++ b/etc/neutron.conf @@ -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 diff --git a/neutron/api/v2/router.py b/neutron/api/v2/router.py index ee008f759..1ae785293 100644 --- a/neutron/api/v2/router.py +++ b/neutron/api/v2/router.py @@ -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, diff --git a/neutron/quota.py b/neutron/quota.py index 95e398aed..cd6a6b714 100644 --- a/neutron/quota.py +++ b/neutron/quota.py @@ -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) diff --git a/neutron/tests/unit/extensions/test_quotasv2.py b/neutron/tests/unit/extensions/test_quotasv2.py index af87c4a76..7c1b51866 100644 --- a/neutron/tests/unit/extensions/test_quotasv2.py +++ b/neutron/tests/unit/extensions/test_quotasv2.py @@ -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