mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-24 03:43:53 +03:00
nixos/tests/home-assistant: improve reload/restart test cases
Wait until home-assistant is fully reloaded or restarted to spot possible errors during startup. Swap out bluetooth_tracker for esphome, since the bluetooth tracker causes errors, when it does not find a bluetooth device. Drop mosquitto from the environment. It wasn't used since the 2022.3.0 release when MQTT stopped being configurable from the YAML config.
This commit is contained in:
parent
9e0e2fdad0
commit
0ae92922a1
@ -7,8 +7,6 @@ in {
|
||||
meta.maintainers = lib.teams.home-assistant.members;
|
||||
|
||||
nodes.hass = { pkgs, ... }: {
|
||||
environment.systemPackages = with pkgs; [ mosquitto ];
|
||||
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = [ "hass" ];
|
||||
@ -108,9 +106,7 @@ in {
|
||||
# Cause a configuration change that requires a service restart as we added a new runtime dependency
|
||||
specialisation.newFeature = {
|
||||
inheritParentConfig = true;
|
||||
configuration.services.home-assistant.config.device_tracker = [
|
||||
{ platform = "bluetooth_tracker"; }
|
||||
];
|
||||
configuration.services.home-assistant.config.esphome = {};
|
||||
};
|
||||
};
|
||||
|
||||
@ -119,6 +115,7 @@ in {
|
||||
in
|
||||
''
|
||||
import re
|
||||
import json
|
||||
|
||||
start_all()
|
||||
|
||||
@ -131,7 +128,19 @@ in {
|
||||
assert match
|
||||
package = match.group('path')
|
||||
|
||||
|
||||
def get_journal_cursor(host) -> str:
|
||||
exit, out = host.execute("journalctl -u home-assistant.service -n1 -o json-pretty --output-fields=__CURSOR")
|
||||
assert exit == 0
|
||||
return json.loads(out)["__CURSOR"]
|
||||
|
||||
|
||||
def wait_for_homeassistant(host, cursor):
|
||||
host.wait_until_succeeds(f"journalctl --after-cursor='{cursor}' -u home-assistant.service | grep -q 'Home Assistant initialized in'")
|
||||
|
||||
|
||||
hass.wait_for_unit("home-assistant.service")
|
||||
cursor = get_journal_cursor(hass)
|
||||
|
||||
with subtest("Check that YAML configuration file is in place"):
|
||||
hass.succeed("test -L ${configDir}/configuration.yaml")
|
||||
@ -148,7 +157,7 @@ in {
|
||||
hass.succeed(f"grep -q 'wake_on_lan' {package}/extra_components")
|
||||
|
||||
with subtest("Check that Home Assistant's web interface and API can be reached"):
|
||||
hass.wait_until_succeeds("journalctl -u home-assistant.service | grep -q 'Home Assistant initialized in'")
|
||||
wait_for_homeassistant(hass, cursor)
|
||||
hass.wait_for_open_port(8123)
|
||||
hass.succeed("curl --fail http://localhost:8123/lovelace")
|
||||
|
||||
@ -162,15 +171,19 @@ in {
|
||||
with subtest("Check service reloads when configuration changes"):
|
||||
# store the old pid of the process
|
||||
pid = hass.succeed("systemctl show --property=MainPID home-assistant.service")
|
||||
cursor = get_journal_cursor(hass)
|
||||
hass.succeed("${system}/specialisation/differentName/bin/switch-to-configuration test")
|
||||
new_pid = hass.succeed("systemctl show --property=MainPID home-assistant.service")
|
||||
assert pid == new_pid, "The PID of the process should not change between process reloads"
|
||||
wait_for_homeassistant(hass, cursor)
|
||||
|
||||
with subtest("check service restarts when package changes"):
|
||||
pid = new_pid
|
||||
cursor = get_journal_cursor(hass)
|
||||
hass.succeed("${system}/specialisation/newFeature/bin/switch-to-configuration test")
|
||||
new_pid = hass.succeed("systemctl show --property=MainPID home-assistant.service")
|
||||
assert pid != new_pid, "The PID of the process shoudl change when the HA binary changes"
|
||||
wait_for_homeassistant(hass, cursor)
|
||||
|
||||
with subtest("Check that no errors were logged"):
|
||||
output_log = hass.succeed("cat ${configDir}/home-assistant.log")
|
||||
|
Loading…
Reference in New Issue
Block a user