diff --git a/tests/network/common.py b/tests/network/common.py index bca8fae6e1bb80257818146752469a52066c16d5..3559c2cb1ccdfa80399efcd81c01ae61a7e4791c 100644 --- a/tests/network/common.py +++ b/tests/network/common.py @@ -17,21 +17,21 @@ class InternetTests: "turris.cz", "google.com" ]) - def test_ping(self, client_board, server): + def test_ping(self, client, server): """Ping various IPv4 servers. We send only one ICMP packet to not flood and to be quickly done with it (the success takes less than second) """ - client_board.run("ping -c 1 '{}'".format(server)) + client.run("ping -c 1 '{}'".format(server)) @pytest.mark.parametrize("server", [ "nic.cz", "turris.cz", "google.com" ]) - def test_dns(self, client_board, server): + def test_dns(self, client, server): """Try to resolve verious domain names. """ - client_board.run("nslookup '{}'".format(server)) + client.run("nslookup '{}'".format(server)) # TODO more excessive DNS testing diff --git a/tests/network/test_lan.py b/tests/network/test_lan.py new file mode 100644 index 0000000000000000000000000000000000000000..cf28dcdca55baa1f3cef63e2641d7371c5697d29 --- /dev/null +++ b/tests/network/test_lan.py @@ -0,0 +1,25 @@ +"""Test LAN access of Internet and software on LAN side. +""" +import time +import pytest +import nsfarm.lxd +from . import common +# pylint: disable=no-self-use + + +def _apply(client_board): + client_board.run("uci commit network") + client_board.run("/etc/init.d/network restart") + time.sleep(5) # TODO drop this as this is just to prevent problems with kernel log in console + client_board.run("while ! ip route | grep -q default; do sleep 1; done") # Wait for default route + + +class TestInternet(common.InternetTests): + """Test WAN with network settings configured statically. + """ + + @pytest.fixture(scope="class", autouse=True) + def client(self, basic_isp, lan1_client): + """With basic router config and client is client container. + """ + yield nsfarm.cli.Shell(lan1_client.pexpect()) diff --git a/tests/network/test_wan.py b/tests/network/test_wan.py index da09fb660fdf2ef97ececa7c6602664a644104a4..8c7292a5ea2f7fde6fe1e358e6fc0784a6683238 100644 --- a/tests/network/test_wan.py +++ b/tests/network/test_wan.py @@ -22,10 +22,11 @@ class TestStatic(common.InternetTests): """ @pytest.fixture(scope="class", autouse=True) - def configure(self, client_board, wan): + def client(self, client_board, wan): """Configure WAN to use static IP """ - with nsfarm.lxd.Container('isp-common', devices=[wan, ]) as container: + print("We are in client fixture once") + with nsfarm.lxd.Container('isp-common', devices=[wan, ]): # TODO implement some utility class to set and revert uci configs on router client_board.run("uci set network.wan.proto='static'") client_board.run("uci set network.wan.ipaddr='172.16.1.42'") @@ -33,7 +34,7 @@ class TestStatic(common.InternetTests): client_board.run("uci set network.wan.gateway='172.16.1.1'") client_board.run("uci set network.wan.dns='1.1.1.1'") # TODO configure to ISP _apply(client_board) - yield container + yield client_board client_board.run("uci set network.wan.proto='none'") client_board.run("uci delete network.wan.ipaddr") client_board.run("uci delete network.wan.netmask") @@ -47,13 +48,13 @@ class TestDHCP(common.InternetTests): """ @pytest.fixture(scope="class", autouse=True) - def configure(self, board, client_board, wan): + def client(self, board, client_board, wan): """Configure WAN to use DHCP """ - with nsfarm.lxd.Container('isp-dhcp', devices=[wan, ]) as container: + with nsfarm.lxd.Container('isp-dhcp', devices=[wan, ]): client_board.run("uci set network.wan.proto='dhcp'") client_board.run("uci commit network") _apply(client_board) - yield container + yield client_board client_board.run("uci set network.wan.proto='none'") client_board.run("uci commit network")