From 1d61c5f736b9df7253a1939fe55f1875f988d1f4 Mon Sep 17 00:00:00 2001 From: Henry Gessau Date: Wed, 24 Jun 2015 03:16:52 +0000 Subject: [PATCH] Revert "Fix subnet creation failure on IPv6 valid gateway" Because it breaks tests.api.test_dhcp_ipv6.NetworksTestDHCPv6.test_dhcp_stateful_fixedips_outrange This reverts commit ee51ef72d37a02005a7733b7f2faf7236db850a1. Change-Id: Id02d9034ca809f194ff7551167bfda3559fb1200 --- neutron/ipam/subnet_alloc.py | 8 +---- neutron/ipam/utils.py | 5 ++-- neutron/tests/unit/ipam/test_subnet_alloc.py | 31 -------------------- 3 files changed, 3 insertions(+), 41 deletions(-) diff --git a/neutron/ipam/subnet_alloc.py b/neutron/ipam/subnet_alloc.py index d1a6f681f..dc38f4375 100644 --- a/neutron/ipam/subnet_alloc.py +++ b/neutron/ipam/subnet_alloc.py @@ -126,19 +126,13 @@ class SubnetAllocator(driver.Pool): self._check_subnetpool_tenant_quota(request.tenant_id, request.prefixlen) cidr = request.subnet_cidr - gateway = request.gateway_ip - if gateway and not ipam_utils.check_subnet_ip(cidr, gateway): - msg = _("Cannot allocate requested subnet due to bad gateway " - "address") - raise n_exc.SubnetAllocationError(reason=msg) - available = self._get_available_prefix_list() matched = netaddr.all_matching_cidrs(cidr, available) if len(matched) is 1 and matched[0].prefixlen <= cidr.prefixlen: return IpamSubnet(request.tenant_id, request.subnet_id, cidr, - gateway_ip=gateway, + gateway_ip=request.gateway_ip, allocation_pools=request.allocation_pools) msg = _("Cannot allocate requested subnet from the available " "set of prefixes") diff --git a/neutron/ipam/utils.py b/neutron/ipam/utils.py index 3f0bda173..74927769a 100644 --- a/neutron/ipam/utils.py +++ b/neutron/ipam/utils.py @@ -21,9 +21,8 @@ def check_subnet_ip(cidr, ip_address): ip = netaddr.IPAddress(ip_address) net = netaddr.IPNetwork(cidr) # Check that the IP is valid on subnet. This cannot be the - # network or the broadcast address (which exists only in IPv4) - return (ip != net.network - and (net.version == 6 or ip != net.broadcast) + # network or the broadcast address + return (ip != net.network and ip != net.broadcast and net.netmask & ip == net.network) diff --git a/neutron/tests/unit/ipam/test_subnet_alloc.py b/neutron/tests/unit/ipam/test_subnet_alloc.py index 8923ef8de..25021af2f 100644 --- a/neutron/tests/unit/ipam/test_subnet_alloc.py +++ b/neutron/tests/unit/ipam/test_subnet_alloc.py @@ -146,37 +146,6 @@ class TestSubnetAllocation(testlib_api.SqlTestCase): self.assertEqual(detail.gateway_ip, netaddr.IPAddress('10.1.2.254')) - def test_allocate_specific_ipv6_subnet_specific_gateway(self): - # Same scenario as described in bug #1466322 - sp = self._create_subnet_pool(self.plugin, self.ctx, 'test-sp', - ['2210::/64'], - 64, 6) - sp = self.plugin._get_subnetpool(self.ctx, sp['id']) - with self.ctx.session.begin(subtransactions=True): - sa = subnet_alloc.SubnetAllocator(sp, self.ctx) - req = ipam.SpecificSubnetRequest(self._tenant_id, - uuidutils.generate_uuid(), - '2210::/64', - '2210::ffff:ffff:ffff:ffff') - res = sa.allocate_subnet(req) - detail = res.get_details() - self.assertEqual(detail.gateway_ip, - netaddr.IPAddress('2210::ffff:ffff:ffff:ffff')) - - def test_allocate_specific_ipv4_subnet_specific_broadcast_gateway(self): - # Valid failure in subnet creation due to gateway==broadcast ip - sp = self._create_subnet_pool(self.plugin, self.ctx, 'test-sp', - ['10.1.0.0/24'], - 24, 4) - sa = subnet_alloc.SubnetAllocator(sp, self.ctx) - req = ipam.SpecificSubnetRequest(self._tenant_id, - uuidutils.generate_uuid(), - '10.1.0.0/24', - gateway_ip='10.1.0.255') - self.assertRaises(n_exc.SubnetAllocationError, - sa.allocate_subnet, - req) - def test__allocation_value_for_tenant_no_allocations(self): sp = self._create_subnet_pool(self.plugin, self.ctx, 'test-sp', ['10.1.0.0/16', '192.168.1.0/24'], -- 2.45.2