diff --git a/supervisor/resolution/evaluations/apparmor.py b/supervisor/resolution/evaluations/apparmor.py index a7174accb..b4ab67dfb 100644 --- a/supervisor/resolution/evaluations/apparmor.py +++ b/supervisor/resolution/evaluations/apparmor.py @@ -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 diff --git a/supervisor/resolution/evaluations/cgroup.py b/supervisor/resolution/evaluations/cgroup.py index b6223d199..5457326a8 100644 --- a/supervisor/resolution/evaluations/cgroup.py +++ b/supervisor/resolution/evaluations/cgroup.py @@ -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 diff --git a/supervisor/resolution/evaluations/container.py b/supervisor/resolution/evaluations/container.py index ac10b9a1a..de6119093 100644 --- a/supervisor/resolution/evaluations/container.py +++ b/supervisor/resolution/evaluations/container.py @@ -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 diff --git a/supervisor/resolution/evaluations/content_trust.py b/supervisor/resolution/evaluations/content_trust.py index eb1f4f78d..7415b7a3b 100644 --- a/supervisor/resolution/evaluations/content_trust.py +++ b/supervisor/resolution/evaluations/content_trust.py @@ -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 diff --git a/supervisor/resolution/evaluations/dbus.py b/supervisor/resolution/evaluations/dbus.py index 6dc612bcf..5d8d3000e 100644 --- a/supervisor/resolution/evaluations/dbus.py +++ b/supervisor/resolution/evaluations/dbus.py @@ -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 diff --git a/supervisor/resolution/evaluations/dns_server.py b/supervisor/resolution/evaluations/dns_server.py index 048d3064a..efdb4ff90 100644 --- a/supervisor/resolution/evaluations/dns_server.py +++ b/supervisor/resolution/evaluations/dns_server.py @@ -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 diff --git a/supervisor/resolution/evaluations/docker_configuration.py b/supervisor/resolution/evaluations/docker_configuration.py index 8c5173580..18b996038 100644 --- a/supervisor/resolution/evaluations/docker_configuration.py +++ b/supervisor/resolution/evaluations/docker_configuration.py @@ -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 diff --git a/supervisor/resolution/evaluations/docker_version.py b/supervisor/resolution/evaluations/docker_version.py index afe75f959..f779d2bff 100644 --- a/supervisor/resolution/evaluations/docker_version.py +++ b/supervisor/resolution/evaluations/docker_version.py @@ -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 diff --git a/supervisor/resolution/evaluations/job_conditions.py b/supervisor/resolution/evaluations/job_conditions.py index b688e5c28..4f7cd2a0b 100644 --- a/supervisor/resolution/evaluations/job_conditions.py +++ b/supervisor/resolution/evaluations/job_conditions.py @@ -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 diff --git a/supervisor/resolution/evaluations/lxc.py b/supervisor/resolution/evaluations/lxc.py index 7343dddfb..136220b43 100644 --- a/supervisor/resolution/evaluations/lxc.py +++ b/supervisor/resolution/evaluations/lxc.py @@ -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 diff --git a/supervisor/resolution/evaluations/network_manager.py b/supervisor/resolution/evaluations/network_manager.py index fb2e509e0..a81529657 100644 --- a/supervisor/resolution/evaluations/network_manager.py +++ b/supervisor/resolution/evaluations/network_manager.py @@ -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 diff --git a/supervisor/resolution/evaluations/operating_system.py b/supervisor/resolution/evaluations/operating_system.py index 44634802f..590c837e5 100644 --- a/supervisor/resolution/evaluations/operating_system.py +++ b/supervisor/resolution/evaluations/operating_system.py @@ -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 diff --git a/supervisor/resolution/evaluations/os_agent.py b/supervisor/resolution/evaluations/os_agent.py index 37fedddb2..056363d6f 100644 --- a/supervisor/resolution/evaluations/os_agent.py +++ b/supervisor/resolution/evaluations/os_agent.py @@ -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 diff --git a/supervisor/resolution/evaluations/privileged.py b/supervisor/resolution/evaluations/privileged.py index 8c1252034..a3b9733b2 100644 --- a/supervisor/resolution/evaluations/privileged.py +++ b/supervisor/resolution/evaluations/privileged.py @@ -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 diff --git a/supervisor/resolution/evaluations/resolved.py b/supervisor/resolution/evaluations/resolved.py index 38b2c5a00..1bfceeca6 100644 --- a/supervisor/resolution/evaluations/resolved.py +++ b/supervisor/resolution/evaluations/resolved.py @@ -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 diff --git a/supervisor/resolution/evaluations/source_mods.py b/supervisor/resolution/evaluations/source_mods.py index 1675bd3da..67a8067d2 100644 --- a/supervisor/resolution/evaluations/source_mods.py +++ b/supervisor/resolution/evaluations/source_mods.py @@ -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 diff --git a/supervisor/resolution/evaluations/systemd.py b/supervisor/resolution/evaluations/systemd.py index c72734bdf..d5ea0e604 100644 --- a/supervisor/resolution/evaluations/systemd.py +++ b/supervisor/resolution/evaluations/systemd.py @@ -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 diff --git a/tests/resolution/evaluation/test_evaluate_cgroup.py b/tests/resolution/evaluation/test_evaluate_cgroup.py index 16ccf1e67..da81b69eb 100644 --- a/tests/resolution/evaluation/test_evaluate_cgroup.py +++ b/tests/resolution/evaluation/test_evaluate_cgroup.py @@ -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)