mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-19 07:06:30 +00:00
Host Apparmor version on info (#3271)
This commit is contained in:
parent
d80d76a24d
commit
3c52f87cdc
@ -9,3 +9,4 @@ ATTR_DT_UTC = "dt_utc"
|
|||||||
ATTR_STARTUP_TIME = "startup_time"
|
ATTR_STARTUP_TIME = "startup_time"
|
||||||
ATTR_USE_NTP = "use_ntp"
|
ATTR_USE_NTP = "use_ntp"
|
||||||
ATTR_USE_RTC = "use_rtc"
|
ATTR_USE_RTC = "use_rtc"
|
||||||
|
ATTR_APPARMOR_VERSION = "apparmor_version"
|
||||||
|
@ -27,6 +27,7 @@ from ..const import (
|
|||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_AGENT_VERSION,
|
ATTR_AGENT_VERSION,
|
||||||
|
ATTR_APPARMOR_VERSION,
|
||||||
ATTR_BOOT_TIMESTAMP,
|
ATTR_BOOT_TIMESTAMP,
|
||||||
ATTR_DT_SYNCHRONIZED,
|
ATTR_DT_SYNCHRONIZED,
|
||||||
ATTR_DT_UTC,
|
ATTR_DT_UTC,
|
||||||
@ -49,6 +50,7 @@ class APIHost(CoreSysAttributes):
|
|||||||
"""Return host information."""
|
"""Return host information."""
|
||||||
return {
|
return {
|
||||||
ATTR_AGENT_VERSION: self.sys_dbus.agent.version,
|
ATTR_AGENT_VERSION: self.sys_dbus.agent.version,
|
||||||
|
ATTR_APPARMOR_VERSION: self.sys_host.apparmor.version,
|
||||||
ATTR_CHASSIS: self.sys_host.info.chassis,
|
ATTR_CHASSIS: self.sys_host.info.chassis,
|
||||||
ATTR_CPE: self.sys_host.info.cpe,
|
ATTR_CPE: self.sys_host.info.cpe,
|
||||||
ATTR_DEPLOYMENT: self.sys_host.info.deployment,
|
ATTR_DEPLOYMENT: self.sys_host.info.deployment,
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
"""AppArmor control for host."""
|
"""AppArmor control for host."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from supervisor.resolution.const import UnsupportedReason
|
from awesomeversion import AwesomeVersion
|
||||||
|
|
||||||
from ..coresys import CoreSys, CoreSysAttributes
|
from ..coresys import CoreSys, CoreSysAttributes
|
||||||
from ..exceptions import DBusError, HostAppArmorError
|
from ..exceptions import DBusError, HostAppArmorError
|
||||||
|
from ..resolution.const import UnsupportedReason
|
||||||
from ..utils.apparmor import validate_profile
|
from ..utils.apparmor import validate_profile
|
||||||
from .const import HostFeature
|
from .const import HostFeature
|
||||||
|
|
||||||
@ -29,6 +32,11 @@ class AppArmorControl(CoreSysAttributes):
|
|||||||
and UnsupportedReason.APPARMOR not in self.sys_resolution.unsupported
|
and UnsupportedReason.APPARMOR not in self.sys_resolution.unsupported
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def version(self) -> AwesomeVersion | None:
|
||||||
|
"""Return hosts AppArmor Version."""
|
||||||
|
return self.sys_dbus.agent.apparmor.version
|
||||||
|
|
||||||
def exists(self, profile_name: str) -> bool:
|
def exists(self, profile_name: str) -> bool:
|
||||||
"""Return True if a profile exists."""
|
"""Return True if a profile exists."""
|
||||||
return profile_name in self._profiles
|
return profile_name in self._profiles
|
||||||
|
24
tests/api/test_host.py
Normal file
24
tests/api/test_host.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
"""Test Host API."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from supervisor.coresys import CoreSys
|
||||||
|
|
||||||
|
# pylint: disable=protected-access
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_api_host_info(api_client, tmp_path, coresys: CoreSys):
|
||||||
|
"""Test host info api."""
|
||||||
|
await coresys.dbus.agent.connect()
|
||||||
|
await coresys.dbus.agent.update()
|
||||||
|
|
||||||
|
coresys.hardware.disk.get_disk_life_time = lambda x: 0
|
||||||
|
coresys.hardware.disk.get_disk_free_space = lambda x: 5000
|
||||||
|
coresys.hardware.disk.get_disk_total_space = lambda x: 50000
|
||||||
|
coresys.hardware.disk.get_disk_used_space = lambda x: 45000
|
||||||
|
|
||||||
|
resp = await api_client.get("/host/info")
|
||||||
|
result = await resp.json()
|
||||||
|
|
||||||
|
assert result["data"]["apparmor_version"] == "2.13.2"
|
Loading…
x
Reference in New Issue
Block a user