]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
DVR: notify specific agent when deleting floating ip
authorOleg Bondarev <obondarev@mirantis.com>
Tue, 6 Oct 2015 12:22:30 +0000 (15:22 +0300)
committerOleg Bondarev <obondarev@mirantis.com>
Thu, 22 Oct 2015 09:30:12 +0000 (09:30 +0000)
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
neutron/db/l3_dvr_db.py
neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py

index ed590a7ddcbd465b36bc36eb93e8ebf7a2682cd7..91245359977e10d2001115113264381f22ef0aa9 100644 (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)
@@ -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.
index 5cce619cd27aa404fa6d086522a853f68a1648f1..ba740a0682c3dd8b5a237e2f1a3a1451871221b5 100644 (file)
@@ -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."""
index 1cc8ac340655ac5df98e3f18c6b99cf6e3116eda..b054301b6474605b278b10d71e54b07e86290ec8 100644 (file)
@@ -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)