mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Updated tests and mark other old OS's as no coverage
This commit is contained in:
parent
fbd2fb282a
commit
5f8130a592
2 changed files with 180 additions and 61 deletions
|
@ -1004,6 +1004,7 @@ def _netbsd_interfaces_ifconfig(out):
|
|||
return ret
|
||||
|
||||
|
||||
# pragma: no cover
|
||||
def _junos_interfaces_ifconfig(out):
|
||||
"""
|
||||
Uses ifconfig to return a dictionary of interfaces with various information
|
||||
|
@ -1074,6 +1075,7 @@ def _junos_interfaces_ifconfig(out):
|
|||
return ret
|
||||
|
||||
|
||||
# pragma: no cover
|
||||
def junos_interfaces():
|
||||
"""
|
||||
Obtain interface information for Junos; ifconfig
|
||||
|
@ -1239,6 +1241,7 @@ def _get_iface_info(iface):
|
|||
return None, error_msg
|
||||
|
||||
|
||||
# pragma: no cover
|
||||
def _hw_addr_aix(iface):
|
||||
"""
|
||||
Return the hardware address (a.k.a. MAC address) for a given interface on AIX
|
||||
|
@ -1277,7 +1280,7 @@ def hw_addr(iface):
|
|||
|
||||
"""
|
||||
if salt.utils.platform.is_aix():
|
||||
return _hw_addr_aix
|
||||
return _hw_addr_aix(iface)
|
||||
|
||||
iface_info, error = _get_iface_info(iface)
|
||||
|
||||
|
@ -1746,6 +1749,7 @@ def _netlink_tool_remote_on(port, which_end):
|
|||
return remotes
|
||||
|
||||
|
||||
# pragma: no cover
|
||||
def _sunos_remotes_on(port, which_end):
|
||||
"""
|
||||
SunOS specific helper function.
|
||||
|
@ -1786,6 +1790,7 @@ def _sunos_remotes_on(port, which_end):
|
|||
return remotes
|
||||
|
||||
|
||||
# pragma: no cover
|
||||
def _freebsd_remotes_on(port, which_end):
|
||||
"""
|
||||
Returns set of ipv4 host addresses of remote established connections
|
||||
|
@ -1848,6 +1853,7 @@ def _freebsd_remotes_on(port, which_end):
|
|||
return remotes
|
||||
|
||||
|
||||
# pragma: no cover
|
||||
def _netbsd_remotes_on(port, which_end):
|
||||
"""
|
||||
Returns set of ipv4 host addresses of remote established connections
|
||||
|
@ -1909,6 +1915,7 @@ def _netbsd_remotes_on(port, which_end):
|
|||
return remotes
|
||||
|
||||
|
||||
# pragma: no cover
|
||||
def _openbsd_remotes_on(port, which_end):
|
||||
"""
|
||||
OpenBSD specific helper function.
|
||||
|
@ -2053,6 +2060,7 @@ def _linux_remotes_on(port, which_end):
|
|||
return remotes
|
||||
|
||||
|
||||
# pragma: no cover
|
||||
def _aix_remotes_on(port, which_end):
|
||||
"""
|
||||
AIX specific helper function.
|
||||
|
|
|
@ -142,6 +142,72 @@ IPV6_SUBNETS = {
|
|||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def linux_interfaces_dict():
|
||||
return {
|
||||
"eth0": {
|
||||
"hwaddr": "e0:3f:49:85:6a:af",
|
||||
"inet": [
|
||||
{
|
||||
"address": "10.10.10.56",
|
||||
"broadcast": "10.10.10.255",
|
||||
"netmask": "255.255.252.0",
|
||||
}
|
||||
],
|
||||
"inet6": [
|
||||
{
|
||||
"address": "fe80::e23f:49ff:fe85:6aaf",
|
||||
"prefixlen": "64",
|
||||
"scope": "link",
|
||||
}
|
||||
],
|
||||
"up": True,
|
||||
},
|
||||
"lo": {
|
||||
"inet": [{"address": "127.0.0.1", "netmask": "255.0.0.0"}],
|
||||
"inet6": [{"address": "::1", "prefixlen": "128", "scope": "host"}],
|
||||
"up": True,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def freebsd_interfaces_dict():
|
||||
return {
|
||||
"": {"up": False},
|
||||
"em0": {
|
||||
"hwaddr": "00:30:48:ff:ff:ff",
|
||||
"inet": [
|
||||
{
|
||||
"address": "10.10.10.250",
|
||||
"broadcast": "10.10.10.255",
|
||||
"netmask": "255.255.255.224",
|
||||
},
|
||||
{
|
||||
"address": "10.10.10.56",
|
||||
"broadcast": "10.10.10.63",
|
||||
"netmask": "255.255.255.192",
|
||||
},
|
||||
],
|
||||
"up": True,
|
||||
},
|
||||
"em1": {"hwaddr": "00:30:48:aa:aa:aa", "up": False},
|
||||
"lo0": {
|
||||
"inet": [{"address": "127.0.0.1", "netmask": "255.0.0.0"}],
|
||||
"inet6": [
|
||||
{"address": "fe80::1", "prefixlen": "64", "scope": "0x8"},
|
||||
{"address": "::1", "prefixlen": "128", "scope": None},
|
||||
],
|
||||
"up": True,
|
||||
},
|
||||
"plip0": {"up": False},
|
||||
"tun0": {
|
||||
"inet": [{"address": "10.12.0.1", "netmask": "255.255.255.255"}],
|
||||
"up": True,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_sanitize_host_ip():
|
||||
ret = network.sanitize_host("10.1./2.$3")
|
||||
assert ret == "10.1.2.3"
|
||||
|
@ -487,70 +553,14 @@ def test_hex2ip():
|
|||
)
|
||||
|
||||
|
||||
def test_interfaces_ifconfig_linux():
|
||||
def test_interfaces_ifconfig_linux(linux_interfaces_dict):
|
||||
interfaces = network._interfaces_ifconfig(LINUX)
|
||||
assert interfaces == {
|
||||
"eth0": {
|
||||
"hwaddr": "e0:3f:49:85:6a:af",
|
||||
"inet": [
|
||||
{
|
||||
"address": "10.10.10.56",
|
||||
"broadcast": "10.10.10.255",
|
||||
"netmask": "255.255.252.0",
|
||||
}
|
||||
],
|
||||
"inet6": [
|
||||
{
|
||||
"address": "fe80::e23f:49ff:fe85:6aaf",
|
||||
"prefixlen": "64",
|
||||
"scope": "link",
|
||||
}
|
||||
],
|
||||
"up": True,
|
||||
},
|
||||
"lo": {
|
||||
"inet": [{"address": "127.0.0.1", "netmask": "255.0.0.0"}],
|
||||
"inet6": [{"address": "::1", "prefixlen": "128", "scope": "host"}],
|
||||
"up": True,
|
||||
},
|
||||
}
|
||||
assert interfaces == linux_interfaces_dict
|
||||
|
||||
|
||||
def test_interfaces_ifconfig_freebsd():
|
||||
def test_interfaces_ifconfig_freebsd(freebsd_interfaces_dict):
|
||||
interfaces = network._interfaces_ifconfig(FREEBSD)
|
||||
assert interfaces == {
|
||||
"": {"up": False},
|
||||
"em0": {
|
||||
"hwaddr": "00:30:48:ff:ff:ff",
|
||||
"inet": [
|
||||
{
|
||||
"address": "10.10.10.250",
|
||||
"broadcast": "10.10.10.255",
|
||||
"netmask": "255.255.255.224",
|
||||
},
|
||||
{
|
||||
"address": "10.10.10.56",
|
||||
"broadcast": "10.10.10.63",
|
||||
"netmask": "255.255.255.192",
|
||||
},
|
||||
],
|
||||
"up": True,
|
||||
},
|
||||
"em1": {"hwaddr": "00:30:48:aa:aa:aa", "up": False},
|
||||
"lo0": {
|
||||
"inet": [{"address": "127.0.0.1", "netmask": "255.0.0.0"}],
|
||||
"inet6": [
|
||||
{"address": "fe80::1", "prefixlen": "64", "scope": "0x8"},
|
||||
{"address": "::1", "prefixlen": "128", "scope": None},
|
||||
],
|
||||
"up": True,
|
||||
},
|
||||
"plip0": {"up": False},
|
||||
"tun0": {
|
||||
"inet": [{"address": "10.12.0.1", "netmask": "255.255.255.255"}],
|
||||
"up": True,
|
||||
},
|
||||
}
|
||||
assert interfaces == freebsd_interfaces_dict
|
||||
|
||||
|
||||
def test_interfaces_ifconfig_solaris():
|
||||
|
@ -1412,3 +1422,104 @@ def test_natural_ipv4_netmask():
|
|||
|
||||
ret = network.natural_ipv4_netmask("10.10.10.250", fmt="netmask")
|
||||
assert ret == "255.0.0.0"
|
||||
|
||||
|
||||
def test_rpad_ipv4_network():
|
||||
ret = network.rpad_ipv4_network("127.0")
|
||||
assert ret == "127.0.0.0"
|
||||
ret = network.rpad_ipv4_network("192.168.3")
|
||||
assert ret == "192.168.3.0"
|
||||
ret = network.rpad_ipv4_network("10.209")
|
||||
assert ret == "10.209.0.0"
|
||||
|
||||
|
||||
def test_hw_addr(linux_interfaces_dict, freebsd_interfaces_dict):
|
||||
|
||||
with patch(
|
||||
"salt.utils.network.linux_interfaces",
|
||||
MagicMock(return_value=linux_interfaces_dict),
|
||||
):
|
||||
hw_addrs = network.hw_addr("eth0")
|
||||
assert hw_addrs == "e0:3f:49:85:6a:af"
|
||||
|
||||
with patch(
|
||||
"salt.utils.network.interfaces", MagicMock(return_value=freebsd_interfaces_dict)
|
||||
), patch("salt.utils.platform.is_netbsd", MagicMock(return_value=True)):
|
||||
hw_addrs = network.hw_addr("em0")
|
||||
assert hw_addrs == "00:30:48:ff:ff:ff"
|
||||
|
||||
hw_addrs = network.hw_addr("em1")
|
||||
assert hw_addrs == "00:30:48:aa:aa:aa"
|
||||
|
||||
hw_addrs = network.hw_addr("dog")
|
||||
assert (
|
||||
hw_addrs
|
||||
== 'Interface "dog" not in available interfaces: "", "em0", "em1", "lo0", "plip0", "tun0"'
|
||||
)
|
||||
|
||||
|
||||
def test_interface_and_ip(linux_interfaces_dict):
|
||||
|
||||
with patch(
|
||||
"salt.utils.network.linux_interfaces",
|
||||
MagicMock(return_value=linux_interfaces_dict),
|
||||
):
|
||||
ret = network.interface("eth0")
|
||||
assert ret == [
|
||||
{
|
||||
"address": "10.10.10.56",
|
||||
"broadcast": "10.10.10.255",
|
||||
"netmask": "255.255.252.0",
|
||||
}
|
||||
]
|
||||
|
||||
ret = network.interface("dog")
|
||||
assert ret == 'Interface "dog" not in available interfaces: "eth0", "lo"'
|
||||
|
||||
ret = network.interface_ip("eth0")
|
||||
assert ret == "10.10.10.56"
|
||||
|
||||
ret = network.interface_ip("dog")
|
||||
assert ret == 'Interface "dog" not in available interfaces: "eth0", "lo"'
|
||||
|
||||
|
||||
def test_subnets(linux_interfaces_dict):
|
||||
|
||||
with patch(
|
||||
"salt.utils.network.linux_interfaces",
|
||||
MagicMock(return_value=linux_interfaces_dict),
|
||||
):
|
||||
ret = network.subnets()
|
||||
assert ret == ["10.10.8.0/22"]
|
||||
|
||||
ret = network.subnets6()
|
||||
assert ret == ["fe80::/64"]
|
||||
|
||||
|
||||
def test_in_subnet(caplog):
|
||||
assert network.in_subnet("fe80::/64", "fe80::e23f:49ff:fe85:6aaf")
|
||||
|
||||
assert network.in_subnet("10.10.8.0/22", "10.10.10.56")
|
||||
|
||||
assert not network.in_subnet("10.10.8.0/22")
|
||||
|
||||
caplog.clear()
|
||||
ret = network.in_subnet("10.10.8.0/40")
|
||||
assert "Invalid CIDR '10.10.8.0/40'" in caplog.text
|
||||
assert not ret
|
||||
|
||||
|
||||
def test_ip_addrs(linux_interfaces_dict):
|
||||
with patch(
|
||||
"salt.utils.network.linux_interfaces",
|
||||
MagicMock(return_value=linux_interfaces_dict),
|
||||
):
|
||||
ret = network.ip_addrs("eth0")
|
||||
assert ret == ["10.10.10.56"]
|
||||
|
||||
with patch(
|
||||
"salt.utils.network.linux_interfaces",
|
||||
MagicMock(return_value=linux_interfaces_dict),
|
||||
):
|
||||
ret = network.ip_addrs6("eth0")
|
||||
assert ret == ["fe80::e23f:49ff:fe85:6aaf"]
|
||||
|
|
Loading…
Add table
Reference in a new issue