Cleanup evaluations (#3857)

* Cleanup

* move

* Add OS available test

Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
This commit is contained in:
Joakim Sørensen 2022-09-13 19:19:07 +02:00 committed by GitHub
parent 5aa8028ff5
commit c67d4d7c0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 42 additions and 38 deletions

View File

@ -24,7 +24,7 @@ class EvaluateAppArmor(EvaluateBase):
@property @property
def on_failure(self) -> str: 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." return "AppArmor is required for Home Assistant."
@property @property

View File

@ -1,6 +1,4 @@
"""Evaluation class for CGroup version.""" """Evaluation class for CGroup version."""
import logging
from ...const import CoreState from ...const import CoreState
from ...coresys import CoreSys from ...coresys import CoreSys
from ..const import UnsupportedReason from ..const import UnsupportedReason
@ -9,8 +7,6 @@ from .base import EvaluateBase
CGROUP_V1_VERSION = "1" CGROUP_V1_VERSION = "1"
CGROUP_V2_VERSION = "2" CGROUP_V2_VERSION = "2"
_LOGGER: logging.Logger = logging.getLogger(__name__)
def setup(coresys: CoreSys) -> EvaluateBase: def setup(coresys: CoreSys) -> EvaluateBase:
"""Initialize evaluation-setup function.""" """Initialize evaluation-setup function."""
@ -20,6 +16,13 @@ def setup(coresys: CoreSys) -> EvaluateBase:
class EvaluateCGroupVersion(EvaluateBase): class EvaluateCGroupVersion(EvaluateBase):
"""Evaluate Docker configuration.""" """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 @property
def reason(self) -> UnsupportedReason: def reason(self) -> UnsupportedReason:
"""Return a UnsupportedReason enum.""" """Return a UnsupportedReason enum."""
@ -27,28 +30,14 @@ class EvaluateCGroupVersion(EvaluateBase):
@property @property
def on_failure(self) -> str: 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 CGroup version used by Docker is not supported" return f"Docker cgroup version {self.sys_docker.info.cgroup} is not supported! {self.expected_versions}"
@property @property
def states(self) -> list[CoreState]: def states(self) -> list[CoreState]:
"""Return a list of valid states when this evaluation can run.""" """Return a list of valid states when this evaluation can run."""
return [CoreState.SETUP] return [CoreState.SETUP]
async def evaluate(self): async def evaluate(self) -> bool:
"""Run evaluation.""" """Run evaluation."""
cgroup_version = self.sys_docker.info.cgroup return self.sys_docker.info.cgroup not in self.expected_versions
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

View File

@ -45,7 +45,7 @@ class EvaluateContainer(EvaluateBase):
@property @property
def on_failure(self) -> str: 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}" return f"Found unsupported images: {self._images}"
@property @property

View File

@ -21,7 +21,7 @@ class EvaluateContentTrust(EvaluateBase):
@property @property
def on_failure(self) -> str: 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." return "System run with disabled trusted content security."
@property @property

View File

@ -21,7 +21,7 @@ class EvaluateDbus(EvaluateBase):
@property @property
def on_failure(self) -> str: 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." return "D-Bus is required for Home Assistant."
@property @property

View File

@ -21,7 +21,7 @@ class EvaluateDNSServer(EvaluateBase):
@property @property
def on_failure(self) -> str: 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." return "Found unsupported DNS server and fallback is disabled."
@property @property

View File

@ -27,7 +27,7 @@ class EvaluateDockerConfiguration(EvaluateBase):
@property @property
def on_failure(self) -> str: 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" return "The configuration of Docker is not supported"
@property @property

View File

@ -21,7 +21,7 @@ class EvaluateDockerVersion(EvaluateBase):
@property @property
def on_failure(self) -> str: 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!" return f"Docker version '{self.sys_docker.info.version}' is not supported by the Supervisor!"
@property @property

View File

@ -21,7 +21,7 @@ class EvaluateJobConditions(EvaluateBase):
@property @property
def on_failure(self) -> str: 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." return "Found unsupported job conditions settings."
@property @property

View File

@ -23,7 +23,7 @@ class EvaluateLxc(EvaluateBase):
@property @property
def on_failure(self) -> str: 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." return "Detected Docker running inside LXC."
@property @property

View File

@ -22,7 +22,7 @@ class EvaluateNetworkManager(EvaluateBase):
@property @property
def on_failure(self) -> str: 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" return "NetworkManager is not correctly configured"
@property @property

View File

@ -23,7 +23,7 @@ class EvaluateOperatingSystem(EvaluateBase):
@property @property
def on_failure(self) -> str: 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}" return f"Detected unsupported OS: {self.sys_host.info.operating_system}"
@property @property

View File

@ -22,7 +22,7 @@ class EvaluateOSAgent(EvaluateBase):
@property @property
def on_failure(self) -> str: 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" return "OS-Agent is not correctly working"
@property @property

View File

@ -21,7 +21,7 @@ class EvaluatePrivileged(EvaluateBase):
@property @property
def on_failure(self) -> str: 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." return "Supervisor does not run in Privileged mode."
@property @property

View File

@ -21,7 +21,7 @@ class EvaluateResolved(EvaluateBase):
@property @property
def on_failure(self) -> str: 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." return "Systemd-Resolved is required for DNS in Home Assistant."
@property @property

View File

@ -28,7 +28,7 @@ class EvaluateSourceMods(EvaluateBase):
@property @property
def on_failure(self) -> str: 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." return "System detect unauthorized source code modifications."
@property @property

View File

@ -22,7 +22,7 @@ class EvaluateSystemd(EvaluateBase):
@property @property
def on_failure(self) -> str: 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" return "Systemd is not correctly working"
@property @property

View File

@ -34,6 +34,21 @@ async def test_evaluation(coresys: CoreSys):
assert cgroup_version.reason not in coresys.resolution.unsupported 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): async def test_did_run(coresys: CoreSys):
"""Test that the evaluation ran as expected.""" """Test that the evaluation ran as expected."""
cgroup_version = EvaluateCGroupVersion(coresys) cgroup_version = EvaluateCGroupVersion(coresys)