Merge "Disallow networks with first ip 0.0.0.0 with dhcp enabled"

This commit is contained in:
Zuul 2018-08-31 19:20:29 +00:00 committed by Gerrit Code Review
commit 981532f0f8
2 changed files with 24 additions and 0 deletions

View File

@ -588,6 +588,10 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
error_message = _("Loopback IP subnet is not supported "
"if enable_dhcp is True")
raise exc.InvalidInput(error_message=error_message)
elif ip_ver == constants.IP_VERSION_4 and net.first is 0:
error_message = _("First IP '0.0.0.0' of network is not "
"supported if enable_dhcp is True.")
raise exc.InvalidInput(error_message=error_message)
if validators.is_attr_set(s.get('gateway_ip')):
self._validate_ip_version(ip_ver, s['gateway_ip'], 'gateway_ip')

View File

@ -3196,6 +3196,16 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
res = subnet_req.get_response(self.api)
self.assertEqual(webob.exc.HTTPClientError.code, res.status_int)
def test_create_subnet_invalid_gw_V4_cidr(self):
with self.network() as network:
data = {'subnet': {'network_id': network['network']['id'],
'cidr': '10.0.0.0/4',
'ip_version': '4',
'tenant_id': network['network']['tenant_id']}}
subnet_req = self.new_create_request('subnets', data)
res = subnet_req.get_response(self.api)
self.assertEqual(webob.exc.HTTPClientError.code, res.status_int)
def test_create_subnet_with_cidr_and_default_subnetpool(self):
"""Expect subnet-create to keep semantic with default pools."""
with self.network() as network:
@ -4608,6 +4618,16 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
res = req.get_response(self.api)
self.assertEqual(res.status_int, 200)
def test_update_subnet_invalid_gw_V4_cidr(self):
with self.network() as network:
with self.subnet(network=network) as subnet:
data = {'subnet': {'cidr': '10.0.0.0/4'}}
req = self.new_update_request('subnets', data,
subnet['subnet']['id'])
res = req.get_response(self.api)
self.assertEqual(webob.exc.HTTPClientError.code,
res.status_int)
def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
with self.network() as network:
with self.subnet(network=network) as subnet: