Send list of images to sentry (#2321)

This commit is contained in:
Pascal Vizeli 2020-12-01 14:29:37 +01:00 committed by GitHub
parent e2a473baa3
commit 0b085354db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 3 deletions

View File

@ -62,6 +62,7 @@ def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict:
"host": coresys.host.info.operating_system, "host": coresys.host.info.operating_system,
"kernel": coresys.host.info.kernel, "kernel": coresys.host.info.kernel,
"machine": coresys.machine, "machine": coresys.machine,
"images": coresys.resolution.evaluate.cached_images,
}, },
"versions": { "versions": {
"audio": coresys.plugins.audio.version, "audio": coresys.plugins.audio.version,

View File

@ -1,6 +1,6 @@
"""Helpers to evaluate the system.""" """Helpers to evaluate the system."""
import logging import logging
from typing import List from typing import List, Set
from ..coresys import CoreSys, CoreSysAttributes from ..coresys import CoreSys, CoreSysAttributes
from .const import UnhealthyReason, UnsupportedReason from .const import UnhealthyReason, UnsupportedReason
@ -33,6 +33,8 @@ class ResolutionEvaluation(CoreSysAttributes):
"""Initialize the evaluation class.""" """Initialize the evaluation class."""
self.coresys = coresys self.coresys = coresys
self.cached_images: Set[str] = set()
self._container = EvaluateContainer(coresys) self._container = EvaluateContainer(coresys)
self._dbus = EvaluateDbus(coresys) self._dbus = EvaluateDbus(coresys)
self._docker_configuration = EvaluateDockerConfiguration(coresys) self._docker_configuration = EvaluateDockerConfiguration(coresys)

View File

@ -7,7 +7,7 @@ from requests import RequestException
from ...const import CoreState from ...const import CoreState
from ...coresys import CoreSys from ...coresys import CoreSys
from ..const import UnsupportedReason from ..const import ContextType, IssueType, SuggestionType, UnsupportedReason
from .base import EvaluateBase from .base import EvaluateBase
_LOGGER: logging.Logger = logging.getLogger(__name__) _LOGGER: logging.Logger = logging.getLogger(__name__)
@ -44,12 +44,15 @@ class EvaluateContainer(EvaluateBase):
async def evaluate(self) -> None: async def evaluate(self) -> None:
"""Run evaluation.""" """Run evaluation."""
self.sys_resolution.evaluate.cached_images.clear()
self._images.clear() self._images.clear()
for image in await self.sys_run_in_executor(self._get_images): for image in await self.sys_run_in_executor(self._get_images):
for tag in image.tags: for tag in image.tags:
image_name = tag.partition(":")[0].split("/")[-1] self.sys_resolution.evaluate.cached_images.add(tag)
# Evalue system # Evalue system
image_name = tag.partition(":")[0].split("/")[-1]
if ( if (
any( any(
image_name.startswith(deny_name) image_name.startswith(deny_name)
@ -68,5 +71,10 @@ class EvaluateContainer(EvaluateBase):
images = self.sys_docker.images.list() images = self.sys_docker.images.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(
IssueType.CORRUPT_DOCKER,
ContextType.SYSTEM,
suggestions=[SuggestionType.EXECUTE_REPAIR],
)
return images return images

View File

@ -165,3 +165,17 @@ def test_unhealthy_on_report(coresys):
assert "issues" in event["contexts"]["resolution"] assert "issues" in event["contexts"]["resolution"]
assert event["contexts"]["resolution"]["unhealthy"][-1] == UnhealthyReason.DOCKER assert event["contexts"]["resolution"]["unhealthy"][-1] == UnhealthyReason.DOCKER
def test_images_report(coresys):
"""Attach image to report."""
coresys.config.diagnostics = True
coresys.core.state = CoreState.RUNNING
coresys.resolution.evaluate.cached_images.add("my/test:image")
with patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0 ** 3))):
event = filter_data(coresys, SAMPLE_EVENT, {})
assert "issues" in event["contexts"]["resolution"]
assert event["contexts"]["host"]["images"] == {"my/test:image"}

View File

@ -48,6 +48,13 @@ async def test_evaluation(coresys: CoreSys):
await container() await container()
assert container.reason in coresys.resolution.unsupported assert container.reason in coresys.resolution.unsupported
assert coresys.resolution.evaluate.cached_images == {
"armhfbuild/watchtower:latest",
"concerco/watchtowerv6:10.0.2",
"containrrr/watchtower:1.1",
"pyouroboros/ouroboros:1.4.3",
}
with patch( with patch(
"supervisor.resolution.evaluations.container.EvaluateContainer._get_images", "supervisor.resolution.evaluations.container.EvaluateContainer._get_images",
return_value=[MagicMock(tags=[])], return_value=[MagicMock(tags=[])],
@ -55,6 +62,8 @@ async def test_evaluation(coresys: CoreSys):
await container() await container()
assert container.reason not in coresys.resolution.unsupported assert container.reason not in coresys.resolution.unsupported
assert coresys.resolution.evaluate.cached_images == set()
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."""