Merge "Deletes FIP agent gw port when last VM is deleted"
This commit is contained in:
commit
166b7fd661
@ -181,6 +181,26 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
||||
super(L3_NAT_with_dvr_db_mixin,
|
||||
self).delete_floatingip(context, id)
|
||||
|
||||
def _get_floatingip_on_port(self, context, port_id=None):
|
||||
"""Helper function to retrieve the fip associated with port."""
|
||||
fip_qry = context.session.query(l3_db.FloatingIP)
|
||||
floating_ip = fip_qry.filter_by(fixed_port_id=port_id)
|
||||
return floating_ip.first()
|
||||
|
||||
def disassociate_floatingips(self, context, port_id, do_notify=True):
|
||||
"""Override disassociate floatingips to delete fip agent gw port."""
|
||||
with context.session.begin(subtransactions=True):
|
||||
fip = self._get_floatingip_on_port(
|
||||
context, port_id=port_id)
|
||||
if fip:
|
||||
admin_ctx = context.elevated()
|
||||
self.clear_unused_fip_agent_gw_port(
|
||||
admin_ctx, fip, id)
|
||||
return super(L3_NAT_with_dvr_db_mixin,
|
||||
self).disassociate_floatingips(context,
|
||||
port_id,
|
||||
do_notify=do_notify)
|
||||
|
||||
def add_router_interface(self, context, router_id, interface_info):
|
||||
add_by_port, add_by_sub = self._validate_interface_info(interface_info)
|
||||
router = self._get_router(context, router_id)
|
||||
|
@ -23,7 +23,6 @@ from neutron import manager
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.tests.unit import testlib_api
|
||||
|
||||
|
||||
_uuid = uuidutils.generate_uuid
|
||||
|
||||
|
||||
@ -214,6 +213,32 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
|
||||
self.mixin.delete_floatingip(self.ctx, fip_id)
|
||||
return vf
|
||||
|
||||
def _disassociate_floatingip_setup(self, port_id=None, floatingip=None):
|
||||
with contextlib.nested(
|
||||
mock.patch.object(self.mixin, '_get_floatingip_on_port'),
|
||||
mock.patch.object(self.mixin,
|
||||
'clear_unused_fip_agent_gw_port'),
|
||||
) as (gf, vf):
|
||||
gf.return_value = floatingip
|
||||
self.mixin.disassociate_floatingips(
|
||||
self.ctx, port_id, do_notify=False)
|
||||
return vf
|
||||
|
||||
def test_disassociate_floatingip_with_vm_port(self):
|
||||
port_id = '1234'
|
||||
floatingip = {
|
||||
'id': _uuid(),
|
||||
'fixed_port_id': 1234,
|
||||
'floating_network_id': _uuid()
|
||||
}
|
||||
mock_disassociate_fip = self._disassociate_floatingip_setup(
|
||||
port_id=port_id, floatingip=floatingip)
|
||||
self.assertTrue(mock_disassociate_fip.called)
|
||||
|
||||
def test_disassociate_floatingip_with_no_vm_port(self):
|
||||
mock_disassociate_fip = self._disassociate_floatingip_setup()
|
||||
self.assertFalse(mock_disassociate_fip.called)
|
||||
|
||||
def test_delete_floatingip_without_internal_port(self):
|
||||
floatingip = {
|
||||
'id': _uuid(),
|
||||
|
Loading…
Reference in New Issue
Block a user