Merge "Only restrict gateway_ip change for router ports"
This commit is contained in:
commit
557da957b8
|
@ -466,10 +466,12 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||||
# a subnet-update and a router-interface-add operation are
|
# a subnet-update and a router-interface-add operation are
|
||||||
# executed concurrently
|
# executed concurrently
|
||||||
if cur_subnet and not ipv6_utils.is_ipv6_pd_enabled(s):
|
if cur_subnet and not ipv6_utils.is_ipv6_pd_enabled(s):
|
||||||
alloc_qry = context.session.query(models_v2.IPAllocation)
|
ipal = models_v2.IPAllocation
|
||||||
allocated = alloc_qry.filter_by(
|
alloc_qry = context.session.query(ipal)
|
||||||
ip_address=cur_subnet['gateway_ip'],
|
alloc_qry = alloc_qry.join("port", "routerport")
|
||||||
subnet_id=cur_subnet['id']).first()
|
allocated = alloc_qry.filter(
|
||||||
|
ipal.ip_address == cur_subnet['gateway_ip'],
|
||||||
|
ipal.subnet_id == cur_subnet['id']).first()
|
||||||
if allocated and allocated['port_id']:
|
if allocated and allocated['port_id']:
|
||||||
raise n_exc.GatewayIpInUse(
|
raise n_exc.GatewayIpInUse(
|
||||||
ip_address=cur_subnet['gateway_ip'],
|
ip_address=cur_subnet['gateway_ip'],
|
||||||
|
|
|
@ -4182,22 +4182,37 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
||||||
self.assertEqual(webob.exc.HTTPClientError.code,
|
self.assertEqual(webob.exc.HTTPClientError.code,
|
||||||
res.status_int)
|
res.status_int)
|
||||||
|
|
||||||
def test_update_subnet_gw_ip_in_use_returns_409(self):
|
def test_update_subnet_gw_ip_in_use_by_router_returns_409(self):
|
||||||
with self.network() as network:
|
with self.network() as network:
|
||||||
with self.subnet(
|
with self.subnet(network=network,
|
||||||
network=network,
|
allocation_pools=[{'start': '10.0.0.2',
|
||||||
allocation_pools=[{'start': '10.0.0.100',
|
'end': '10.0.0.8'}]) as subnet:
|
||||||
'end': '10.0.0.253'}]) as subnet:
|
s = subnet['subnet']
|
||||||
subnet_data = subnet['subnet']
|
|
||||||
with self.port(
|
with self.port(
|
||||||
subnet=subnet,
|
subnet=subnet, fixed_ips=[{'subnet_id': s['id'],
|
||||||
fixed_ips=[{'subnet_id': subnet_data['id'],
|
'ip_address': s['gateway_ip']}]
|
||||||
'ip_address': subnet_data['gateway_ip']}]):
|
) as port:
|
||||||
|
# this protection only applies to router ports so we need
|
||||||
|
# to make this port belong to a router
|
||||||
|
ctx = context.get_admin_context()
|
||||||
|
with ctx.session.begin():
|
||||||
|
router = l3_db.Router()
|
||||||
|
ctx.session.add(router)
|
||||||
|
with ctx.session.begin():
|
||||||
|
rp = l3_db.RouterPort(router_id=router.id,
|
||||||
|
port_id=port['port']['id'])
|
||||||
|
ctx.session.add(rp)
|
||||||
data = {'subnet': {'gateway_ip': '10.0.0.99'}}
|
data = {'subnet': {'gateway_ip': '10.0.0.99'}}
|
||||||
req = self.new_update_request('subnets', data,
|
req = self.new_update_request('subnets', data,
|
||||||
subnet_data['id'])
|
s['id'])
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
self.assertEqual(409, res.status_int)
|
self.assertEqual(409, res.status_int)
|
||||||
|
# should work fine if it's not a router port
|
||||||
|
with ctx.session.begin():
|
||||||
|
ctx.session.delete(rp)
|
||||||
|
ctx.session.delete(router)
|
||||||
|
res = req.get_response(self.api)
|
||||||
|
self.assertEqual(res.status_int, 200)
|
||||||
|
|
||||||
def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
|
def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
|
||||||
with self.network() as network:
|
with self.network() as network:
|
||||||
|
|
Loading…
Reference in New Issue