Add check for cidr overrapping for adding external gateway

Fixes bug 1053633
Also add check for cidr overrapping between external gateway and
interfaces

Change-Id: I5bfb2fd96ea467b63e940893979a912caf550deb
This commit is contained in:
Nachi Ueno
2012-09-21 20:52:16 +00:00
parent cf54850d15
commit 9343c44818
2 changed files with 44 additions and 5 deletions

View File

@@ -193,6 +193,12 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
if network_id is not None and (gw_port is None or
gw_port['network_id'] != network_id):
subnets = self._get_subnets_by_network(context,
network_id)
for subnet in subnets:
self._check_for_dup_router_subnet(context, router_id,
network_id, subnet['id'])
# Port has no 'tenant-id', as it is hidden from user
gw_port = self.create_port(context.elevated(), {
'port':
@@ -250,8 +256,7 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
try:
rport_qry = context.session.query(models_v2.Port)
rports = rport_qry.filter_by(
device_id=router_id,
device_owner=DEVICE_OWNER_ROUTER_INTF,).all()
device_id=router_id).all()
# its possible these ports on on the same network, but
# different subnet
new_cidr = self._get_subnet(context, subnet_id)['cidr']

View File

@@ -561,6 +561,40 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
None,
p1['port']['id'])
def test_router_add_gateway_dup_subnet1(self):
with self.router() as r:
with self.subnet() as s:
body = self._router_interface_action('add',
r['router']['id'],
s['subnet']['id'],
None)
self._set_net_external(s['subnet']['network_id'])
self._add_external_gateway_to_router(
r['router']['id'],
s['subnet']['network_id'],
expected_code=exc.HTTPBadRequest.code)
body = self._router_interface_action('remove',
r['router']['id'],
s['subnet']['id'],
None)
def test_router_add_gateway_dup_subnet2(self):
with self.router() as r:
with self.subnet() as s:
self._set_net_external(s['subnet']['network_id'])
self._add_external_gateway_to_router(
r['router']['id'],
s['subnet']['network_id'])
self._router_interface_action('add',
r['router']['id'],
s['subnet']['id'],
None,
expected_code=exc.
HTTPBadRequest.code)
self._remove_external_gateway_from_router(
r['router']['id'],
s['subnet']['network_id'])
def test_router_add_interface_overlapped_cidr(self):
with self.router() as r:
with self.subnet(cidr='10.0.1.0/24') as s1:
@@ -763,7 +797,7 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
@contextlib.contextmanager
def floatingip_with_assoc(self, port_id=None, fmt='json'):
with self.subnet() as public_sub:
with self.subnet(cidr='11.0.0.0/24') as public_sub:
self._set_net_external(public_sub['subnet']['network_id'])
with self.port() as private_port:
with self.router() as r:
@@ -794,7 +828,7 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
@contextlib.contextmanager
def floatingip_no_assoc(self, private_sub, fmt='json'):
with self.subnet() as public_sub:
with self.subnet(cidr='12.0.0.0/24') as public_sub:
self._set_net_external(public_sub['subnet']['network_id'])
with self.router() as r:
self._add_external_gateway_to_router(
@@ -831,7 +865,7 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
def test_floatingip_with_assoc_fails(self):
fmt = 'json'
with self.subnet() as public_sub:
with self.subnet(cidr='200.0.0.1/24') as public_sub:
self._set_net_external(public_sub['subnet']['network_id'])
with self.port() as private_port:
with self.router() as r: