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

tests: wait for container boot or network on container spawn

This is causing issues because containers in some cases are not starting
fast enough. We should always make sure that container is prepared for
tests and for exactly that purpose wait scripts available.
parent 089093f1
......@@ -154,6 +154,7 @@ def fixture_isp_container(lxd, device_map):
"""Minimal ISP container used to provide the Internet access for the most of the tests.
"""
with nsfarm.lxd.Container(lxd, 'isp-common', device_map) as container:
nsfarm.cli.Shell(container.pexpect()).run('wait4network')
yield container
......@@ -162,6 +163,7 @@ def fixture_lan1_client(lxd, device_map):
"""Starts client container on LAN1 and provides it.
"""
with nsfarm.lxd.Container(lxd, 'client', {"net:lan": device_map["net:lan1"]}) as container:
nsfarm.cli.Shell(container.pexpect()).run('wait4boot')
yield container
......
......@@ -21,7 +21,7 @@ class TestStatic(common.InternetTests):
"""Configure WAN to use static IP
"""
print("We are in client fixture once")
with nsfarm.lxd.Container(lxd, 'isp-common', device_map):
with nsfarm.lxd.Container(lxd, 'isp-common', device_map) as container:
# 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'")
......@@ -29,6 +29,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='172.16.1.1'")
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
......@@ -50,9 +51,10 @@ class TestDHCP(common.InternetTests):
def client(self, lxd, device_map, board, client_board):
"""Configure WAN to use DHCP
"""
with nsfarm.lxd.Container(lxd, 'isp-dhcp', device_map):
with nsfarm.lxd.Container(lxd, 'isp-dhcp', device_map) as container:
client_board.run("uci set network.wan.proto='dhcp'")
client_board.run("uci commit network")
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
......
......@@ -25,6 +25,7 @@ def fixture_attacker_container(lxd, device_map):
intentional as this way we won't poison data that much even if we send them to Sentinel network.
"""
with Container(lxd, 'attacker', device_map) as container:
Shell(container.pexpect()).run('wait4boot')
yield container
......
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