mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-23 17:16:33 +00:00
Add os-agent to evaluations for supported systems (#3138)
This commit is contained in:
parent
a85e816cd7
commit
5933b66b1c
@ -44,5 +44,5 @@ class HostFeature(str, Enum):
|
||||
REBOOT = "reboot"
|
||||
SERVICES = "services"
|
||||
SHUTDOWN = "shutdown"
|
||||
AGENT = "agent"
|
||||
OS_AGENT = "os_agent"
|
||||
TIMEDATE = "timedate"
|
||||
|
@ -88,7 +88,7 @@ class HostManager(CoreSysAttributes):
|
||||
features.append(HostFeature.TIMEDATE)
|
||||
|
||||
if self.sys_dbus.agent.is_connected:
|
||||
features.append(HostFeature.AGENT)
|
||||
features.append(HostFeature.OS_AGENT)
|
||||
|
||||
if self.sys_os.available:
|
||||
features.append(HostFeature.HAOS)
|
||||
|
@ -175,7 +175,7 @@ class Job(CoreSysAttributes):
|
||||
|
||||
if (
|
||||
JobCondition.OS_AGENT in self.conditions
|
||||
and HostFeature.AGENT not in self.sys_host.features
|
||||
and HostFeature.OS_AGENT not in self.sys_host.features
|
||||
):
|
||||
raise JobConditionException(
|
||||
f"'{self._method.__qualname__}' blocked from execution, no Home Assistant OS-Agent available"
|
||||
|
@ -27,19 +27,20 @@ class ContextType(str, Enum):
|
||||
class UnsupportedReason(str, Enum):
|
||||
"""Reasons for unsupported status."""
|
||||
|
||||
CONTAINER = "container"
|
||||
DBUS = "dbus"
|
||||
APPARMOR = "apparmor"
|
||||
CONTAINER = "container"
|
||||
CONTENT_TRUST = "content_trust"
|
||||
DBUS = "dbus"
|
||||
DOCKER_CONFIGURATION = "docker_configuration"
|
||||
DOCKER_VERSION = "docker_version"
|
||||
JOB_CONDITIONS = "job_conditions"
|
||||
LXC = "lxc"
|
||||
NETWORK_MANAGER = "network_manager"
|
||||
OS = "os"
|
||||
OS_AGENT = "os_agent"
|
||||
PRIVILEGED = "privileged"
|
||||
SYSTEMD = "systemd"
|
||||
JOB_CONDITIONS = "job_conditions"
|
||||
CONTENT_TRUST = "content_trust"
|
||||
SOURCE_MODS = "source_mods"
|
||||
SYSTEMD = "systemd"
|
||||
|
||||
|
||||
class UnhealthyReason(str, Enum):
|
||||
|
35
supervisor/resolution/evaluations/os_agent.py
Normal file
35
supervisor/resolution/evaluations/os_agent.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""Evaluation class for host agent."""
|
||||
|
||||
from ...const import CoreState
|
||||
from ...coresys import CoreSys
|
||||
from ...host.const import HostFeature
|
||||
from ..const import UnsupportedReason
|
||||
from .base import EvaluateBase
|
||||
|
||||
|
||||
def setup(coresys: CoreSys) -> EvaluateBase:
|
||||
"""Initialize evaluation-setup function."""
|
||||
return EvaluateOSAgent(coresys)
|
||||
|
||||
|
||||
class EvaluateOSAgent(EvaluateBase):
|
||||
"""Evaluate host agent support."""
|
||||
|
||||
@property
|
||||
def reason(self) -> UnsupportedReason:
|
||||
"""Return a UnsupportedReason enum."""
|
||||
return UnsupportedReason.OS_AGENT
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
return "OS-Agent is not correctly working"
|
||||
|
||||
@property
|
||||
def states(self) -> list[CoreState]:
|
||||
"""Return a list of valid states when this evaluation can run."""
|
||||
return [CoreState.SETUP]
|
||||
|
||||
async def evaluate(self):
|
||||
"""Run evaluation."""
|
||||
return HostFeature.OS_AGENT not in self.sys_host.features
|
@ -39,5 +39,6 @@ class EvaluateSystemd(EvaluateBase):
|
||||
HostFeature.SERVICES,
|
||||
HostFeature.SHUTDOWN,
|
||||
HostFeature.REBOOT,
|
||||
HostFeature.TIMEDATE,
|
||||
)
|
||||
)
|
||||
|
53
tests/resolution/evaluation/test_evaluate_os_agent.py
Normal file
53
tests/resolution/evaluation/test_evaluate_os_agent.py
Normal file
@ -0,0 +1,53 @@
|
||||
"""Test evaluation base."""
|
||||
# pylint: disable=import-error,protected-access
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from supervisor.const import CoreState
|
||||
from supervisor.coresys import CoreSys
|
||||
from supervisor.host.const import HostFeature
|
||||
from supervisor.resolution.evaluations.os_agent import EvaluateOSAgent
|
||||
|
||||
|
||||
async def test_evaluation(coresys: CoreSys):
|
||||
"""Test evaluation."""
|
||||
agent = EvaluateOSAgent(coresys)
|
||||
coresys.core.state = CoreState.SETUP
|
||||
|
||||
assert agent.reason not in coresys.resolution.unsupported
|
||||
|
||||
coresys._host = MagicMock()
|
||||
|
||||
coresys.host.features = [HostFeature.HOSTNAME]
|
||||
await agent()
|
||||
assert agent.reason in coresys.resolution.unsupported
|
||||
|
||||
coresys.host.features = [
|
||||
HostFeature.OS_AGENT,
|
||||
]
|
||||
await agent()
|
||||
assert agent.reason not in coresys.resolution.unsupported
|
||||
|
||||
|
||||
async def test_did_run(coresys: CoreSys):
|
||||
"""Test that the evaluation ran as expected."""
|
||||
agent = EvaluateOSAgent(coresys)
|
||||
should_run = agent.states
|
||||
should_not_run = [state for state in CoreState if state not in should_run]
|
||||
assert len(should_run) != 0
|
||||
assert len(should_not_run) != 0
|
||||
|
||||
with patch(
|
||||
"supervisor.resolution.evaluations.os_agent.EvaluateOSAgent.evaluate",
|
||||
return_value=None,
|
||||
) as evaluate:
|
||||
for state in should_run:
|
||||
coresys.core.state = state
|
||||
await agent()
|
||||
evaluate.assert_called_once()
|
||||
evaluate.reset_mock()
|
||||
|
||||
for state in should_not_run:
|
||||
coresys.core.state = state
|
||||
await agent()
|
||||
evaluate.assert_not_called()
|
||||
evaluate.reset_mock()
|
@ -22,12 +22,14 @@ async def test_evaluation(coresys: CoreSys):
|
||||
assert systemd.reason in coresys.resolution.unsupported
|
||||
|
||||
coresys.host.features = [
|
||||
HostFeature.HOSTNAME,
|
||||
HostFeature.SERVICES,
|
||||
HostFeature.SHUTDOWN,
|
||||
HostFeature.REBOOT,
|
||||
HostFeature.TIMEDATE,
|
||||
]
|
||||
await systemd()
|
||||
assert systemd.reason in coresys.resolution.unsupported
|
||||
assert systemd.reason not in coresys.resolution.unsupported
|
||||
|
||||
|
||||
async def test_did_run(coresys: CoreSys):
|
||||
|
Loading…
x
Reference in New Issue
Block a user