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

NAT-199: add tests for delete host in IPAM

parent 551aa18c
No related branches found
No related tags found
2 merge requests!27Merge develop into NAT-185,!15Nat 185
......@@ -73,7 +73,12 @@ def delete_service_host(
cname_aliases=[],
service_type=''
) -> HostAddresses:
return None
return _ipam.delete_service_host(
hostname=hostname,
host_addresses=host_addresses,
cname_aliases=cname_aliases,
service_type=service_type
)
if __name__ == '__main__':
......
......@@ -315,3 +315,96 @@ def test_delete_service_network(data_config_filename):
service_type='TRUNK'
)
assert service_network is None
@responses.activate
def test_delete_service_host(data_config_filename):
responses.add(
method=responses.GET,
url=re.compile(r'.*/wapi.*record:host.*'),
json=[
{
'_ref': 'record:host/ZG5zLmhvc3QkLl9kZWZhdWx0Lmdzby5oYV9sbw:ha_lo.gso/default', # noqa: E501
'ipv4addrs': [
{
'_ref': 'record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuZ3NvLmhhX2xvLjEwLjI1NS4yNTUuMS40.255.255.1/ha_lo.gso/default', # noqa: E501
'configure_for_dhcp': False,
'host': 'ha_lo.gso', 'ipv4addr': '10.255.255.1'
}
],
'ipv6addrs': [
{
'_ref': 'record:host_ipv6addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuZvLmhhX2xvLmRlYWQ6YmVlZjo6MS4:dead%3Abeef%3A%3A1/ha_lo.gso/default', # noqa: E501
'configure_for_dhcp': False,
'host': 'ha_lo.gso', 'ipv6addr': 'dead:beef::1'
}
],
'name': 'ha_lo.gso', 'view': 'default'
}
]
)
responses.add(
method=responses.GET,
url=re.compile(r'.*/wapi.*record:cname.*'),
json=[
{
'_ref': 'record:cname/ZG5zLmJpbmRfY25hbWUkLl9kZWZhdWx0Lmdzby5oYS5hbGlhczE:alias1.ha.gso/default', # noqa: E501
'canonical': 'hA_LO.lo', 'name': 'alias1.ha.lo',
'view': 'default'
},
{
'_ref': 'record:cname/5zLmJpbmRfY25hbWUkLl9kZWZhdWx0Lmdzby5oYS5hbGlhczI:alias2.ha.gso/default', # noqa: E501
'canonical': 'hA_LO.lo', 'name': 'alias2.ha.lo',
'view': 'default'
}
]
)
responses.add(
method=responses.DELETE,
url=re.compile(r'.*/wapi.*record:host.*'),
body='record:host/ZG5zLmhvc3QkLl9kZWZhdWx0Lmdzby5oYl9sbw:hb_lo.gso/default' # noqa: E501
)
responses.add(
method=responses.DELETE,
url=re.compile(r'.*/wapi.*record:cname.*'),
body='record:cname/ZG5zLmJpbmRfY25hbWUkLl9kZWZhdWx0Lmdzby5oYi5hbGlhczE:alias1.hb.gso/default' # noqa: E501
)
input_host_addresses = ipam.HostAddresses(
v4=ipaddress.ip_address('10.255.255.1'),
v6=ipaddress.ip_address('dead:beef::1')
)
host_addresses = ipam.delete_service_host(
hostname='ha_lo',
host_addresses=input_host_addresses,
cname_aliases=['alias1.ha', 'alias2.ha'],
service_type='LO'
)
assert host_addresses == ipam.HostAddresses(
v4=ipaddress.ip_address('10.255.255.1'),
v6=ipaddress.ip_address('dead:beef::1')
)
# Fail because missing CNAME
with pytest.raises(AssertionError):
host_addresses = ipam.delete_service_host(
hostname='ha_lo',
host_addresses=input_host_addresses,
cname_aliases=['alias1.ha'],
service_type='LO'
)
assert host_addresses is None
# Fail because non-matching CNAME
with pytest.raises(AssertionError):
host_addresses = ipam.delete_service_host(
hostname='ha_lo',
host_addresses=input_host_addresses,
cname_aliases=['alias1.ha', 'alias2.ha', 'alias3.ha'],
service_type='LO'
)
assert host_addresses 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