From: Fawad Khaliq Date: Wed, 25 Jun 2014 21:37:29 +0000 (-0700) Subject: Fixed dhcp & gateway ip conflict in PLUMgrid plugin X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=cba1493de269937f7df761fbacbc27d6e0fa6fa3;p=openstack-build%2Fneutron-build.git Fixed dhcp & gateway ip conflict in PLUMgrid plugin * Adjust dhcp IP if conflicts with gateway IP * Added unit test case Closes-Bug:1333442 Change-Id: Iaa4e63faf28b783e6b5dbc50035ca50ccde9951a --- diff --git a/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py b/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py index 8d0dbef0d..4fb61bf7c 100644 --- a/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py +++ b/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py @@ -586,12 +586,17 @@ class NeutronPluginPLUMgridV2(db_base_plugin_v2.NeutronDbPluginV2, pools = [] # Auto allocate the pool around gateway_ip net = netaddr.IPNetwork(subnet['cidr']) - first_ip = net.first + 2 + boundary = int(netaddr.IPAddress(subnet['gateway_ip'] or net.last)) + potential_dhcp_ip = int(net.first + 1) + if boundary == potential_dhcp_ip: + first_ip = net.first + 3 + boundary = net.first + 2 + else: + first_ip = net.first + 2 last_ip = net.last - 1 - gw_ip = int(netaddr.IPAddress(subnet['gateway_ip'] or net.last)) # Use the gw_ip to find a point for splitting allocation pools # for this subnet - split_ip = min(max(gw_ip, net.first), net.last) + split_ip = min(max(boundary, net.first), net.last) if split_ip > first_ip: pools.append({'start': str(netaddr.IPAddress(first_ip)), 'end': str(netaddr.IPAddress(split_ip - 1))}) diff --git a/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py b/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py index f5d503c0a..83daf2d80 100644 --- a/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py +++ b/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py @@ -127,6 +127,19 @@ class TestPlumgridAllocationPool(PLUMgridPluginV2TestCase): pool = plugin._allocate_pools_for_subnet(context, subnet) self.assertEqual(allocation_pool, pool) + def test_conflict_dhcp_gw_ip(self): + cidr = '10.0.0.0/24' + gateway_ip = '10.0.0.1' + subnet = {'gateway_ip': gateway_ip, + 'cidr': cidr, + 'ip_version': 4} + allocation_pool = [{"start": '10.0.0.3', + "end": '10.0.0.254'}] + context = None + plugin = manager.NeutronManager.get_plugin() + pool = plugin._allocate_pools_for_subnet(context, subnet) + self.assertEqual(allocation_pool, pool) + class TestPlumgridProvidernet(PLUMgridPluginV2TestCase):