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)
)
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):

View File

@ -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)