]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add expected IDs to router.interface.* notifications
authorEoghan Glynn <eglynn@redhat.com>
Tue, 26 Mar 2013 16:27:05 +0000 (16:27 +0000)
committerEoghan Glynn <eglynn@redhat.com>
Thu, 4 Apr 2013 15:17:49 +0000 (16:17 +0100)
Fixes bug 1160431

The router.interface.{create|delete} notifications are intended to be
consumed by ceilometer, but did not include the router or tenant IDs
in the RPC message payload. Ceilometer requires both these data for
metering purposes.

The missing UUIDs are now provided in the notifications.

Change-Id: I1ca6e1d5377100a0549293e0bdff0182711c750f

quantum/db/l3_db.py
quantum/tests/unit/test_l3_plugin.py

index e7e4849af4b12aa662eeb2d9993a3b4c2dafafe5..48e202f57ca4a3abafe2191320dad74566c6fede 100644 (file)
@@ -365,7 +365,9 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
             context, routers, 'add_router_interface',
             {'network_id': port['network_id'],
              'subnet_id': subnet_id})
-        info = {'port_id': port['id'],
+        info = {'id': router_id,
+                'tenant_id': subnet['tenant_id'],
+                'port_id': port['id'],
                 'subnet_id': port['fixed_ips'][0]['subnet_id']}
         notifier_api.notify(context,
                             notifier_api.publisher_id('network'),
@@ -402,6 +404,7 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
                         port_id=port_id,
                         subnet_id=interface_info['subnet_id'])
             subnet_id = port_db['fixed_ips'][0]['subnet_id']
+            subnet = self._get_subnet(context, subnet_id)
             self._confirm_router_interface_not_in_use(
                 context, router_id, subnet_id)
             _network_id = port_db['network_id']
@@ -439,13 +442,15 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
             context, routers, 'remove_router_interface',
             {'network_id': _network_id,
              'subnet_id': subnet_id})
+        info = {'id': router_id,
+                'tenant_id': subnet['tenant_id'],
+                'port_id': port_id,
+                'subnet_id': subnet_id}
         notifier_api.notify(context,
                             notifier_api.publisher_id('network'),
                             'router.interface.delete',
                             notifier_api.CONF.default_notification_level,
-                            {'router.interface':
-                             {'port_id': port_id,
-                              'subnet_id': subnet_id}})
+                            {'router.interface': info})
 
     def _get_floatingip(self, context, id):
         try:
index 703686b24e3b03190be83d3d948abb3a29d8e524..df3af357ca593e4aa1bf6d534bb921f54cb283df 100644 (file)
@@ -669,6 +669,18 @@ class L3NatDBTestCase(L3NatTestCaseBase):
                     set(n['event_type'] for n in test_notifier.NOTIFICATIONS),
                     set(exp_notifications))
 
+                for n in test_notifier.NOTIFICATIONS:
+                    if n['event_type'].startswith('router.interface.'):
+                        payload = n['payload']['router.interface']
+                        self.assertIn('id', payload)
+                        self.assertEquals(payload['id'], r['router']['id'])
+                        self.assertIn('tenant_id', payload)
+                        stid = s['subnet']['tenant_id']
+                        # tolerate subnet tenant deliberately to '' in the
+                        # nicira metadata access case
+                        self.assertTrue(payload['tenant_id'] == stid or
+                                        payload['tenant_id'] == '')
+
     def test_router_add_interface_subnet_with_bad_tenant_returns_404(self):
         with mock.patch('quantum.context.Context.to_dict') as tdict:
             tenant_id = _uuid()