]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
IPAM: fix 'enable-dhcp' with internal driver
authorGary Kotton <gkotton@vmware.com>
Wed, 18 Nov 2015 16:26:18 +0000 (08:26 -0800)
committerGary Kotton <gkotton@vmware.com>
Thu, 19 Nov 2015 13:03:25 +0000 (05:03 -0800)
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
neutron/tests/unit/db/test_db_base_plugin_v2.py

index cebb92aa43e337f35ba472117c662817edfe0f0c..68a306327cdb41419c81ffabcc95bd1851033131 100644 (file)
@@ -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 "
index 9be3545dfe28140e079c7c5979b2fe4bceda1c2d..13fed38c2ebe13e58236d84856175fd627c0bde1 100644 (file)
@@ -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: