From 1d80f54fb9c0642489a9fa9f922406e1fdd58b6e Mon Sep 17 00:00:00 2001 From: Swaminathan Vasudevan Date: Tue, 25 Nov 2014 15:47:59 -0800 Subject: [PATCH] Deletes floating agent gw port on disassociate This patch deletes the floating agent gw port on floatingip disassociate. A recent change in the neutron trunk broke this functionality. This was introduced by the patch that addressed the re-order operations in (l3_dvr) update floating ip. The current patch fixes the problem. Change-Id: I98e766cf4ed33412d9d5dae07217553acbb5009c Closes-Bug: #1394026 --- neutron/db/l3_dvr_db.py | 20 ++++++++++---------- neutron/tests/unit/db/test_l3_dvr_db.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index d3974db8f78..91896104348 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -159,17 +159,17 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, l3_db.RouterPort.port_type.in_(l3_const.ROUTER_INTERFACE_OWNERS) ) - def update_floatingip(self, context, id, floatingip): - res_fip = super(L3_NAT_with_dvr_db_mixin, self).update_floatingip( - context, id, floatingip) - admin_ctx = context.elevated() - fip = floatingip['floatingip'] - unused_agent_port = (fip.get('port_id', -1) is None and - res_fip.get('fixed_port_id')) - if unused_agent_port: + def _update_fip_assoc(self, context, fip, floatingip_db, external_port): + """Override to delete the fip agent gw port on disassociate.""" + fip_port = fip.get('port_id') + unused_fip_agent_gw_port = ( + fip_port is None and floatingip_db['fixed_port_id']) + if unused_fip_agent_gw_port: + admin_ctx = context.elevated() self.clear_unused_fip_agent_gw_port( - admin_ctx, floatingip) - return res_fip + admin_ctx, floatingip_db) + super(L3_NAT_with_dvr_db_mixin, self)._update_fip_assoc( + context, fip, floatingip_db, external_port) def clear_unused_fip_agent_gw_port( self, context, floatingip_db): diff --git a/neutron/tests/unit/db/test_l3_dvr_db.py b/neutron/tests/unit/db/test_l3_dvr_db.py index 68d48e3171a..404b552e3e7 100644 --- a/neutron/tests/unit/db/test_l3_dvr_db.py +++ b/neutron/tests/unit/db/test_l3_dvr_db.py @@ -310,3 +310,22 @@ class L3DvrTestCase(testlib_api.SqlTestCase): self.assertIn(fip, router[l3_const.FLOATINGIP_KEY]) self.assertIn('fip_interface', router[l3_const.FLOATINGIP_AGENT_INTF_KEY]) + + def test_delete_disassociated_floatingip_agent_port(self): + fip = { + 'id': _uuid(), + 'port_id': None + } + floatingip = { + 'id': _uuid(), + 'fixed_port_id': 1234, + } + with contextlib.nested( + mock.patch.object(self.mixin, + 'clear_unused_fip_agent_gw_port'), + mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin, + '_update_fip_assoc'), + ) as (vf, cf): + self.mixin._update_fip_assoc( + self.ctx, fip, floatingip, mock.ANY) + self.assertTrue(vf.called)