1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-25 04:46:25 +00:00

Use Journal Export Format for host (advanced) logs (#4963)

* Use Journal Export Format for host (advanced) logs

Add methods for handling Journal Export Format and use it for fetching
of host logs. This is foundation for colored streaming logs for other
endpoints as well.

* Make pylint happier - remove extra pass statement

* Rewrite journal gateway tests to mock ClientResponse's StreamReader

* Handle connection refused error when connecting to journal-gatewayd

* Use SYSTEMD_JOURNAL_GATEWAYD_SOCKET global path also for connection

* Use parsing algorithm suggested by @agners in review

* Fix timestamps in formatting, always use UTC for now

* Add tests for Accept header in host logs

* Apply suggestions from @agners

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

* Bail out of parsing earlier if field is not in required fields

* Fix parsing issue discovered in the wild and add test case

* Make verbose formatter more tolerant

* Use some bytes' native functions for some minor optimizations

* Move MalformedBinaryEntryError to exceptions module, add test for it

---------

Co-authored-by: Stefan Agner <stefan@agner.ch>
This commit is contained in:
Jan Čermák
2024-03-20 09:00:45 +01:00
committed by GitHub
parent 0e0fadd72d
commit 0814552b2a
12 changed files with 519 additions and 41 deletions

View File

@@ -1,4 +1,5 @@
"""Common test functions."""
import asyncio
from functools import partial
from inspect import unwrap
import os
@@ -47,12 +48,7 @@ from supervisor.store.addon import AddonStore
from supervisor.store.repository import Repository
from supervisor.utils.dt import utcnow
from .common import (
load_binary_fixture,
load_fixture,
load_json_fixture,
mock_dbus_services,
)
from .common import load_binary_fixture, load_json_fixture, mock_dbus_services
from .const import TEST_ADDON_SLUG
from .dbus_service_mocks.base import DBusServiceMock
from .dbus_service_mocks.network_connection_settings import (
@@ -408,10 +404,28 @@ async def journald_gateway() -> MagicMock:
with patch("supervisor.host.logs.Path.is_socket", return_value=True), patch(
"supervisor.host.logs.ClientSession.get"
) as get:
get.return_value.__aenter__.return_value.text = AsyncMock(
return_value=load_fixture("logs_host.txt")
reader = asyncio.StreamReader(loop=asyncio.get_running_loop())
async def response_text():
return (await reader.read()).decode("utf-8")
client_response = MagicMock(
content=reader,
text=response_text,
)
yield get
get.return_value.__aenter__.return_value = client_response
get.return_value.__aenter__.return_value.__aenter__.return_value = (
client_response
)
yield reader
@pytest.fixture
async def journal_logs_reader() -> MagicMock:
"""Mock journal_logs_reader in host API."""
with patch("supervisor.api.host.journal_logs_reader") as reader:
yield reader
@pytest.fixture