From 7771f16116ce8a34c83bc5673b4508b4e839eacb Mon Sep 17 00:00:00 2001 From: LIU Yulong Date: Tue, 16 Jun 2020 10:02:24 +0800 Subject: [PATCH] [L3] Delete DvrFipGatewayPortAgentBindings after no gw ports This is the code behavior aligning for dvr related logical. The L3 dvr DB will remove all related FIP agent gateway port after there is no real use of it. But the DvrFipGatewayPortAgentBindings remain, it will cause the issue of new floating IP failed to bind. This patch adds the binding deleting action. Related-bug: #1883089 Change-Id: I62c29e172bc8705dade11d37bb347241ef8ad5f8 (cherry picked from commit 8dee0d9a4eb4282b989f2c77a79e55aa89554788) --- neutron/db/l3_dvr_db.py | 5 +++++ neutron/tests/unit/db/test_l3_dvr_db.py | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index 3e022a61781..463174c9812 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -375,6 +375,11 @@ class DVRResourceOperationHandler(object): # to clean up the fip namespace as it is no longer required. self.l3plugin.l3_rpc_notifier.delete_fipnamespace_for_ext_net( payload.context, network_id) + # Delete the Floating IP agent gateway port + # bindings on all hosts + l3_obj.DvrFipGatewayPortAgentBinding.delete_objects( + payload.context, + network_id=network_id) def _delete_fip_agent_port(self, context, network_id, host_id): try: diff --git a/neutron/tests/unit/db/test_l3_dvr_db.py b/neutron/tests/unit/db/test_l3_dvr_db.py index 3bdb1998bae..e2eda73a2e7 100644 --- a/neutron/tests/unit/db/test_l3_dvr_db.py +++ b/neutron/tests/unit/db/test_l3_dvr_db.py @@ -1409,3 +1409,27 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): self.assertRaises( exceptions.BadRequest, self.mixin._get_assoc_data, self.ctx, mock.ANY, mock.Mock()) + + def test__delete_dvr_internal_ports(self): + payload = mock.Mock() + payload.context = mock.Mock() + payload.latest_state = {'distributed': True} + payload.metadata = {'new_network_id': 'fake-net-1', + 'network_id': 'fake-net-2'} + plugin = mock.Mock() + directory.add_plugin(plugin_constants.CORE, plugin) + plugin.get_ports.return_value = [] + with mock.patch.object(self.mixin, + 'delete_floatingip_agent_gateway_port') as \ + del_port, \ + mock.patch.object( + self.mixin.l3_rpc_notifier, + 'delete_fipnamespace_for_ext_net') as \ + del_fip_ns, \ + mock.patch.object(router_obj.DvrFipGatewayPortAgentBinding, + "delete_objects") as del_binding: + self.mixin._delete_dvr_internal_ports( + None, None, resources.ROUTER_GATEWAY, payload) + del_port.assert_called_once() + del_fip_ns.assert_called_once() + del_binding.assert_called_once()