]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Deprecate quota_items, register resources upon REST initialization
authorSalvatore Orlando <salv.orlando@gmail.com>
Sat, 9 May 2015 00:03:55 +0000 (17:03 -0700)
committerSalvatore Orlando <salv.orlando@gmail.com>
Mon, 11 May 2015 11:03:40 +0000 (04:03 -0700)
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

etc/neutron.conf
neutron/api/v2/router.py
neutron/quota.py
neutron/tests/unit/extensions/test_quotasv2.py

index 99a3ca3761ab95b5ed6ce30b27cffb9d11de8b30..ee42954bfe9dd1840771b4db0e4dae2837b9c4ef 100644 (file)
 # 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
index ee008f759de7e520f1cf45410648e708d871ff5a..1ae7852936a7874a8256cde0a45408ce6fb8ff6b 100644 (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,
index 95e398aed18b9a9042874a6c32c1c59897e0b360..cd6a6b71433537319011dc00854fd40a1b96394e 100644 (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)
index af87c4a76992005957478c3e1ed383a2602b14d4..7c1b51866a986cff813115e8cfd8cd83a3e1d195 100644 (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