]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable resource usage tracking for reference plugins.
authorSalvatore Orlando <salv.orlando@gmail.com>
Thu, 4 Jun 2015 22:43:35 +0000 (15:43 -0700)
committerSalvatore Orlando <salv.orlando@gmail.com>
Tue, 28 Jul 2015 18:55:04 +0000 (11:55 -0700)
Specify which resources should be tracked when initializing
the ML2 and l3_router plugins. This will enable usage tracking
for the following resources:
- Networks
- Ports
- Subnets
- Subnet pools
- Security groups
- Security group rules
- Routers
- Floating IPs

Partially implements blueprint: bp/better-quotas

Change-Id: I57287b15ffdadc30297651a01e9f05110e9ce6b6

neutron/plugins/ml2/plugin.py
neutron/quota/resource.py
neutron/services/l3_router/l3_router_plugin.py
neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py
neutron/tests/unit/extensions/test_securitygroup.py

index 9a1d5a84eac014e55da23f4fd7474f0691f0034f..77798c6b7c62141e5aa26629c38eb14ed096b905 100644 (file)
@@ -55,6 +55,7 @@ from neutron.db import extradhcpopt_db
 from neutron.db import models_v2
 from neutron.db import netmtu_db
 from neutron.db.quota import driver  # noqa
+from neutron.db import securitygroups_db
 from neutron.db import securitygroups_rpc_base as sg_db_rpc
 from neutron.db import vlantransparent_db
 from neutron.extensions import allowedaddresspairs as addr_pair
@@ -74,6 +75,7 @@ from neutron.plugins.ml2 import driver_context
 from neutron.plugins.ml2 import managers
 from neutron.plugins.ml2 import models
 from neutron.plugins.ml2 import rpc
+from neutron.quota import resource_registry
 
 LOG = log.getLogger(__name__)
 
@@ -126,6 +128,13 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
             self._aliases = aliases
         return self._aliases
 
+    @resource_registry.tracked_resources(
+        network=models_v2.Network,
+        port=models_v2.Port,
+        subnet=models_v2.Subnet,
+        subnetpool=models_v2.SubnetPool,
+        security_group=securitygroups_db.SecurityGroup,
+        security_group_rule=securitygroups_db.SecurityGroupRule)
     def __init__(self):
         # First load drivers, then initialize DB, then initialize drivers
         self.type_manager = managers.TypeManager()
index d9a716a5eb8c2c7a38143546948b1151e6d8d9ec..eb0036859fa557a112502cde7468b45bc68dabcc 100644 (file)
@@ -17,6 +17,7 @@ from oslo_config import cfg
 from oslo_db import api as oslo_db_api
 from oslo_db import exception as oslo_db_exception
 from oslo_log import log
+from oslo_utils import excutils
 from sqlalchemy import event
 
 from neutron.db import api as db_api
@@ -191,14 +192,12 @@ class TrackedResource(BaseResource):
 
     @lockutils.synchronized('dirty_tenants')
     def _db_event_handler(self, mapper, _conn, target):
-        tenant_id = target.get('tenant_id')
-        if not tenant_id:
-            # NOTE: This is an unexpected error condition. Log anomaly but do
-            # not raise as this might have unexpected effects on other
-            # operations
-            LOG.error(_LE("Model class %s does not have tenant_id attribute"),
-                      target)
-            return
+        try:
+            tenant_id = target['tenant_id']
+        except AttributeError:
+            with excutils.save_and_reraise_exception():
+                LOG.error(_LE("Model class %s does not have a tenant_id "
+                              "attribute"), target)
         self._dirty_tenants.add(tenant_id)
 
     # Retry the operation if a duplicate entry exception is raised. This
index 289f81d1b3d6cffa238f265dcd55794082ffb2a4..4c4e96ae5bfa031012736b0db42f8ad966bea605 100644 (file)
@@ -30,6 +30,7 @@ from neutron.db import l3_gwmode_db
 from neutron.db import l3_hamode_db
 from neutron.db import l3_hascheduler_db
 from neutron.plugins.common import constants
+from neutron.quota import resource_registry
 
 
 class L3RouterPlugin(common_db_mixin.CommonDbMixin,
@@ -52,6 +53,8 @@ class L3RouterPlugin(common_db_mixin.CommonDbMixin,
                                    "extraroute", "l3_agent_scheduler",
                                    "l3-ha"]
 
+    @resource_registry.tracked_resources(router=l3_db.Router,
+                                         floatingip=l3_db.FloatingIP)
     def __init__(self):
         self.setup_rpc()
         self.router_scheduler = importutils.import_object(
index 78eb49308a1c699b9cc7570051e46ff1cfcdbb14..3ad241d56715e845feb716ef527ccccf3eefc43a 100644 (file)
@@ -33,6 +33,9 @@ class TestDhcpRpcCallback(base.BaseTestCase):
         self.callbacks = dhcp_rpc.DhcpRpcCallback()
         self.log_p = mock.patch('neutron.api.rpc.handlers.dhcp_rpc.LOG')
         self.log = self.log_p.start()
+        set_dirty_p = mock.patch('neutron.quota.resource_registry.'
+                                 'set_resources_dirty')
+        self.mock_set_dirty = set_dirty_p.start()
 
     def test_get_active_networks(self):
         plugin_retval = [dict(id='a'), dict(id='b')]
index 31b191cf89d75123fc81d268e6c7fa60071ec75b..44e816ba027f1e892c5f782e53cbdaf7961e91f3 100644 (file)
@@ -452,8 +452,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
                     '22', '22',
                     remote_ip_prefix,
                     None,
-                    None,
-                    ethertype)
+                    ethertype=ethertype)
                 res = self._create_security_group_rule(self.fmt, rule)
                 self.assertEqual(res.status_int, webob.exc.HTTPBadRequest.code)
 
@@ -474,8 +473,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
                     '22', '22',
                     remote_ip_prefix,
                     None,
-                    None,
-                    ethertype)
+                    ethertype=ethertype)
                 res = self._create_security_group_rule(self.fmt, rule)
                 self.assertEqual(res.status_int, 201)
                 res_sg = self.deserialize(self.fmt, res)