context, subnet_id, s)
if "allocation_pools" in s:
- self._validate_allocation_pools(s['allocation_pools'],
- s['cidr'])
changes['allocation_pools'] = (
self._update_subnet_allocation_pools(context, subnet_id, s))
new_subnetpool_id != subnet.subnetpool_id):
raise n_exc.NetworkSubnetPoolAffinityError()
- def _validate_allocation_pools(self, ip_pools, subnet_cidr):
+ def validate_allocation_pools(self, ip_pools, subnet_cidr):
"""Validate IP allocation pools.
Verify start and end address for each allocation pool are valid,
return self.generate_pools(cidr, gateway_ip)
ip_range_pools = self.pools_to_ip_range(allocation_pools)
- self._validate_allocation_pools(ip_range_pools, cidr)
+ self.validate_allocation_pools(ip_range_pools, cidr)
if gateway_ip:
self.validate_gw_out_of_pools(gateway_ip, ip_range_pools)
return ip_range_pools
self.assertEqual(res.status_int,
webob.exc.HTTPConflict.code)
+ def test_update_subnet_allocation_pools_invalid_returns_400(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:
+ # Check allocation pools
+ invalid_pools = [[{'end': '10.0.0.254'}],
+ [{'start': '10.0.0.254'}],
+ [{'start': '1000.0.0.254'}],
+ [{'start': '10.0.0.2', 'end': '10.0.0.254'},
+ {'end': '10.0.0.254'}],
+ None,
+ [{'start': '10.0.0.200', 'end': '10.0.3.20'}],
+ [{'start': '10.0.2.250', 'end': '10.0.3.5'}],
+ [{'start': '10.0.0.0', 'end': '10.0.0.50'}],
+ [{'start': '10.0.2.10', 'end': '10.0.2.5'}],
+ [{'start': 'fe80::2', 'end': 'fe80::ffff'}]]
+ for pool in invalid_pools:
+ data = {'subnet': {'allocation_pools': pool}}
+ req = self.new_update_request('subnets', data,
+ subnet['subnet']['id'])
+ res = req.get_response(self.api)
+ self.assertEqual(res.status_int,
+ webob.exc.HTTPClientError.code)
+
+ def test_update_subnet_allocation_pools_overlapping_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.20', 'end': '10.0.0.40'},
+ {'start': '10.0.0.30', 'end': '10.0.0.50'}]}}
+ 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