1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 20:35:55 +00:00

Use journal-gatewayd's new /boots endpoint to list boots (#5914)

* Use journal-gatewayd's new /boots endpoint to list boots

Current method we use for getting boots has several known downsides, for
example it can miss some incomplete boots and the performance might be
worse than what we could get by using Systemd directly. Systemd was
missing a method to get list boots through the journal-gatewayd but that
should be addressed by the new /boots endpoint added in [1] which
returns application/json-seq response containing all boots as reported
in `journalctl --list-boots`.

Implement Supervisor methods to parse this format and use the endpoint
at first, falling back to the old method if it fails.

[1] https://github.com/systemd/systemd/pull/37574

* Log info instead of warning when /boots is not present

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

* Split records only by RS instead of LF in journal_boots_reader

* Strip only RS, json.loads is fine with whitespace

---------

Co-authored-by: Stefan Agner <stefan@agner.ch>
This commit is contained in:
Jan Čermák
2025-05-29 11:41:23 +02:00
committed by GitHub
parent 705e76abe3
commit 4d1a5e2dc2
7 changed files with 201 additions and 14 deletions

View File

@@ -47,6 +47,7 @@ from supervisor.coresys import CoreSys
from supervisor.dbus.network import NetworkManager
from supervisor.docker.manager import DockerAPI
from supervisor.docker.monitor import DockerMonitor
from supervisor.exceptions import HostLogError
from supervisor.homeassistant.api import APIState
from supervisor.host.logs import LogsControl
from supervisor.os.manager import OSManager
@@ -463,6 +464,7 @@ async def journald_gateway() -> AsyncGenerator[MagicMock]:
return (await client_response.content.read()).decode("utf-8")
client_response.text = response_text
client_response.status = 200
get.return_value.__aenter__.return_value = client_response
get.return_value.__aenter__.return_value.__aenter__.return_value = (
@@ -471,6 +473,20 @@ async def journald_gateway() -> AsyncGenerator[MagicMock]:
yield client_response
@pytest.fixture
async def without_journal_gatewayd_boots() -> AsyncGenerator[MagicMock]:
"""Make method using /boots of systemd-journald-gateway fail."""
def raise_host_log_error_side_effect(*args, **kwargs):
raise HostLogError("Mocked error")
with patch(
"supervisor.host.logs.LogsControl._get_boot_ids_native"
) as get_boot_ids_native:
get_boot_ids_native.side_effect = raise_host_log_error_side_effect
yield get_boot_ids_native
@pytest.fixture
async def journal_logs_reader() -> MagicMock:
"""Mock journal_logs_reader in host API."""