Skip to content
Snippets Groups Projects
Verified Commit 4eb0f0f3 authored by Karel Koci's avatar Karel Koci :metal:
Browse files

tests/network: add tests of internet connection for LAN

This reuses WAN tests for LAN as well to check that clients are able to
access internet trough router.
parent c7dda52d
Branches
1 merge request!2Initial development
......@@ -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
"""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())
......@@ -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")
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment