From: Swaminathan Vasudevan Date: Tue, 25 Nov 2014 23:47:59 +0000 (-0800) Subject: Deletes floating agent gw port on disassociate X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1d80f54fb9c0642489a9fa9f922406e1fdd58b6e;p=openstack-build%2Fneutron-build.git 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 --- diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index d3974db8f..918961043 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 68d48e317..404b552e3 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)