From 349b7e48ea64140af96f2baa10da65e92035d486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Mon, 7 Apr 2025 16:13:11 +0200 Subject: [PATCH] Add tests for checking connectivity, fix Supervisor update test (#4008) When there's a problem with connectivity, it may result in obscure errors later in the testing. Add checks testing three scenarions: * connectivity in host - both using curl and nmcli * connectivity in Supervisor container (uses docker0 as default via) * connectivity in CLI container (uses hassio as default via) Also make sure that Supervisor upgrade isn't attempted when the version information is missing. --- tests/smoke_test/test_basic.py | 23 +++++++++++++++++++++++ tests/supervisor_test/test_supervisor.py | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/smoke_test/test_basic.py b/tests/smoke_test/test_basic.py index ce73f677f..b25d422a2 100644 --- a/tests/smoke_test/test_basic.py +++ b/tests/smoke_test/test_basic.py @@ -87,6 +87,29 @@ def test_systemctl_no_cycles(shell): assert not output, f"Found Systemd dependency cycles:\n{"\n".join(output)}" +def test_host_connectivity(shell): + output = shell.run_check("curl -f https://checkonline.home-assistant.io/online.txt") + assert "NetworkManager is online" in output + output = shell.run_check("nmcli network connectivity check") + assert "full" in output, f"Connectivity check failed, nmcli reports: {output}" + + +@pytest.mark.dependency(depends=["test_init"]) +@pytest.mark.timeout(10) +def test_supervisor_connectivity(shell): + # checks URL used by connectivity checks via docker0 bridge + output = shell.run_check("docker exec -ti hassio_supervisor curl -f https://checkonline.home-assistant.io/online.txt") + assert "NetworkManager is online" in output + + +@pytest.mark.dependency(depends=["test_init"]) +@pytest.mark.timeout(10) +def test_hassio_connectivity(shell): + # checks URL used by connectivity checks via hassio bridge + output = shell.run_check("docker exec -ti hassio_cli curl -f https://checkonline.home-assistant.io/online.txt") + assert "NetworkManager is online" in output + + @pytest.mark.dependency(depends=["test_init"]) def test_custom_swap_size(shell, target): output = shell.run_check("stat -c '%s' /mnt/data/swapfile") diff --git a/tests/supervisor_test/test_supervisor.py b/tests/supervisor_test/test_supervisor.py index d8f4c4b56..2b8bc1b2a 100644 --- a/tests/supervisor_test/test_supervisor.py +++ b/tests/supervisor_test/test_supervisor.py @@ -59,7 +59,9 @@ def test_check_supervisor(shell_json): def test_update_supervisor(shell_json): supervisor_info = shell_json("ha supervisor info --no-progress --raw-json") supervisor_version = supervisor_info.get("data").get("version") - if supervisor_version == supervisor_info.get("data").get("version_latest"): + supervisor_version_latest = supervisor_info.get("data").get("version_latest") + assert supervisor_version_latest, "Missing latest supervisor version info" + if supervisor_version == supervisor_version_latest: logger.info("Supervisor is already up to date") pytest.skip("Supervisor is already up to date") else: