1
0
mirror of https://github.com/home-assistant/operating-system.git synced 2025-12-20 02:18:37 +00:00
Files
operating-system/tests/smoke_test/test_basic.py
Jan Čermák 3e36628c09 Create foundation for Labgrid-based OS tests (#2812)
* Create foundation for Labgrid-based OS tests

Add foundation for Labgrid-based tests of OS builds. Currently uses just
the QEMU driver, which starts a virtual machine with pristine OS, and
generates few log reports which are saved as build artifacts.

Workflow is currently triggered either manually by specifying an OS
version, or by OS build job, which now saves an artifact of the OVA
image. This allows for some modularity. If we eventually add the
possibility to run builds on PRs, we could also add the workflow_call
trigger and turn the workflow into a reusable one.

TBD (in future PRs): some meaningful tests and possibility to test on
real hardware (either local or distributed).

* Apply suggestions from @agners

Co-authored-by: Stefan Agner <stefan@agner.ch>

* Wrap test command in a script, create venv for local tests

* Make shellcheck happy

---------

Co-authored-by: Stefan Agner <stefan@agner.ch>
2023-10-17 18:23:29 +02:00

49 lines
1.3 KiB
Python

import logging
from time import sleep
_LOGGER = logging.getLogger(__name__)
def test_init(shell_command):
def check_container_running(container_name):
out = shell_command.run_check(
f"docker container inspect -f '{{{{.State.Status}}}}' {container_name} || true"
)
return "running" in out
# wait for important containers first
for _ in range(20):
if check_container_running("homeassistant") and check_container_running("hassio_supervisor"):
break
sleep(5)
# wait for system ready
for _ in range(20):
output = "\n".join(shell_command.run_check("ha os info || true"))
if "System is not ready" not in output:
break
sleep(5)
output = shell_command.run_check("ha os info")
_LOGGER.info("%s", "\n".join(output))
def test_dmesg(shell_command):
output = shell_command.run_check("dmesg")
_LOGGER.info("%s", "\n".join(output))
def test_supervisor_logs(shell_command):
output = shell_command.run_check("ha su logs")
_LOGGER.info("%s", "\n".join(output))
def test_systemctl_status(shell_command):
output = shell_command.run_check(
"systemctl --no-pager -l status -a || true", timeout=90
)
_LOGGER.info("%s", "\n".join(output))