mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-08 17:56:33 +00:00
Cleanup evaluations (#3857)
* Cleanup * move * Add OS available test Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
This commit is contained in:
parent
5aa8028ff5
commit
c67d4d7c0b
@ -24,7 +24,7 @@ class EvaluateAppArmor(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "AppArmor is required for Home Assistant."
|
||||
|
||||
@property
|
||||
|
@ -1,6 +1,4 @@
|
||||
"""Evaluation class for CGroup version."""
|
||||
import logging
|
||||
|
||||
from ...const import CoreState
|
||||
from ...coresys import CoreSys
|
||||
from ..const import UnsupportedReason
|
||||
@ -9,8 +7,6 @@ from .base import EvaluateBase
|
||||
CGROUP_V1_VERSION = "1"
|
||||
CGROUP_V2_VERSION = "2"
|
||||
|
||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup(coresys: CoreSys) -> EvaluateBase:
|
||||
"""Initialize evaluation-setup function."""
|
||||
@ -20,6 +16,13 @@ def setup(coresys: CoreSys) -> EvaluateBase:
|
||||
class EvaluateCGroupVersion(EvaluateBase):
|
||||
"""Evaluate Docker configuration."""
|
||||
|
||||
@property
|
||||
def expected_versions(self) -> set[str]:
|
||||
"""Return expected cgroup versions."""
|
||||
if self.coresys.os.available:
|
||||
return {CGROUP_V1_VERSION, CGROUP_V2_VERSION}
|
||||
return {CGROUP_V1_VERSION}
|
||||
|
||||
@property
|
||||
def reason(self) -> UnsupportedReason:
|
||||
"""Return a UnsupportedReason enum."""
|
||||
@ -27,28 +30,14 @@ class EvaluateCGroupVersion(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
return "The CGroup version used by Docker is not supported"
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return f"Docker cgroup version {self.sys_docker.info.cgroup} is not supported! {self.expected_versions}"
|
||||
|
||||
@property
|
||||
def states(self) -> list[CoreState]:
|
||||
"""Return a list of valid states when this evaluation can run."""
|
||||
return [CoreState.SETUP]
|
||||
|
||||
async def evaluate(self):
|
||||
async def evaluate(self) -> bool:
|
||||
"""Run evaluation."""
|
||||
cgroup_version = self.sys_docker.info.cgroup
|
||||
|
||||
expected_version = [CGROUP_V1_VERSION]
|
||||
if self.coresys.os.available:
|
||||
expected_version.append(CGROUP_V2_VERSION)
|
||||
|
||||
if cgroup_version not in expected_version:
|
||||
_LOGGER.warning(
|
||||
"Docker cgroup version %s is not supported! %s",
|
||||
cgroup_version,
|
||||
expected_version,
|
||||
)
|
||||
return True
|
||||
|
||||
return False
|
||||
return self.sys_docker.info.cgroup not in self.expected_versions
|
||||
|
@ -45,7 +45,7 @@ class EvaluateContainer(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return f"Found unsupported images: {self._images}"
|
||||
|
||||
@property
|
||||
|
@ -21,7 +21,7 @@ class EvaluateContentTrust(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "System run with disabled trusted content security."
|
||||
|
||||
@property
|
||||
|
@ -21,7 +21,7 @@ class EvaluateDbus(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "D-Bus is required for Home Assistant."
|
||||
|
||||
@property
|
||||
|
@ -21,7 +21,7 @@ class EvaluateDNSServer(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "Found unsupported DNS server and fallback is disabled."
|
||||
|
||||
@property
|
||||
|
@ -27,7 +27,7 @@ class EvaluateDockerConfiguration(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "The configuration of Docker is not supported"
|
||||
|
||||
@property
|
||||
|
@ -21,7 +21,7 @@ class EvaluateDockerVersion(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return f"Docker version '{self.sys_docker.info.version}' is not supported by the Supervisor!"
|
||||
|
||||
@property
|
||||
|
@ -21,7 +21,7 @@ class EvaluateJobConditions(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "Found unsupported job conditions settings."
|
||||
|
||||
@property
|
||||
|
@ -23,7 +23,7 @@ class EvaluateLxc(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "Detected Docker running inside LXC."
|
||||
|
||||
@property
|
||||
|
@ -22,7 +22,7 @@ class EvaluateNetworkManager(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "NetworkManager is not correctly configured"
|
||||
|
||||
@property
|
||||
|
@ -23,7 +23,7 @@ class EvaluateOperatingSystem(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return f"Detected unsupported OS: {self.sys_host.info.operating_system}"
|
||||
|
||||
@property
|
||||
|
@ -22,7 +22,7 @@ class EvaluateOSAgent(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "OS-Agent is not correctly working"
|
||||
|
||||
@property
|
||||
|
@ -21,7 +21,7 @@ class EvaluatePrivileged(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "Supervisor does not run in Privileged mode."
|
||||
|
||||
@property
|
||||
|
@ -21,7 +21,7 @@ class EvaluateResolved(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "Systemd-Resolved is required for DNS in Home Assistant."
|
||||
|
||||
@property
|
||||
|
@ -28,7 +28,7 @@ class EvaluateSourceMods(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "System detect unauthorized source code modifications."
|
||||
|
||||
@property
|
||||
|
@ -22,7 +22,7 @@ class EvaluateSystemd(EvaluateBase):
|
||||
|
||||
@property
|
||||
def on_failure(self) -> str:
|
||||
"""Return a string that is printed when self.evaluate is False."""
|
||||
"""Return a string that is printed when self.evaluate is True."""
|
||||
return "Systemd is not correctly working"
|
||||
|
||||
@property
|
||||
|
@ -34,6 +34,21 @@ async def test_evaluation(coresys: CoreSys):
|
||||
assert cgroup_version.reason not in coresys.resolution.unsupported
|
||||
|
||||
|
||||
async def test_evaluation_os_available(coresys: CoreSys):
|
||||
"""Test evaluation with OS available."""
|
||||
cgroup_version = EvaluateCGroupVersion(coresys)
|
||||
coresys.core.state = CoreState.SETUP
|
||||
|
||||
coresys.os._available = True
|
||||
coresys.docker.info.cgroup = CGROUP_V2_VERSION
|
||||
await cgroup_version()
|
||||
assert cgroup_version.reason not in coresys.resolution.unsupported
|
||||
|
||||
coresys.docker.info.cgroup = CGROUP_V1_VERSION
|
||||
await cgroup_version()
|
||||
assert cgroup_version.reason not in coresys.resolution.unsupported
|
||||
|
||||
|
||||
async def test_did_run(coresys: CoreSys):
|
||||
"""Test that the evaluation ran as expected."""
|
||||
cgroup_version = EvaluateCGroupVersion(coresys)
|
||||
|
Loading…
x
Reference in New Issue
Block a user