"""
fip_hostid = self.get_vm_port_hostid(
context, floatingip_db['fixed_port_id'])
- if fip_hostid and self.check_fips_availability_on_host(
- context, fip_hostid):
- LOG.debug('Deleting the Agent GW Port on host: %s', fip_hostid)
- self.delete_floatingip_agent_gateway_port(context, fip_hostid)
+ if fip_hostid and self.check_fips_availability_on_host_ext_net(
+ context, fip_hostid, floatingip_db['floating_network_id']):
+ LOG.debug('Deleting the Agent GW Port for ext-net: '
+ '%s', floatingip_db['floating_network_id'])
+ self.delete_floatingip_agent_gateway_port(
+ context, fip_hostid, floatingip_db['floating_network_id'])
def delete_floatingip(self, context, id):
floatingip = self._get_floatingip(context, id)
if ports:
return ports[0]
- def check_fips_availability_on_host(self, context, host_id):
- """Query all floating_ips and filter by particular host."""
+ def check_fips_availability_on_host_ext_net(
+ self, context, host_id, fip_ext_net_id):
+ """Query all floating_ips and filter on host and external net."""
fip_count_on_host = 0
with context.session.begin(subtransactions=True):
routers = self._get_sync_routers(context, router_ids=None)
# Check for the active floatingip in the host
for fip in floating_ips:
f_host = self.get_vm_port_hostid(context, fip['port_id'])
- if f_host == host_id:
+ if (f_host == host_id and
+ (fip['floating_network_id'] == fip_ext_net_id)):
fip_count_on_host += 1
# If fip_count greater than 1 or equal to zero no action taken
# if the fip_count is equal to 1, then this would be last active
return True
return False
- def delete_floatingip_agent_gateway_port(self, context, host_id):
- """Function to delete the FIP agent gateway port on host."""
+ def delete_floatingip_agent_gateway_port(
+ self, context, host_id, ext_net_id):
+ """Function to delete FIP gateway port with given ext_net_id."""
# delete any fip agent gw port
- device_filter = {'device_owner': [DEVICE_OWNER_AGENT_GW]}
+ device_filter = {'device_owner': [DEVICE_OWNER_AGENT_GW],
+ 'network_id': [ext_net_id]}
ports = self._core_plugin.get_ports(context,
filters=device_filter)
for p in ports:
mock.patch.object(self.mixin,
'get_vm_port_hostid'),
mock.patch.object(self.mixin,
- 'check_fips_availability_on_host'),
+ 'check_fips_availability_on_host_ext_net'),
mock.patch.object(self.mixin,
'delete_floatingip_agent_gateway_port')
) as (gfips, gvm, cfips, dfips):
self.assertTrue(cfips.called)
self.assertTrue(gvm.called)
+ def test_delete_floatingip_agent_gateway_port(self):
+ port = {
+ 'id': 'my_port_id',
+ 'binding:host_id': 'foo_host',
+ 'network_id': 'ext_network_id',
+ 'device_owner': l3_const.DEVICE_OWNER_AGENT_GW
+ }
+ with contextlib.nested(
+ mock.patch.object(manager.NeutronManager, 'get_plugin'),
+ mock.patch.object(self.mixin,
+ 'get_vm_port_hostid')) as (gp, vm_host):
+ plugin = mock.Mock()
+ gp.return_value = plugin
+ plugin.get_ports.return_value = [port]
+ vm_host.return_value = 'foo_host'
+ self.mixin.delete_floatingip_agent_gateway_port(
+ self.ctx, 'foo_host', 'network_id')
+ plugin.get_ports.assert_called_with(self.ctx, filters={
+ 'network_id': ['network_id'],
+ 'device_owner': [l3_const.DEVICE_OWNER_AGENT_GW]})
+ plugin._delete_port.assert_called_with(self.ctx, 'my_port_id')
+
def _delete_floatingip_test_setup(self, floatingip):
fip_id = floatingip['id']
with contextlib.nested(