Skip to content
Snippets Groups Projects
Commit 378c07f2 authored by JORGE SASIAIN's avatar JORGE SASIAIN
Browse files

NAT-152 / NAT-198: update tests and add some tests for fail cases

parent 4e5878d5
No related branches found
No related tags found
2 merge requests!27Merge develop into NAT-185,!15Nat 185
......@@ -36,7 +36,8 @@ def configuration_data():
"networks": ["dead:beef::/80"],
"mask": 128
},
"domain_name": ".lo"
"domain_name": ".lo",
"dns_view": "default"
},
"TRUNK": {
"V4": {
......@@ -49,7 +50,8 @@ def configuration_data():
"networks": [],
"mask": 126
},
"domain_name": ".trunk"
"domain_name": ".trunk",
"dns_view": "default"
},
"GEANT_IP": {
"V4": {
......@@ -62,7 +64,8 @@ def configuration_data():
"networks": [],
"mask": 126
},
"domain_name": ".geantip"
"domain_name": ".geantip",
"dns_view": "default"
}
},
"PROVISIONING_PROXY": {
......
import ipaddress
import pytest
import re
import responses
......@@ -32,6 +33,11 @@ def test_new_service_networks(data_config_filename):
v6=ipaddress.ip_network('dead:beef::18/128')
)
# should fail because this service type has networks instead of containers
with pytest.raises(AssertionError):
service_networks = ipam.new_service_networks(service_type='LO')
assert service_networks is None
@responses.activate
def test_new_service_host(data_config_filename):
......@@ -56,7 +62,7 @@ def test_new_service_host(data_config_filename):
responses.add(
method=responses.GET,
url=re.compile(r'.*/wapi.*/network.*'),
url=re.compile(r'.*/wapi.*/network.*10.255.255.*'),
json=[
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMjU1LjI1NS4yMC8zMi8w:10.255.255.20/32/default", # noqa: E501
......@@ -67,6 +73,19 @@ def test_new_service_host(data_config_filename):
)
responses.add(
method=responses.GET,
url=re.compile(r'.*/wapi.*/network.*10.255.254.*'),
json=[
{
"_ref": "network/ZG5zLm5Gd0VHQkRQUjMzLjMwNzIuMzE1LzAyLzI:10.255.254.20/32/default", # noqa: E501
"network": "10.255.254.20/32",
"network_view": "default"
}
]
)
responses.add(
method=responses.GET,
url=re.compile(r'.*/wapi.*/ipv6network.*'),
......@@ -81,13 +100,20 @@ def test_new_service_host(data_config_filename):
responses.add(
method=responses.POST,
url=re.compile(r'.*/wapi.*/network.*/.*?_function=next_available_ip&num=1$'), # noqa: E501
url=re.compile(r'.*/wapi.*/network/.*10.255.255.*?_function=next_available_ip&num=1$'), # noqa: E501
json={'ips': ['10.255.255.20']}
)
responses.add(
method=responses.POST,
url=re.compile(r'.*/wapi.*/ipv6network.*/.*?_function=next_available_ip&num=1$'), # noqa: E501
url=re.compile(r'.*/wapi.*/network/.*10.255.254.*?_function=next_available_ip&num=1$'), # noqa: E501
body="Cannot find 1 available IP address(es) in this network",
status=400
)
responses.add(
method=responses.POST,
url=re.compile(r'.*/wapi.*/ipv6network/.*?_function=next_available_ip&num=1$'), # noqa: E501
json={'ips': ['dead:beef::18']}
)
......@@ -109,6 +135,7 @@ def test_new_service_host(data_config_filename):
}
)
# test host creation by IP addresses
service_hosts = ipam.new_service_host(
hostname='test',
service_type='TRUNK',
......@@ -122,6 +149,7 @@ def test_new_service_host(data_config_filename):
v6=ipaddress.ip_address('dead:beef::18')
)
# test host creation by network addresses
service_hosts = ipam.new_service_host(
hostname='test',
service_type='TRUNK',
......@@ -135,6 +163,7 @@ def test_new_service_host(data_config_filename):
v6=ipaddress.ip_address('dead:beef::18')
)
# test host creation by just service_type when service cfg uses networks
service_hosts = ipam.new_service_host(
hostname='test',
service_type='LO'
......@@ -144,6 +173,7 @@ def test_new_service_host(data_config_filename):
v6=ipaddress.ip_address('dead:beef::18')
)
# test host creation by just service_type when service cfg uses containers
service_hosts = ipam.new_service_host(
hostname='test',
service_type='TRUNK'
......@@ -152,3 +182,15 @@ def test_new_service_host(data_config_filename):
v4=ipaddress.ip_address('10.255.255.20'),
v6=ipaddress.ip_address('dead:beef::18')
)
# test host creation that should return a no available IP error
with pytest.raises(AssertionError):
service_hosts = ipam.new_service_host(
hostname='test',
service_type='TRUNK',
service_networks=ipam.ServiceNetworks(
v4=ipaddress.ip_network('10.255.254.20/32'),
v6=ipaddress.ip_network('dead:beef::18/128')
)
)
assert service_hosts is None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment