Prevent router being deleted if it is used by a floating IP

Fixes bug 1080638

Change-Id: I10768044aac3fe0ce994e42e798df754478d98d1
This commit is contained in:
Gary Kotton
2012-11-16 00:20:33 +00:00
parent abb2bd3a0d
commit 01ea2723e5
2 changed files with 40 additions and 1 deletions

View File

@@ -227,9 +227,16 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
with context.session.begin(subtransactions=True):
router = self._get_router(context, id)
# Ensure that the router is not used
fips = self.get_floatingips_count(context.elevated(),
filters={'router_id': [id]})
if fips:
raise l3.RouterInUse(router_id=id)
device_filter = {'device_id': [id],
'device_owner': [DEVICE_OWNER_ROUTER_INTF]}
ports = self.get_ports(context, filters=device_filter)
ports = self.get_ports_count(context.elevated(),
filters=device_filter)
if ports:
raise l3.RouterInUse(router_id=id)

View File

@@ -931,6 +931,38 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
private_sub['subnet']['id'],
None)
def test_router_delete_with_floatingip(self):
with self.port() as p:
private_sub = {'subnet': {'id':
p['port']['fixed_ips'][0]['subnet_id']}}
with self.subnet(cidr='12.0.0.0/24') as public_sub:
fmt = 'json'
self._set_net_external(public_sub['subnet']['network_id'])
res = self._create_router(fmt, _uuid())
r = self.deserialize(fmt, res)
self._add_external_gateway_to_router(
r['router']['id'],
public_sub['subnet']['network_id'])
self._router_interface_action('add', r['router']['id'],
private_sub['subnet']['id'],
None)
res = self._create_floatingip(
fmt, public_sub['subnet']['network_id'],
port_id=p['port']['id'])
self.assertEqual(res.status_int, exc.HTTPCreated.code)
floatingip = self.deserialize(fmt, res)
self._remove_external_gateway_from_router(
r['router']['id'],
public_sub['subnet']['network_id'])
self._delete('routers', r['router']['id'],
expected_code=exc.HTTPConflict.code)
# Cleanup
self._delete('floatingips', floatingip['floatingip']['id'])
self._router_interface_action('remove', r['router']['id'],
private_sub['subnet']['id'],
None)
self._delete('routers', r['router']['id'])
def test_floatingip_update(self):
with self.port() as p:
private_sub = {'subnet': {'id':