Commit b0a8a7b1 authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos
Browse files

cyclades: Update subnets.py to support slac

IPv6 subnets now support a boolean attribute called slac.
If a request for a subnet contains both a slac field and an enable_dhcp
field, only the slac one will be used. If no slac field is found for an
IPv6 subnet, the field enable_dhcp will be used instead.

IPv4 subnets silently ignore any slac field if present and only use
enable_dhcp.

This commit adds the relevant tests in tests/subnets.py too.
parent 317dadb4
......@@ -129,10 +129,15 @@ def create_subnet(request):
if ipversion == 6:
networks.validate_network_params(None, None, cidr, gateway)
slac = subnet.get('slac', None)
if slac is not None:
dhcp = check_dhcp_value(slac)
else:
dhcp = check_dhcp_value(subnet.get('enable_dhcp', True))
else:
networks.validate_network_params(cidr, gateway)
dhcp = check_dhcp_value(subnet.get('enable_dhcp', True))
dhcp = check_dhcp_value(subnet.get('enable_dhcp', True))
name = check_name_length(subnet.get('name', None))
dns = subnet.get('dns_nameservers', None)
......@@ -275,6 +280,10 @@ def subnet_to_dict(subnet):
'dns_nameservers': subnet.dns_nameservers,
'host_routes': subnet.host_routes,
'allocation_pools': []})
if subnet.ipversion == 6:
dictionary['slac'] = subnet.dhcp
return dictionary
......@@ -288,8 +297,8 @@ def check_number_of_subnets(network, version):
def check_dhcp_value(dhcp):
"""Check if dhcp value is in acceptable values"""
if dhcp not in [True, False]:
raise api.faults.BadRequest("Malformed request, enable_dhcp must be "
"True or False")
raise api.faults.BadRequest("Malformed request, enable_dhcp/slac must "
"be True or False")
return dhcp
......
......@@ -92,6 +92,48 @@ class SubnetTest(BaseAPITest):
json.dumps(request), "json")
self.assertSuccess(response)
def test_create_subnet_success_ipv4_with_slac(self):
"""Test create an IPv4 subnet, with a slac that will be ingored"""
test_net = mf.NetworkFactory()
request = {
'subnet': {
'network_id': test_net.id,
'cidr': '10.0.3.0/24',
'ip_version': 4,
'slac': False}
}
response = self.post(SUBNETS_URL, test_net.userid,
json.dumps(request), "json")
self.assertSuccess(response)
def test_create_subnet_success_ipv6_with_slac(self):
"""Test create a subnet with ipv6 and slac"""
test_net = mf.NetworkFactory()
request = {
'subnet': {
'network_id': test_net.id,
'cidr': 'fdc1:4992:1130:fc0b::/64',
'ip_version': 6,
'slac': False}
}
response = self.post(SUBNETS_URL, test_net.userid,
json.dumps(request), "json")
self.assertSuccess(response)
def test_create_subnet_with_malformed_slac(self):
"""Test create a subnet with ipv6 and a malformed slac"""
test_net = mf.NetworkFactory()
request = {
'subnet': {
'network_id': test_net.id,
'cidr': 'fdc1:4992:1130:fc0b::/64',
'ip_version': 6,
'slac': 'Random'}
}
response = self.post(SUBNETS_URL, test_net.userid,
json.dumps(request), "json")
self.assertBadRequest(response)
def test_create_subnet_success_ipv6(self):
"""Test create an IPv6 subnet successfully"""
test_net = mf.NetworkFactory()
......@@ -287,6 +329,19 @@ class SubnetTest(BaseAPITest):
"json")
self.assertBadRequest(response)
def test_create_subnet_with_dhcp_set_to_false(self):
"""Create a subnet with a dhcp set to false"""
test_net = mf.NetworkFactory()
request = {
'subnet': {
'network_id': test_net.id,
'cidr': '192.168.3.0/24',
'enable_dhcp': False}
}
response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
"json")
self.assertSuccess(response)
def test_create_subnet_with_dns_nameservers(self):
"""Create a subnet with dns nameservers"""
test_net = mf.NetworkFactory()
......
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