From 8d8444aa0ce0e6db1ebbc922311ec1eef546f2fe Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Wed, 18 Nov 2015 08:26:18 -0800 Subject: [PATCH] IPAM: fix 'enable-dhcp' with internal driver Commit 0c1f96ad5a6606c1205bd50ea944c3a383892cde 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 Change-Id: I4d7ecb985762a8eef39cb2f22f210b4899f1a22e --- neutron/db/db_base_plugin_v2.py | 11 +------ .../tests/unit/db/test_db_base_plugin_v2.py | 30 ------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index cebb92aa43e..68a306327cd 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -451,16 +451,7 @@ 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) + net = netaddr.IPNetwork(s['cidr']) if net.is_multicast(): error_message = _("Multicast IP subnet is not supported " diff --git a/neutron/tests/unit/db/test_db_base_plugin_v2.py b/neutron/tests/unit/db/test_db_base_plugin_v2.py index 9be3545dfe2..13fed38c2eb 100644 --- a/neutron/tests/unit/db/test_db_base_plugin_v2.py +++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py @@ -4361,36 +4361,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: