Merge "Prevent update alloc pool over existing gateway ip"

This commit is contained in:
Jenkins 2015-08-04 00:44:18 +00:00 committed by Gerrit Code Review
commit 37eab0bb4c
2 changed files with 21 additions and 2 deletions

View File

@ -577,9 +577,13 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
range_pools = self.ipam.pools_to_ip_range(s['allocation_pools'])
s['allocation_pools'] = range_pools
if s.get('gateway_ip') is not None:
# If either gateway_ip or allocation_pools were specified
gateway_ip = s.get('gateway_ip')
if gateway_ip is not None or s.get('allocation_pools') is not None:
if gateway_ip is None:
gateway_ip = db_subnet.gateway_ip
pools = range_pools if range_pools is not None else db_pools
self.ipam.validate_gw_out_of_pools(s["gateway_ip"], pools)
self.ipam.validate_gw_out_of_pools(gateway_ip, pools)
with context.session.begin(subtransactions=True):
subnet, changes = self.ipam.update_db_subnet(context, id, s,

View File

@ -4161,6 +4161,21 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
self.assertEqual(res.status_int,
webob.exc.HTTPClientError.code)
#updating alloc pool on top of existing subnet.gateway_ip
def test_update_subnet_allocation_pools_over_gateway_ip_returns_409(self):
allocation_pools = [{'start': '10.0.0.2', 'end': '10.0.0.254'}]
with self.network() as network:
with self.subnet(network=network,
allocation_pools=allocation_pools,
cidr='10.0.0.0/24') as subnet:
data = {'subnet': {'allocation_pools': [
{'start': '10.0.0.1', 'end': '10.0.0.254'}]}}
req = self.new_update_request('subnets', data,
subnet['subnet']['id'])
res = req.get_response(self.api)
self.assertEqual(res.status_int,
webob.exc.HTTPConflict.code)
def _test_subnet_update_enable_dhcp_no_ip_available_returns_409(
self, allocation_pools, cidr):
ip_version = netaddr.IPNetwork(cidr).version