]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fixed dhcp & gateway ip conflict in PLUMgrid plugin
authorFawad Khaliq <fawad@plumgrid.com>
Wed, 25 Jun 2014 21:37:29 +0000 (14:37 -0700)
committerFawad Khaliq <fawad@plumgrid.com>
Wed, 25 Jun 2014 21:41:22 +0000 (14:41 -0700)
   * Adjust dhcp IP if conflicts with gateway IP
   * Added unit test case

Closes-Bug:1333442
Change-Id: Iaa4e63faf28b783e6b5dbc50035ca50ccde9951a

neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py
neutron/tests/unit/plumgrid/test_plumgrid_plugin.py

index 8d0dbef0df1915c41e7c161bb128c4a5c9170496..4fb61bf7c066657225ff7d7cb832b6b853dbe629 100644 (file)
@@ -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))})
index f5d503c0ad89ce9367eeccd5ba253eef22701c3f..83daf2d809079ce4d20850a244ced5e8a2d39d92 100644 (file)
@@ -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):