Skip to content

Commit

Permalink
Prevent router being deleted if it is used by a floating IP
Browse files Browse the repository at this point in the history
Fixes bug 1080638

Change-Id: I10768044aac3fe0ce994e42e798df754478d98d1
  • Loading branch information
Gary Kotton committed Nov 28, 2012
1 parent abb2bd3 commit 01ea272
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion quantum/db/l3_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,16 @@ def delete_router(self, context, id):
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)

Expand Down
32 changes: 32 additions & 0 deletions quantum/tests/unit/test_l3_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,38 @@ def test_floatingip_with_assoc_fails(self):
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':
Expand Down

0 comments on commit 01ea272

Please sign in to comment.