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
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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)