From: Salvatore Orlando Date: Thu, 1 Oct 2015 23:07:59 +0000 (-0700) Subject: Pecan: Fix quota enforcement X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d1d5f2a3bc11fbaa61dcbcce7de2be03b88dd606;p=openstack-build%2Fneutron-build.git Pecan: Fix quota enforcement 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) --- diff --git a/neutron/pecan_wsgi/hooks/quota_enforcement.py b/neutron/pecan_wsgi/hooks/quota_enforcement.py index bc9e46d63..e1e4a0b61 100644 --- a/neutron/pecan_wsgi/hooks/quota_enforcement.py +++ b/neutron/pecan_wsgi/hooks/quota_enforcement.py @@ -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} diff --git a/neutron/pecan_wsgi/startup.py b/neutron/pecan_wsgi/startup.py index 758ac2588..bdb87e2ae 100644 --- a/neutron/pecan_wsgi/startup.py +++ b/neutron/pecan_wsgi/startup.py @@ -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'):