mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-13 20:26:29 +00:00
Adjust container evaluation (#3174)
* Adjust container evaluation * remove test
This commit is contained in:
parent
1ee6c0491c
commit
8a553dbb59
@ -11,7 +11,6 @@ from .validate import get_valid_modules
|
|||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
UNHEALTHY = [
|
UNHEALTHY = [
|
||||||
UnsupportedReason.CONTAINER,
|
|
||||||
UnsupportedReason.DOCKER_VERSION,
|
UnsupportedReason.DOCKER_VERSION,
|
||||||
UnsupportedReason.LXC,
|
UnsupportedReason.LXC,
|
||||||
UnsupportedReason.PRIVILEGED,
|
UnsupportedReason.PRIVILEGED,
|
||||||
|
@ -7,7 +7,13 @@ from requests import RequestException
|
|||||||
|
|
||||||
from ...const import CoreState
|
from ...const import CoreState
|
||||||
from ...coresys import CoreSys
|
from ...coresys import CoreSys
|
||||||
from ..const import ContextType, IssueType, SuggestionType, UnsupportedReason
|
from ..const import (
|
||||||
|
ContextType,
|
||||||
|
IssueType,
|
||||||
|
SuggestionType,
|
||||||
|
UnhealthyReason,
|
||||||
|
UnsupportedReason,
|
||||||
|
)
|
||||||
from .base import EvaluateBase
|
from .base import EvaluateBase
|
||||||
|
|
||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
@ -47,6 +53,16 @@ class EvaluateContainer(EvaluateBase):
|
|||||||
"""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, CoreState.RUNNING, CoreState.INITIALIZE]
|
return [CoreState.SETUP, CoreState.RUNNING, CoreState.INITIALIZE]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def known_images(self) -> set[str]:
|
||||||
|
"""Return a set of all known images."""
|
||||||
|
return {
|
||||||
|
self.sys_homeassistant.image,
|
||||||
|
self.sys_supervisor.image,
|
||||||
|
*(plugin.image for plugin in self.sys_plugins.all_plugins),
|
||||||
|
*(addon.image for addon in self.sys_addons.installed),
|
||||||
|
}
|
||||||
|
|
||||||
async def evaluate(self) -> None:
|
async def evaluate(self) -> None:
|
||||||
"""Run evaluation."""
|
"""Run evaluation."""
|
||||||
self.sys_resolution.evaluate.cached_images.clear()
|
self.sys_resolution.evaluate.cached_images.clear()
|
||||||
@ -57,15 +73,18 @@ class EvaluateContainer(EvaluateBase):
|
|||||||
self.sys_resolution.evaluate.cached_images.add(tag)
|
self.sys_resolution.evaluate.cached_images.add(tag)
|
||||||
|
|
||||||
# Evalue system
|
# Evalue system
|
||||||
image_name = tag.partition(":")[0].split("/")[-1]
|
image_name = tag.partition(":")[0]
|
||||||
if (
|
if image_name not in self.known_images:
|
||||||
any(
|
|
||||||
image_name.startswith(deny_name)
|
|
||||||
for deny_name in DOCKER_IMAGE_DENYLIST
|
|
||||||
)
|
|
||||||
and image_name not in self._images
|
|
||||||
):
|
|
||||||
self._images.add(image_name)
|
self._images.add(image_name)
|
||||||
|
if any(
|
||||||
|
image_name.split("/")[-1].startswith(deny_name)
|
||||||
|
for deny_name in DOCKER_IMAGE_DENYLIST
|
||||||
|
):
|
||||||
|
_LOGGER.error(
|
||||||
|
"Found image in deny-list '%s' on the host", image_name
|
||||||
|
)
|
||||||
|
self.sys_resolution.unhealthy = UnhealthyReason.DOCKER
|
||||||
|
|
||||||
return len(self._images) != 0
|
return len(self._images) != 0
|
||||||
|
|
||||||
def _get_images(self) -> list[Any]:
|
def _get_images(self) -> list[Any]:
|
||||||
@ -73,7 +92,9 @@ class EvaluateContainer(EvaluateBase):
|
|||||||
images = []
|
images = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
images = self.sys_docker.images.list()
|
images = [
|
||||||
|
container.image for container in self.sys_docker.containers.list()
|
||||||
|
]
|
||||||
except (DockerException, RequestException) as err:
|
except (DockerException, RequestException) as err:
|
||||||
_LOGGER.error("Corrupt docker overlayfs detect: %s", err)
|
_LOGGER.error("Corrupt docker overlayfs detect: %s", err)
|
||||||
self.sys_resolution.create_issue(
|
self.sys_resolution.create_issue(
|
||||||
|
@ -92,12 +92,3 @@ async def test_adding_and_removing_unsupported_reason(coresys: CoreSys):
|
|||||||
await coresys.resolution.evaluate.evaluate_system()
|
await coresys.resolution.evaluate.evaluate_system()
|
||||||
assert UnsupportedReason.NETWORK_MANAGER not in coresys.resolution.unsupported
|
assert UnsupportedReason.NETWORK_MANAGER not in coresys.resolution.unsupported
|
||||||
assert coresys.core.supported
|
assert coresys.core.supported
|
||||||
|
|
||||||
|
|
||||||
async def test_set_unhealthy(coresys: CoreSys):
|
|
||||||
"""Test setting unhealthy."""
|
|
||||||
assert coresys.core.healthy
|
|
||||||
coresys.resolution.unsupported = UnsupportedReason.CONTAINER
|
|
||||||
await coresys.resolution.evaluate.evaluate_system()
|
|
||||||
|
|
||||||
assert not coresys.core.healthy
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user