mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Make all network unit tests run on Windows
This commit is contained in:
parent
8b16003cab
commit
cae94bca24
1 changed files with 23 additions and 18 deletions
|
@ -7,6 +7,7 @@ import pytest
|
|||
import salt.exceptions
|
||||
import salt.utils.network
|
||||
import salt.utils.network as network
|
||||
import salt.utils.platform
|
||||
from salt._compat import ipaddress
|
||||
from tests.support.mock import MagicMock, create_autospec, mock_open, patch
|
||||
|
||||
|
@ -1430,9 +1431,12 @@ def test_isportopen_false():
|
|||
assert ret is False
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows(reason="Do not run on Windows")
|
||||
def test_isportopen():
|
||||
ret = network.isportopen("127.0.0.1", "22")
|
||||
if salt.utils.platform.is_windows():
|
||||
port = "135"
|
||||
else:
|
||||
port = "22"
|
||||
ret = network.isportopen("127.0.0.1", port)
|
||||
assert ret == 0
|
||||
|
||||
|
||||
|
@ -1446,14 +1450,19 @@ def test_get_socket():
|
|||
assert ret.type == socket.SOCK_STREAM
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows(reason="Do not run on Windows")
|
||||
# @pytest.mark.skip_on_windows(reason="Do not run on Windows")
|
||||
def test_ip_to_host(grains):
|
||||
if salt.utils.platform.is_windows():
|
||||
hostname = socket.gethostname()
|
||||
else:
|
||||
hostname = "localhost"
|
||||
|
||||
ret = network.ip_to_host("127.0.0.1")
|
||||
if grains["oscodename"] == "Photon":
|
||||
if grains.get("oscodename") == "Photon":
|
||||
# Photon returns this for IPv4
|
||||
assert ret == "ipv6-localhost"
|
||||
else:
|
||||
assert ret == "localhost"
|
||||
assert ret == hostname
|
||||
|
||||
ret = network.ip_to_host("2001:a71::1")
|
||||
assert ret is None
|
||||
|
@ -1463,22 +1472,22 @@ def test_ip_to_host(grains):
|
|||
assert ret == "localhost6"
|
||||
elif grains["os_family"] == "Debian":
|
||||
if grains["osmajorrelease"] == 12:
|
||||
assert ret == "localhost"
|
||||
assert ret == hostname
|
||||
else:
|
||||
assert ret == "ip6-localhost"
|
||||
elif grains["os_family"] == "RedHat":
|
||||
if grains["oscodename"] == "Photon":
|
||||
assert ret == "ipv6-localhost"
|
||||
else:
|
||||
assert ret == "localhost"
|
||||
assert ret == hostname
|
||||
elif grains["os_family"] == "Arch":
|
||||
if grains.get("osmajorrelease", None) is None:
|
||||
# running doesn't have osmajorrelease grains
|
||||
assert ret == "localhost"
|
||||
assert ret == hostname
|
||||
else:
|
||||
assert ret == "ip6-localhost"
|
||||
else:
|
||||
assert ret == "localhost"
|
||||
assert ret == hostname
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -1508,11 +1517,10 @@ def test_rpad_ipv4_network(addr, expected):
|
|||
assert network.rpad_ipv4_network(addr) == expected
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows(reason="Do not run on Windows")
|
||||
def test_hw_addr(linux_interfaces_dict, freebsd_interfaces_dict):
|
||||
|
||||
with patch(
|
||||
"salt.utils.network.linux_interfaces",
|
||||
"salt.utils.network.interfaces",
|
||||
MagicMock(return_value=linux_interfaces_dict),
|
||||
):
|
||||
hw_addrs = network.hw_addr("eth0")
|
||||
|
@ -1534,11 +1542,10 @@ def test_hw_addr(linux_interfaces_dict, freebsd_interfaces_dict):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows(reason="Do not run on Windows")
|
||||
def test_interface_and_ip(linux_interfaces_dict):
|
||||
|
||||
with patch(
|
||||
"salt.utils.network.linux_interfaces",
|
||||
"salt.utils.network.interfaces",
|
||||
MagicMock(return_value=linux_interfaces_dict),
|
||||
):
|
||||
expected = [
|
||||
|
@ -1561,11 +1568,10 @@ def test_interface_and_ip(linux_interfaces_dict):
|
|||
assert ret == 'Interface "dog" not in available interfaces: "eth0", "lo"'
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows(reason="Do not run on Windows")
|
||||
def test_subnets(linux_interfaces_dict):
|
||||
|
||||
with patch(
|
||||
"salt.utils.network.linux_interfaces",
|
||||
"salt.utils.network.interfaces",
|
||||
MagicMock(return_value=linux_interfaces_dict),
|
||||
):
|
||||
ret = network.subnets()
|
||||
|
@ -1586,17 +1592,16 @@ def test_in_subnet(caplog):
|
|||
assert not ret
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows(reason="Do not run on Windows")
|
||||
def test_ip_addrs(linux_interfaces_dict):
|
||||
with patch(
|
||||
"salt.utils.network.linux_interfaces",
|
||||
"salt.utils.network.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",
|
||||
"salt.utils.network.interfaces",
|
||||
MagicMock(return_value=linux_interfaces_dict),
|
||||
):
|
||||
ret = network.ip_addrs6("eth0")
|
||||
|
|
Loading…
Add table
Reference in a new issue