Verified Commit cae250c2 authored by Karel Koci's avatar Karel Koci 🤘
Browse files

tests: use ping instead of sleep to check for network readiness

There is an issue that although software reports interface being up a
few initial frames won't pass. The original "fix" for it was to just
wait a moment but that brakes depending on hardware we are running tests
on. Although it is not ideal we instead use ping. Pinging our gateway
that is our ISP container should be enough to make sure that connection
is established.
At the same time this is not in any way required for DHCP. The reason is
because to get IP address we have to communicate with ISP and thus
connection is established for sure. This means that any sleep is nor any
other wait is required there.
parent 734abfcd
......@@ -171,7 +171,7 @@ def fixture_lan1_client(lxd, device_map):
# Standard configuration ###############################################################################################
@pytest.fixture(name="board_wan", scope="module")
def fixture_board_wan(board, client_board, isp_container):
def fixture_board_wan(client_board, isp_container):
"""Basic config Internet configuration usable for most of the tests.
This configures static IP through ips_container.
Returns wan IPv4 address of WAN interface.
......@@ -184,8 +184,7 @@ def fixture_board_wan(board, client_board, isp_container):
client_board.run("uci set network.wan.dns='172.16.1.1'")
client_board.run("uci commit network")
client_board.run("/etc/init.d/network restart")
client_board.run(f"while ! ip link show {board.wan} | grep -q ' state UP '; do sleep 1; done")
time.sleep(3) # Wait just a bit to ensure that network is up and running
client_board.run("while ! ping -c1 -w1 172.16.1.1 >/dev/null; do true; done")
yield wan_ip
client_board.run("uci set network.wan.proto='none'")
client_board.run("uci delete network.wan.ipaddr")
......
......@@ -17,7 +17,7 @@ class TestStatic(common.InternetTests):
"""
@pytest.fixture(scope="class", autouse=True)
def client(self, lxd, device_map, board, client_board):
def client(self, lxd, device_map, client_board):
"""Configure WAN to use static IP
"""
print("We are in client fixture once")
......@@ -31,8 +31,7 @@ class TestStatic(common.InternetTests):
client_board.run("uci commit network")
nsfarm.cli.Shell(container.pexpect()).run('wait4network')
client_board.run("/etc/init.d/network restart")
client_board.run(f"while ! ip link show {board.wan} | grep -q ' state UP '; do sleep 1; done")
time.sleep(3) # Wait just a bit to ensure that network is up and running
client_board.run("while ! ping -c1 -w1 172.16.1.1 >/dev/null; do true; done")
yield client_board
client_board.run("uci set network.wan.proto='none'")
client_board.run("uci delete network.wan.ipaddr")
......@@ -57,7 +56,6 @@ class TestDHCP(common.InternetTests):
nsfarm.cli.Shell(container.pexpect()).run('wait4network')
client_board.run("/etc/init.d/network restart")
client_board.run("while ! ip route | grep -q default; do sleep 1; done")
time.sleep(1) # Wait just a bit to ensure that network is up and running
yield client_board
client_board.run("uci set network.wan.proto='none'")
client_board.run("uci commit network")
Supports Markdown
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