From cc9a931baa8c41cab959730c0c33f490c20d4f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Wed, 16 Oct 2024 09:04:24 +0200 Subject: [PATCH] Fix Supervisor log fallback for the /follow endpoint (#5354) When an error occurs when streaming Supervisor logs, the fallback method receives the follow kwarg as well, which is invalid for the Docker log handler: TypeError: APISupervisor.logs() got an unexpected keyword argument 'follow' The exception is still printed to the logs but with all the extra noise caused by this error. Removing the argument makes the stack trace more comprehensible and the fallback actually works as desired. --- supervisor/api/__init__.py | 1 + tests/api/test_supervisor.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/supervisor/api/__init__.py b/supervisor/api/__init__.py index 3b2938482..f71e028f9 100644 --- a/supervisor/api/__init__.py +++ b/supervisor/api/__init__.py @@ -413,6 +413,7 @@ class RestAPI(CoreSysAttributes): # No need to capture HostNotSupportedError to Sentry, the cause # is known and reported to the user using the resolution center. capture_exception(err) + kwargs.pop("follow", None) # Follow is not supported for Docker logs return await api_supervisor.logs(*args, **kwargs) self.webapp.add_routes( diff --git a/tests/api/test_supervisor.py b/tests/api/test_supervisor.py index 4ec224708..06735137c 100644 --- a/tests/api/test_supervisor.py +++ b/tests/api/test_supervisor.py @@ -183,6 +183,17 @@ async def test_api_supervisor_fallback( b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", ] + # check fallback also works for the follow endpoint (no mock reset needed) + + with patch("supervisor.api._LOGGER.exception") as logger: + resp = await api_client.get("/supervisor/logs/follow") + logger.assert_called_once_with( + "Failed to get supervisor logs using advanced_logs API" + ) + + assert resp.status == 200 + assert resp.content_type == "text/plain" + journald_logs.reset_mock() # also check generic Python error