Make evaluation of container better (#2316)

This commit is contained in:
Pascal Vizeli 2020-11-30 18:00:12 +01:00 committed by GitHub
parent e09a839148
commit 2d294f6841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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