Add expected IDs to router.interface.* notifications

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
This commit is contained in:
Eoghan Glynn
2013-03-26 16:27:05 +00:00
committed by Gary Kotton
parent cf4d1d8c65
commit 67292a7aac
2 changed files with 21 additions and 4 deletions

View File

@@ -374,7 +374,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'),
@@ -420,6 +422,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']
@@ -457,13 +460,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:

View 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()