Skip to content

Commit

Permalink
Send notification on router interface create/delete
Browse files Browse the repository at this point in the history
This fixes bug #1060985 for Quantum

Change-Id: I39d2d15340913dd0fad753c3e95fb74d329481a9
Signed-off-by: Julien Danjou <julien@danjou.info>
  • Loading branch information
jd committed Jan 17, 2013
1 parent 7fa8086 commit c4004b6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
21 changes: 18 additions & 3 deletions quantum/db/l3_db.py
Expand Up @@ -32,6 +32,7 @@
from quantum.db import models_v2
from quantum.extensions import l3
from quantum.openstack.common import log as logging
from quantum.openstack.common.notifier import api as notifier_api
from quantum.openstack.common import uuidutils
from quantum import policy

Expand Down Expand Up @@ -352,8 +353,14 @@ def add_router_interface(self, context, router_id, interface_info):

routers = self.get_sync_data(context.elevated(), [router_id])
l3_rpc_agent_api.L3AgentNofity.routers_updated(context, routers)
return {'port_id': port['id'],
info = {'port_id': port['id'],
'subnet_id': port['fixed_ips'][0]['subnet_id']}
notifier_api.notify(context,
notifier_api.publisher_id('network'),
'router.interface.create',
notifier_api.CONF.default_notification_level,
{'router.interface': info})
return info

def _confirm_router_interface_not_in_use(self, context, router_id,
subnet_id):
Expand Down Expand Up @@ -391,9 +398,9 @@ def remove_router_interface(self, context, router_id, interface_info):
raise q_exc.SubnetMismatchForPort(
port_id=port_id,
subnet_id=interface_info['subnet_id'])
subnet_id = port_db['fixed_ips'][0]['subnet_id']
self._confirm_router_interface_not_in_use(
context, router_id,
port_db['fixed_ips'][0]['subnet_id'])
context, router_id, subnet_id)
self.delete_port(context, port_db['id'], l3_port_check=False)
elif 'subnet_id' in interface_info:
subnet_id = interface_info['subnet_id']
Expand All @@ -412,6 +419,7 @@ def remove_router_interface(self, context, router_id, interface_info):

for p in ports:
if p['fixed_ips'][0]['subnet_id'] == subnet_id:
port_id = p['id']
self.delete_port(context, p['id'], l3_port_check=False)
found = True
break
Expand All @@ -423,6 +431,13 @@ def remove_router_interface(self, context, router_id, interface_info):
subnet_id=subnet_id)
routers = self.get_sync_data(context.elevated(), [router_id])
l3_rpc_agent_api.L3AgentNofity.routers_updated(context, routers)
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}})

def _get_floatingip(self, context, id):
try:
Expand Down
22 changes: 22 additions & 0 deletions quantum/tests/unit/test_l3_plugin.py
Expand Up @@ -42,6 +42,8 @@
from quantum import manager
from quantum.openstack.common import cfg
from quantum.openstack.common import log as logging
from quantum.openstack.common.notifier import test_notifier
from quantum.openstack.common.notifier import api as notifier_api
from quantum.openstack.common import uuidutils
from quantum.tests.unit import test_api_v2
from quantum.tests.unit import test_db_plugin
Expand Down Expand Up @@ -296,6 +298,14 @@ def setUp(self):
test_config['extension_manager'] = ext_mgr
super(L3NatDBTestCase, self).setUp()

# Set to None to reload the drivers
notifier_api._drivers = None
cfg.CONF.set_override("notification_driver", [test_notifier.__name__])

def tearDown(self):
test_notifier.NOTIFICATIONS = []
super(L3NatDBTestCase, self).tearDown()

def _create_router(self, fmt, tenant_id, name=None,
admin_state_up=None, set_context=False):
data = {'router': {'tenant_id': tenant_id}}
Expand Down Expand Up @@ -477,6 +487,18 @@ def test_router_add_interface_subnet(self):
body = self._show('ports', r_port_id,
expected_code=exc.HTTPNotFound.code)

self.assertEqual(len(test_notifier.NOTIFICATIONS), 8)
self.assertEqual(
set(n['event_type'] for n in test_notifier.NOTIFICATIONS),
set(['router.create.start',
'router.create.end',
'network.create.start',
'network.create.end',
'subnet.create.start',
'subnet.create.end',
'router.interface.create',
'router.interface.delete']))

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()
Expand Down

0 comments on commit c4004b6

Please sign in to comment.