From eef7990e8a51bce7543d0bf602324051394ebccc Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Tue, 6 Oct 2015 15:22:30 +0300 Subject: [PATCH] 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 --- neutron/db/l3_db.py | 8 ++-- neutron/db/l3_dvr_db.py | 4 ++ .../l3_router/test_l3_dvr_router_plugin.py | 46 +++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index ed590a7dd..912453599 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -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) @@ -1383,8 +1382,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. diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index 5cce619cd..ba740a068 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -725,6 +725,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.""" diff --git a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py index 1cc8ac340..b054301b6 100644 --- a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py +++ b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py @@ -345,3 +345,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) -- 2.45.2