IPAM: fix 'enable-dhcp' with internal driver

Commit 0c1f96ad5a broke the ipam
internal driver. The base plugin should only call the ipam interface
and not invoke the IPallocation data model.

The code that validated that the subnet had one free IP address was
removed. This would not guarantee that a port would indeed be free,
that is, a parallel operation could have created a port on the subnet
during this check.

Closes-bug: #1514810

Conflicts:
	neutron/db/db_base_plugin_v2.py

Change-Id: I4d7ecb985762a8eef39cb2f22f210b4899f1a22e
(cherry picked from commit 8d8444aa0c)
This commit is contained in:
Gary Kotton 2015-11-18 08:26:18 -08:00
parent 271413fcb4
commit b2801195e3
2 changed files with 0 additions and 40 deletions

View File

@ -451,16 +451,6 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if ((ip_ver == 4 and subnet_prefixlen > 30) or
(ip_ver == 6 and subnet_prefixlen > 126)):
raise n_exc.InvalidInput(error_message=error_message)
else:
# NOTE(watanabe.isao): The following restriction is necessary
# only when updating subnet.
if cur_subnet:
range_qry = context.session.query(models_v2.
IPAvailabilityRange).join(models_v2.IPAllocationPool)
ip_range = range_qry.filter_by(subnet_id=s['id']).first()
if not ip_range:
raise n_exc.IpAddressGenerationFailure(
net_id=cur_subnet.network_id)
if attributes.is_attr_set(s.get('gateway_ip')):
self._validate_ip_version(ip_ver, s['gateway_ip'], 'gateway_ip')

View File

@ -4310,36 +4310,6 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
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
with self.network() as network:
with self.subnet(network=network,
allocation_pools=allocation_pools,
enable_dhcp=False,
cidr=cidr,
ip_version=ip_version) as subnet:
id = subnet['subnet']['network_id']
self._create_port(self.fmt, id)
data = {'subnet': {'enable_dhcp': True}}
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_ipv4(self):
allocation_pools = [{'start': '10.0.0.2', 'end': '10.0.0.2'}]
cidr = '10.0.0.0/30'
self._test_subnet_update_enable_dhcp_no_ip_available_returns_409(
allocation_pools, cidr)
def test_subnet_update_enable_dhcp_no_ip_available_returns_409_ipv6(self):
allocation_pools = [{'start': '2001:db8::2', 'end': '2001:db8::2'}]
cidr = '2001:db8::/126'
self._test_subnet_update_enable_dhcp_no_ip_available_returns_409(
allocation_pools, cidr)
def test_show_subnet(self):
with self.network() as network:
with self.subnet(network=network) as subnet: