Commit 3e0d4da8 authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos Committed by Christos Stavrakakis
Browse files

cyclades: Fix a bug in logic/

* Fix a potential crash if the gateway IP was the last available IP of
the subnet
* Create the corresponding test
parent b6d3e87b
......@@ -250,6 +250,24 @@ class SubnetTest(BaseAPITest):
json.dumps(request), "json")
def test_create_subnet_with_gateway_as_the_last_ip_of_subnet(self):
"""Test create a subnet with a gateway, as the last IP of the subnet"""
test_net = mf.NetworkFactory()
request = {
'subnet': {
'cidr': '',
'ip_version': 4,
response =, test_net.userid,
json.dumps(request), "json")
resp = json.loads(response.content)['subnet']
self.assertEqual("", resp['gateway_ip'])
self.assertEqual([{"start": "", "end": ""}],
def test_create_subnet_with_ip_pool_end_lower_than_start(self):
"""Test create a subnet with a pool where end is lower than start"""
test_net = mf.NetworkFactory()
......@@ -115,11 +115,13 @@ def _create_subnet(network_id, user_id, cidr, name, ipversion=4, gateway=None,
if ipversion == 6:
raise api.faults.Conflict("Can't allocate an IP Pool in IPv6")
elif ipversion == 4:
# Check if the gateway is the first IP of the subnet, in this case
# create a single ip pool
# Check if the gateway is the first IP of the subnet, or the last. In
# that case create a single ip pool.
if gateway_ip:
if int(gateway_ip) - int(cidr_ip) == 1:
allocation_pools = [(gateway_ip + 1, cidr_ip.broadcast - 1)]
elif int(cidr_ip.broadcast) - int(gateway_ip) == 1:
allocation_pools = [( + 1, gateway_ip - 1)]
# If the gateway isn't the first available ip, create two
# different ip pools adjacent to said ip
......@@ -232,7 +234,7 @@ def validate_pools(pool_list, cidr, gateway):
if not (gateway < start or gateway > end):
raise api.faults.Conflict("Gateway cannot be in pool range")
# Check if there is a conflict between the IP Poll ranges
# Check if there is a conflict between the IP Pool ranges
end =
for pool in pool_list:
if end >= pool[0]:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment