diff --git a/supervisor/api/const.py b/supervisor/api/const.py index ab7817e2b..01cee8f85 100644 --- a/supervisor/api/const.py +++ b/supervisor/api/const.py @@ -16,6 +16,7 @@ ATTR_APPARMOR_VERSION = "apparmor_version" ATTR_AGENT_VERSION = "agent_version" ATTR_AVAILABLE_UPDATES = "available_updates" ATTR_BOOT_TIMESTAMP = "boot_timestamp" +ATTR_BOOTS = "boots" ATTR_BROADCAST_LLMNR = "broadcast_llmnr" ATTR_BROADCAST_MDNS = "broadcast_mdns" ATTR_DATA_DISK = "data_disk" @@ -23,6 +24,7 @@ ATTR_DEVICE = "device" ATTR_DT_SYNCHRONIZED = "dt_synchronized" ATTR_DT_UTC = "dt_utc" ATTR_FALLBACK = "fallback" +ATTR_IDENTIFIERS = "identifiers" ATTR_LLMNR = "llmnr" ATTR_LLMNR_HOSTNAME = "llmnr_hostname" ATTR_MDNS = "mdns" diff --git a/supervisor/api/host.py b/supervisor/api/host.py index 59f51b900..60a39500b 100644 --- a/supervisor/api/host.py +++ b/supervisor/api/host.py @@ -33,10 +33,12 @@ from .const import ( ATTR_AGENT_VERSION, ATTR_APPARMOR_VERSION, ATTR_BOOT_TIMESTAMP, + ATTR_BOOTS, ATTR_BROADCAST_LLMNR, ATTR_BROADCAST_MDNS, ATTR_DT_SYNCHRONIZED, ATTR_DT_UTC, + ATTR_IDENTIFIERS, ATTR_LLMNR_HOSTNAME, ATTR_STARTUP_TIME, ATTR_USE_NTP, @@ -130,13 +132,16 @@ class APIHost(CoreSysAttributes): """Return a list of boot IDs.""" boot_ids = await self.sys_host.logs.get_boot_ids() return { - str(1 + i - len(boot_ids)): boot_id for i, boot_id in enumerate(boot_ids) + ATTR_BOOTS: { + str(1 + i - len(boot_ids)): boot_id + for i, boot_id in enumerate(boot_ids) + } } @api_process async def list_identifiers(self, _: web.Request): """Return a list of syslog identifiers.""" - return await self.sys_host.logs.get_identifiers() + return {ATTR_IDENTIFIERS: await self.sys_host.logs.get_identifiers()} async def _get_boot_id(self, possible_offset: str) -> str: """Convert offset into boot ID if required.""" diff --git a/supervisor/host/logs.py b/supervisor/host/logs.py index dbf84357e..d03cdab79 100644 --- a/supervisor/host/logs.py +++ b/supervisor/host/logs.py @@ -41,7 +41,6 @@ class LogsControl(CoreSysAttributes): self.coresys: CoreSys = coresys self._profiles: set[str] = set() self._boot_ids: list[str] = [] - self._identifiers: list[str] = [] self._default_identifiers: list[str] = [] @property @@ -54,11 +53,6 @@ class LogsControl(CoreSysAttributes): """Get boot IDs from oldest to newest.""" return self._boot_ids - @property - def identifiers(self) -> list[str]: - """Get syslog identifiers.""" - return self._identifiers - @property def default_identifiers(self) -> list[str]: """Get default syslog identifiers.""" @@ -120,7 +114,7 @@ class LogsControl(CoreSysAttributes): path=f"/fields/{PARAM_SYSLOG_IDENTIFIER}", timeout=ClientTimeout(total=20), ) as resp: - return (await resp.text()).split("\n") + return [i for i in (await resp.text()).split("\n") if i] except (ClientError, TimeoutError) as err: raise HostLogError( "Could not get a list of syslog identifiers from systemd-journal-gatewayd", diff --git a/tests/api/test_host.py b/tests/api/test_host.py index 0c1ddcf08..581fc3874 100644 --- a/tests/api/test_host.py +++ b/tests/api/test_host.py @@ -128,14 +128,16 @@ async def test_api_boot_ids_info(api_client: TestClient, journald_logs: MagicMoc """Test getting boot IDs.""" resp = await api_client.get("/host/logs/boots") result = await resp.json() - assert result["data"] == {"0": "ccc", "-1": "bbb", "-2": "aaa"} + assert result["data"] == {"boots": {"0": "ccc", "-1": "bbb", "-2": "aaa"}} async def test_api_identifiers_info(api_client: TestClient, journald_logs: MagicMock): """Test getting syslog identifiers.""" resp = await api_client.get("/host/logs/identifiers") result = await resp.json() - assert result["data"] == ["hassio_supervisor", "hassos-config", "kernel"] + assert result["data"] == { + "identifiers": ["hassio_supervisor", "hassos-config", "kernel"] + } async def test_advanced_logs( diff --git a/tests/fixtures/logs_identifiers.txt b/tests/fixtures/logs_identifiers.txt index eb2e1952b..a321d06ae 100644 --- a/tests/fixtures/logs_identifiers.txt +++ b/tests/fixtures/logs_identifiers.txt @@ -47,4 +47,4 @@ ghcr.io/home-assistant/odroid-n2-homeassistant:2022.10.0.dev20220919/homeassista ghcr.io/home-assistant/aarch64-hassio-observer:2022.09.dev1101/hassio_observer ghcr.io/home-assistant/aarch64-addon-example:1.2.0/addon_94cfad5a_example ghcr.io/home-assistant/aarch64-hassio-audio:2022.05.0/hassio_audio -addon_local_ssh \ No newline at end of file +addon_local_ssh diff --git a/tests/host/test_logs.py b/tests/host/test_logs.py index 2759a6a06..ee3002496 100644 --- a/tests/host/test_logs.py +++ b/tests/host/test_logs.py @@ -22,7 +22,6 @@ async def test_load(coresys: CoreSys): await coresys.host.logs.load() assert coresys.host.logs.boot_ids == [] - assert coresys.host.logs.identifiers == [] # File is quite large so just check it loaded for identifier in ["kernel", "os-agent", "systemd"]: @@ -79,6 +78,7 @@ async def test_identifiers(coresys: CoreSys, journald_gateway: MagicMock): ) # Mock is large so just look for a few different types of identifiers + identifiers = await coresys.host.logs.get_identifiers() for identifier in [ "addon_local_ssh", "hassio_dns", @@ -86,4 +86,6 @@ async def test_identifiers(coresys: CoreSys, journald_gateway: MagicMock): "kernel", "os-agent", ]: - assert identifier in await coresys.host.logs.get_identifiers() + assert identifier in identifiers + + assert "" not in identifiers