Merge "Add check for cidr overrapping for adding external gateway"
This commit is contained in:
commit
96f1c565a6
@ -194,6 +194,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':
|
||||
@ -251,8 +257,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']
|
||||
|
@ -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:
|
||||
@ -766,7 +800,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:
|
||||
@ -797,7 +831,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(
|
||||
@ -834,7 +868,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:
|
||||
|
Loading…
Reference in New Issue
Block a user