DVR: notify specific agent when deleting floating ip

In DVR case we only need to notify the l3 agent on compute node
where associated fixed port is located.

Closes-Bug: #1486828
Change-Id: I644238ca295c4eb6df75a99a8ef6143a801b27cb
(cherry picked from commit eef7990e8a)
This commit is contained in:
Oleg Bondarev 2015-10-06 15:22:30 +03:00
parent 84c969bd23
commit bf92dbb246
3 changed files with 54 additions and 4 deletions

View File

@ -1037,7 +1037,6 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
def _delete_floatingip(self, context, id):
floatingip = self._get_floatingip(context, id)
router_id = floatingip['router_id']
# Foreign key cascade will take care of the removal of the
# floating IP record once the port is deleted. We can't start
# a transaction first to remove it ourselves because the delete_port
@ -1045,7 +1044,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
self._core_plugin.delete_port(context.elevated(),
floatingip['floating_port_id'],
l3_port_check=False)
return router_id
return self._make_floatingip_dict(floatingip)
def delete_floatingip(self, context, id):
self._delete_floatingip(context, id)
@ -1376,8 +1375,9 @@ class L3_NAT_db_mixin(L3_NAT_dbonly_mixin, L3RpcNotifierMixin):
return floatingip
def delete_floatingip(self, context, id):
router_id = self._delete_floatingip(context, id)
self.notify_router_updated(context, router_id, 'delete_floatingip')
floating_ip = self._delete_floatingip(context, id)
self.notify_router_updated(context, floating_ip['router_id'],
'delete_floatingip')
def disassociate_floatingips(self, context, port_id, do_notify=True):
"""Disassociate all floating IPs linked to specific port.

View File

@ -722,6 +722,10 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
self._notify_floating_ip_change(context, floatingip)
return floatingip
def delete_floatingip(self, context, id):
floating_ip = self._delete_floatingip(context, id)
self._notify_floating_ip_change(context, floating_ip)
def is_distributed_router(router):
"""Return True if router to be handled is distributed."""

View File

@ -381,3 +381,49 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework):
def test_update_floating_ip_agent_notification_non_dvr(self):
self._test_update_floating_ip_agent_notification(dvr=False)
def _test_delete_floating_ip_agent_notification(self, dvr=True):
with self.subnet() as ext_subnet,\
self.subnet(cidr='20.0.0.0/24') as int_subnet,\
self.port(subnet=int_subnet,
device_owner='compute:None') as int_port:
# make net external
ext_net_id = ext_subnet['subnet']['network_id']
self._update('networks', ext_net_id,
{'network': {external_net.EXTERNAL: True}})
router = self._create_router(distributed=dvr)
self.l3_plugin.update_router(
self.context, router['id'],
{'router': {
'external_gateway_info': {'network_id': ext_net_id}}})
self.l3_plugin.add_router_interface(
self.context, router['id'],
{'subnet_id': int_subnet['subnet']['id']})
floating_ip = {'floating_network_id': ext_net_id,
'router_id': router['id'],
'port_id': int_port['port']['id'],
'tenant_id': int_port['port']['tenant_id']}
floating_ip = self.l3_plugin.create_floatingip(
self.context, {'floatingip': floating_ip})
with mock.patch.object(
self.l3_plugin, '_l3_rpc_notifier') as l3_notif:
self.l3_plugin.delete_floatingip(
self.context, floating_ip['id'])
if dvr:
l3_notif.routers_updated_on_host.assert_called_once_with(
self.context, [router['id']],
int_port['port']['binding:host_id'])
self.assertFalse(l3_notif.routers_updated.called)
else:
l3_notif.routers_updated.assert_called_once_with(
self.context, [router['id']], None)
self.assertFalse(
l3_notif.routers_updated_on_host.called)
def test_delete_floating_ip_agent_notification(self):
self._test_delete_floating_ip_agent_notification()
def test_delete_floating_ip_agent_notification_non_dvr(self):
self._test_delete_floating_ip_agent_notification(dvr=False)