]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Pecan: Fix quota enforcement
authorSalvatore Orlando <salv.orlando@gmail.com>
Thu, 1 Oct 2015 23:07:59 +0000 (16:07 -0700)
committerKyle Mestery <mestery@mestery.com>
Fri, 2 Oct 2015 15:58:05 +0000 (15:58 +0000)
Ensure that core resources, and not only extension resources,
are registered with the quota engine. Otherwise no enforcement
will happen for them.

Further, do not pass anymore the 'resource name' to the resource's
count method as it is not necessary anymore since Liberty.

Change-Id: I895b4e69e50dbf1aac39e07eba07c3e3ff30808a
Closes-bug: #1501948
(cherry picked from commit 809ac2161577ef354b75713c0d5210e03fa16d6a)

neutron/pecan_wsgi/hooks/quota_enforcement.py
neutron/pecan_wsgi/startup.py

index bc9e46d6344de90c9725b517aa7e3d0c2e569901..e1e4a0b6104503f004daa6afea836847f0d8f566 100644 (file)
@@ -18,7 +18,6 @@ from pecan import hooks
 
 from neutron.common import exceptions
 from neutron import manager
-from neutron.pecan_wsgi.hooks import attribute_population
 from neutron import quota
 
 
@@ -45,8 +44,6 @@ class QuotaEnforcementHook(hooks.PecanHook):
                 count = quota.QUOTAS.count(neutron_context,
                                            resource,
                                            plugin,
-                                           attribute_population._plural(
-                                               resource),
                                            tenant_id)
                 delta = deltas.get(tenant_id, 0) + 1
                 kwargs = {resource: count + delta}
index 758ac25884392666781065aef536c5d10171cb3e..bdb87e2aedf8a559cb8e633178858e8dd373595e 100644 (file)
@@ -22,6 +22,7 @@ from neutron.i18n import _LI, _LW
 from neutron import manager
 from neutron.pecan_wsgi.controllers import root
 from neutron import policy
+from neutron.quota import resource_registry
 
 LOG = log.getLogger(__name__)
 
@@ -100,6 +101,19 @@ def initialize_all():
             LOG.debug("There are already controllers for resource:%s",
                       resource)
 
+    # NOTE(salv-orlando): If you are care about code quality, please read below
+    # Hackiness is strong with the piece of code below. It is used for
+    # populating resource plurals and registering resources with the quota
+    # engine, but the method it calls were not coinceived with this aim.
+    # Therefore it only leverages side-effects from those methods. Moreover,
+    # as it is really not advisable to load an instance of
+    # neutron.api.v2.router.APIRouter just to register resources with the
+    # quota  engine, core resources are explicitly registered here.
+    # TODO(salv-orlando): The Pecan WSGI support should provide its own
+    # solution to manage resource plurals and registration of resources with
+    # the quota engine
+    for resource in router.RESOURCES.keys():
+        resource_registry.register_resource_by_name(resource)
     for ext in ext_mgr.extensions.values():
         # make each extension populate its plurals
         if hasattr(ext, 'get_resources'):