Merge "Fix bug when checking duplicated subnets for router interface" into stable/ocata
This commit is contained in:
commit
fa1c3b4438
@ -468,7 +468,9 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
raise e.errors[0].error
|
||||
|
||||
self._check_for_dup_router_subnets(context, router,
|
||||
new_network_id, subnets)
|
||||
new_network_id,
|
||||
subnets,
|
||||
include_gateway=True)
|
||||
self._create_router_gw_port(context, router,
|
||||
new_network_id, ext_ips)
|
||||
registry.notify(resources.ROUTER_GATEWAY,
|
||||
@ -582,7 +584,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
filters=filters)
|
||||
|
||||
def _check_for_dup_router_subnets(self, context, router,
|
||||
network_id, new_subnets):
|
||||
network_id, new_subnets,
|
||||
include_gateway=False):
|
||||
# It's possible these ports are on the same network, but
|
||||
# different subnets.
|
||||
new_subnet_ids = {s['id'] for s in new_subnets}
|
||||
@ -593,7 +596,10 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
msg = (_("Router already has a port on subnet %s")
|
||||
% ip['subnet_id'])
|
||||
raise n_exc.BadRequest(resource='router', msg=msg)
|
||||
router_subnets.append(ip['subnet_id'])
|
||||
gw_owner = (p.get('device_owner') == DEVICE_OWNER_ROUTER_GW)
|
||||
if include_gateway == gw_owner:
|
||||
router_subnets.append(ip['subnet_id'])
|
||||
|
||||
# Ignore temporary Prefix Delegation CIDRs
|
||||
new_subnets = [s for s in new_subnets
|
||||
if s['cidr'] != n_const.PROVISIONAL_IPV6_PD_PREFIX]
|
||||
|
@ -1569,6 +1569,36 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
|
||||
expected_code=exc.
|
||||
HTTPBadRequest.code)
|
||||
|
||||
def test_router_add_interface_cidr_overlapped_with_gateway(self):
|
||||
with self.router() as r:
|
||||
with self.subnet(cidr='10.0.1.0/24') as s1, self.subnet(
|
||||
cidr='10.0.0.0/16') as s2:
|
||||
self._set_net_external(s2['subnet']['network_id'])
|
||||
self._add_external_gateway_to_router(
|
||||
r['router']['id'],
|
||||
s2['subnet']['network_id'])
|
||||
res = self._router_interface_action('add',
|
||||
r['router']['id'],
|
||||
s1['subnet']['id'],
|
||||
None)
|
||||
self.assertIn('port_id', res)
|
||||
|
||||
def test_router_add_interface_by_port_cidr_overlapped_with_gateway(self):
|
||||
with self.router() as r:
|
||||
with self.subnet(cidr='10.0.1.0/24') as s1, self.subnet(
|
||||
cidr='10.0.0.0/16') as s2:
|
||||
with self.port(subnet=s1) as p:
|
||||
self._set_net_external(s2['subnet']['network_id'])
|
||||
self._add_external_gateway_to_router(
|
||||
r['router']['id'],
|
||||
s2['subnet']['network_id'])
|
||||
|
||||
res = self._router_interface_action('add',
|
||||
r['router']['id'],
|
||||
None,
|
||||
p['port']['id'])
|
||||
self.assertIn('port_id', res)
|
||||
|
||||
def test_router_add_gateway_dup_subnet1_returns_400(self):
|
||||
with self.router() as r:
|
||||
with self.subnet() as s:
|
||||
|
Loading…
Reference in New Issue
Block a user