Fixes update router gateway successful with existed floatingip association
Fixes bug 1081877 Change-Id: I77e6034a39dc9db85de691a9ba596b2c8ca9d124
This commit is contained in:
parent
30d6c8e7d4
commit
1a44190cb4
@ -182,6 +182,11 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
|
|||||||
|
|
||||||
# figure out if we need to delete existing port
|
# figure out if we need to delete existing port
|
||||||
if gw_port and gw_port['network_id'] != network_id:
|
if gw_port and gw_port['network_id'] != network_id:
|
||||||
|
fip_count = self.get_floatingips_count(context.elevated(),
|
||||||
|
{'router_id': [router_id]})
|
||||||
|
if fip_count:
|
||||||
|
raise l3.RouterExternalGatewayInUseByFloatingIp(
|
||||||
|
router_id=router_id, net_id=gw_port['network_id'])
|
||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
router.gw_port = None
|
router.gw_port = None
|
||||||
context.session.add(router)
|
context.session.add(router)
|
||||||
|
@ -64,6 +64,12 @@ class ExternalNetworkInUse(qexception.InUse):
|
|||||||
"non-external, since it has existing gateway ports")
|
"non-external, since it has existing gateway ports")
|
||||||
|
|
||||||
|
|
||||||
|
class RouterExternalGatewayInUseByFloatingIp(qexception.InUse):
|
||||||
|
message = _("Gateway cannot be updated for router %(router_id), since a "
|
||||||
|
"gateway to external network %(net_id) is required by one or "
|
||||||
|
"more floating IPs.")
|
||||||
|
|
||||||
|
|
||||||
def _validate_uuid_or_none(data, valid_values=None):
|
def _validate_uuid_or_none(data, valid_values=None):
|
||||||
if data is None:
|
if data is None:
|
||||||
return None
|
return None
|
||||||
|
@ -717,6 +717,21 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
|
|||||||
r['router']['id'],
|
r['router']['id'],
|
||||||
s2['subnet']['network_id'])
|
s2['subnet']['network_id'])
|
||||||
|
|
||||||
|
def test_router_update_gateway_with_existed_floatingip(self):
|
||||||
|
with self.subnet() as subnet:
|
||||||
|
self._set_net_external(subnet['subnet']['network_id'])
|
||||||
|
with self.floatingip_with_assoc() as fip:
|
||||||
|
self._add_external_gateway_to_router(
|
||||||
|
fip['floatingip']['router_id'],
|
||||||
|
subnet['subnet']['network_id'],
|
||||||
|
expected_code=exc.HTTPConflict.code)
|
||||||
|
|
||||||
|
def test_router_update_gateway_to_empty_with_existed_floatingip(self):
|
||||||
|
with self.floatingip_with_assoc() as fip:
|
||||||
|
self._remove_external_gateway_from_router(
|
||||||
|
fip['floatingip']['router_id'], None,
|
||||||
|
expected_code=exc.HTTPConflict.code)
|
||||||
|
|
||||||
def test_router_add_gateway_invalid_network(self):
|
def test_router_add_gateway_invalid_network(self):
|
||||||
with self.router() as r:
|
with self.router() as r:
|
||||||
self._add_external_gateway_to_router(
|
self._add_external_gateway_to_router(
|
||||||
@ -950,9 +965,6 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
|
|||||||
port_id=p['port']['id'])
|
port_id=p['port']['id'])
|
||||||
self.assertEqual(res.status_int, exc.HTTPCreated.code)
|
self.assertEqual(res.status_int, exc.HTTPCreated.code)
|
||||||
floatingip = self.deserialize(fmt, res)
|
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'],
|
self._delete('routers', r['router']['id'],
|
||||||
expected_code=exc.HTTPConflict.code)
|
expected_code=exc.HTTPConflict.code)
|
||||||
# Cleanup
|
# Cleanup
|
||||||
|
Loading…
Reference in New Issue
Block a user