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
(cherry picked from commit cba1493de2)
This commit is contained in:
Fawad Khaliq 2014-06-25 14:37:29 -07:00
parent 60839b6e04
commit 98ef1bcd22
2 changed files with 21 additions and 3 deletions

View File

@ -583,12 +583,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))})

View File

@ -129,6 +129,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 = NeutronManager.get_plugin()
pool = plugin._allocate_pools_for_subnet(context, subnet)
self.assertEqual(allocation_pool, pool)
class TestPlumgridProvidernet(PLUMgridPluginV2TestCase):