Merge "Deletes floating agent gw port on disassociate"

This commit is contained in:
Jenkins 2015-01-08 20:11:58 +00:00 committed by Gerrit Code Review
commit 6df7f5abf1
2 changed files with 29 additions and 10 deletions

View File

@ -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) l3_db.RouterPort.port_type.in_(l3_const.ROUTER_INTERFACE_OWNERS)
) )
def update_floatingip(self, context, id, floatingip): def _update_fip_assoc(self, context, fip, floatingip_db, external_port):
res_fip = super(L3_NAT_with_dvr_db_mixin, self).update_floatingip( """Override to delete the fip agent gw port on disassociate."""
context, id, floatingip) fip_port = fip.get('port_id')
admin_ctx = context.elevated() unused_fip_agent_gw_port = (
fip = floatingip['floatingip'] fip_port is None and floatingip_db['fixed_port_id'])
unused_agent_port = (fip.get('port_id', -1) is None and if unused_fip_agent_gw_port:
res_fip.get('fixed_port_id')) admin_ctx = context.elevated()
if unused_agent_port:
self.clear_unused_fip_agent_gw_port( self.clear_unused_fip_agent_gw_port(
admin_ctx, floatingip) admin_ctx, floatingip_db)
return res_fip super(L3_NAT_with_dvr_db_mixin, self)._update_fip_assoc(
context, fip, floatingip_db, external_port)
def clear_unused_fip_agent_gw_port( def clear_unused_fip_agent_gw_port(
self, context, floatingip_db): self, context, floatingip_db):

View File

@ -310,3 +310,22 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
self.assertIn(fip, router[l3_const.FLOATINGIP_KEY]) self.assertIn(fip, router[l3_const.FLOATINGIP_KEY])
self.assertIn('fip_interface', self.assertIn('fip_interface',
router[l3_const.FLOATINGIP_AGENT_INTF_KEY]) 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)