Revision 97ca522f
b/snf-cyclades-app/synnefo/api/subnets.py | ||
---|---|---|
129 | 129 |
|
130 | 130 |
if ipversion == 6: |
131 | 131 |
networks.validate_network_params(None, None, cidr, gateway) |
132 |
slac = subnet.get('slac', None) |
|
133 |
if slac is not None: |
|
134 |
dhcp = check_dhcp_value(slac) |
|
135 |
else: |
|
136 |
dhcp = check_dhcp_value(subnet.get('enable_dhcp', True)) |
|
132 | 137 |
else: |
133 | 138 |
networks.validate_network_params(cidr, gateway) |
139 |
dhcp = check_dhcp_value(subnet.get('enable_dhcp', True)) |
|
134 | 140 |
|
135 |
dhcp = check_dhcp_value(subnet.get('enable_dhcp', True)) |
|
136 | 141 |
name = check_name_length(subnet.get('name', None)) |
137 | 142 |
|
138 | 143 |
dns = subnet.get('dns_nameservers', None) |
... | ... | |
275 | 280 |
'dns_nameservers': subnet.dns_nameservers, |
276 | 281 |
'host_routes': subnet.host_routes, |
277 | 282 |
'allocation_pools': []}) |
283 |
|
|
284 |
if subnet.ipversion == 6: |
|
285 |
dictionary['slac'] = subnet.dhcp |
|
286 |
|
|
278 | 287 |
return dictionary |
279 | 288 |
|
280 | 289 |
|
... | ... | |
288 | 297 |
def check_dhcp_value(dhcp): |
289 | 298 |
"""Check if dhcp value is in acceptable values""" |
290 | 299 |
if dhcp not in [True, False]: |
291 |
raise api.faults.BadRequest("Malformed request, enable_dhcp must be "
|
|
292 |
"True or False") |
|
300 |
raise api.faults.BadRequest("Malformed request, enable_dhcp/slac must "
|
|
301 |
"be True or False")
|
|
293 | 302 |
return dhcp |
294 | 303 |
|
295 | 304 |
|
b/snf-cyclades-app/synnefo/api/tests/subnets.py | ||
---|---|---|
92 | 92 |
json.dumps(request), "json") |
93 | 93 |
self.assertSuccess(response) |
94 | 94 |
|
95 |
def test_create_subnet_success_ipv4_with_slac(self): |
|
96 |
"""Test create an IPv4 subnet, with a slac that will be ingored""" |
|
97 |
test_net = mf.NetworkFactory() |
|
98 |
request = { |
|
99 |
'subnet': { |
|
100 |
'network_id': test_net.id, |
|
101 |
'cidr': '10.0.3.0/24', |
|
102 |
'ip_version': 4, |
|
103 |
'slac': False} |
|
104 |
} |
|
105 |
response = self.post(SUBNETS_URL, test_net.userid, |
|
106 |
json.dumps(request), "json") |
|
107 |
self.assertSuccess(response) |
|
108 |
|
|
109 |
def test_create_subnet_success_ipv6_with_slac(self): |
|
110 |
"""Test create a subnet with ipv6 and slac""" |
|
111 |
test_net = mf.NetworkFactory() |
|
112 |
request = { |
|
113 |
'subnet': { |
|
114 |
'network_id': test_net.id, |
|
115 |
'cidr': 'fdc1:4992:1130:fc0b::/64', |
|
116 |
'ip_version': 6, |
|
117 |
'slac': False} |
|
118 |
} |
|
119 |
response = self.post(SUBNETS_URL, test_net.userid, |
|
120 |
json.dumps(request), "json") |
|
121 |
self.assertSuccess(response) |
|
122 |
|
|
123 |
def test_create_subnet_with_malformed_slac(self): |
|
124 |
"""Test create a subnet with ipv6 and a malformed slac""" |
|
125 |
test_net = mf.NetworkFactory() |
|
126 |
request = { |
|
127 |
'subnet': { |
|
128 |
'network_id': test_net.id, |
|
129 |
'cidr': 'fdc1:4992:1130:fc0b::/64', |
|
130 |
'ip_version': 6, |
|
131 |
'slac': 'Random'} |
|
132 |
} |
|
133 |
response = self.post(SUBNETS_URL, test_net.userid, |
|
134 |
json.dumps(request), "json") |
|
135 |
self.assertBadRequest(response) |
|
136 |
|
|
95 | 137 |
def test_create_subnet_success_ipv6(self): |
96 | 138 |
"""Test create an IPv6 subnet successfully""" |
97 | 139 |
test_net = mf.NetworkFactory() |
... | ... | |
287 | 329 |
"json") |
288 | 330 |
self.assertBadRequest(response) |
289 | 331 |
|
332 |
def test_create_subnet_with_dhcp_set_to_false(self): |
|
333 |
"""Create a subnet with a dhcp set to false""" |
|
334 |
test_net = mf.NetworkFactory() |
|
335 |
request = { |
|
336 |
'subnet': { |
|
337 |
'network_id': test_net.id, |
|
338 |
'cidr': '192.168.3.0/24', |
|
339 |
'enable_dhcp': False} |
|
340 |
} |
|
341 |
response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request), |
|
342 |
"json") |
|
343 |
self.assertSuccess(response) |
|
344 |
|
|
290 | 345 |
def test_create_subnet_with_dns_nameservers(self): |
291 | 346 |
"""Create a subnet with dns nameservers""" |
292 | 347 |
test_net = mf.NetworkFactory() |
Also available in: Unified diff