From 2d294f68418fbbcdbad776cdd9c614ef952074c4 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 30 Nov 2020 18:00:12 +0100 Subject: [PATCH] Make evaluation of container better (#2316) --- supervisor/bootstrap.py | 1 + supervisor/resolution/check.py | 3 +-- supervisor/resolution/evaluate.py | 4 +--- supervisor/resolution/evaluations/container.py | 16 ++++++++++------ supervisor/resolution/fixup.py | 6 ++---- .../evaluation/test_evaluate_container.py | 16 +++++++++++----- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/supervisor/bootstrap.py b/supervisor/bootstrap.py index 9fbf492c2..56676c7b2 100644 --- a/supervisor/bootstrap.py +++ b/supervisor/bootstrap.py @@ -303,6 +303,7 @@ def setup_diagnostics(coresys: CoreSys) -> None: sentry_sdk.init( dsn="https://9c6ea70f49234442b4746e447b24747e@o427061.ingest.sentry.io/5370612", before_send=lambda event, hint: filter_data(coresys, event, hint), + auto_enabling_integrations=False, integrations=[AioHttpIntegration(), sentry_logging], release=SUPERVISOR_VERSION, max_breadcrumbs=30, diff --git a/supervisor/resolution/check.py b/supervisor/resolution/check.py index 9196de8a6..eca0de579 100644 --- a/supervisor/resolution/check.py +++ b/supervisor/resolution/check.py @@ -3,7 +3,6 @@ import logging from typing import List from ..coresys import CoreSys, CoreSysAttributes -from ..exceptions import HassioError from .checks.base import CheckBase from .checks.free_space import CheckFreeSpace @@ -31,7 +30,7 @@ class ResolutionCheck(CoreSysAttributes): for test in self.all_tests: try: await test() - except HassioError as err: + except Exception as err: # pylint: disable=broad-except _LOGGER.warning("Error during processing %s: %s", test.issue, err) self.sys_capture_exception(err) diff --git a/supervisor/resolution/evaluate.py b/supervisor/resolution/evaluate.py index c7cbb60e4..7c14092c0 100644 --- a/supervisor/resolution/evaluate.py +++ b/supervisor/resolution/evaluate.py @@ -2,8 +2,6 @@ import logging from typing import List -from supervisor.exceptions import HassioError - from ..coresys import CoreSys, CoreSysAttributes from .const import UnhealthyReason, UnsupportedReason from .evaluations.base import EvaluateBase @@ -69,7 +67,7 @@ class ResolutionEvaluation(CoreSysAttributes): for evaluation in self.all_evalutions: try: await evaluation() - except HassioError as err: + except Exception as err: # pylint: disable=broad-except _LOGGER.warning( "Error during processing %s: %s", evaluation.reason, err ) diff --git a/supervisor/resolution/evaluations/container.py b/supervisor/resolution/evaluations/container.py index b0645d80a..2c02139a2 100644 --- a/supervisor/resolution/evaluations/container.py +++ b/supervisor/resolution/evaluations/container.py @@ -13,9 +13,8 @@ from .base import EvaluateBase _LOGGER: logging.Logger = logging.getLogger(__name__) DOCKER_IMAGE_DENYLIST = [ - "containrrr/watchtower", - "pyouroboros/ouroboros", - "v2tec/watchtower", + "watchtower", + "ouroboros", ] @@ -41,16 +40,21 @@ class EvaluateContainer(EvaluateBase): @property def states(self) -> List[CoreState]: """Return a list of valid states when this evaluation can run.""" - return [CoreState.SETUP, CoreState.RUNNING] + return [CoreState.SETUP, CoreState.RUNNING, CoreState.INITIALIZE] async def evaluate(self) -> None: """Run evaluation.""" self._images.clear() for image in await self.sys_run_in_executor(self._get_images): for tag in image.tags: - image_name = tag.split(":")[0] + image_name = tag.partition(":")[0].split("/")[-1] + + # Evalue system if ( - image_name in DOCKER_IMAGE_DENYLIST + 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) diff --git a/supervisor/resolution/fixup.py b/supervisor/resolution/fixup.py index d07dd2837..d82ece6fd 100644 --- a/supervisor/resolution/fixup.py +++ b/supervisor/resolution/fixup.py @@ -2,10 +2,8 @@ import logging from typing import List -from supervisor.exceptions import HassioError -from supervisor.resolution.data import Suggestion - from ..coresys import CoreSys, CoreSysAttributes +from .data import Suggestion from .fixups.base import FixupBase from .fixups.clear_full_snapshot import FixupClearFullSnapshot from .fixups.create_full_snapshot import FixupCreateFullSnapshot @@ -49,7 +47,7 @@ class ResolutionFixup(CoreSysAttributes): continue try: await fix() - except HassioError as err: + except Exception as err: # pylint: disable=broad-except _LOGGER.warning("Error during processing %s: %s", fix.suggestion, err) self.sys_capture_exception(err) diff --git a/tests/resolution/evaluation/test_evaluate_container.py b/tests/resolution/evaluation/test_evaluate_container.py index 15c59e1e7..75d52659d 100644 --- a/tests/resolution/evaluation/test_evaluate_container.py +++ b/tests/resolution/evaluation/test_evaluate_container.py @@ -6,10 +6,7 @@ from docker.errors import DockerException from supervisor.const import CoreState from supervisor.coresys import CoreSys -from supervisor.resolution.evaluations.container import ( - DOCKER_IMAGE_DENYLIST, - EvaluateContainer, -) +from supervisor.resolution.evaluations.container import EvaluateContainer def test_get_images(coresys: CoreSys): @@ -37,7 +34,16 @@ async def test_evaluation(coresys: CoreSys): with patch( "supervisor.resolution.evaluations.container.EvaluateContainer._get_images", - return_value=[MagicMock(tags=[f"{DOCKER_IMAGE_DENYLIST[0]}:latest"])], + return_value=[ + MagicMock( + tags=[ + "armhfbuild/watchtower:latest", + "concerco/watchtowerv6:10.0.2", + "containrrr/watchtower:1.1", + "pyouroboros/ouroboros:1.4.3", + ] + ) + ], ): await container() assert container.reason in coresys.resolution.unsupported