Skip to content

Commit

Permalink
Addon load should not fail due to docker error (#5011)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdegat01 authored Apr 11, 2024
1 parent 8c3a520 commit f0e2fb3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion supervisor/addons/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ async def load(self) -> None:
await self.instance.check_image(self.version, default_image, self.arch)
except DockerError:
_LOGGER.info("No %s addon Docker image %s found", self.slug, self.image)
with suppress(AddonsError):
with suppress(DockerError):
await self.instance.install(self.version, default_image, arch=self.arch)

self.persist[ATTR_IMAGE] = default_image
Expand Down
30 changes: 30 additions & 0 deletions tests/addons/test_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,3 +817,33 @@ async def test_addon_loads_missing_image(
)
assert coresys.docker.images.build.call_args.kwargs["platform"] == "linux/amd64"
assert install_addon_ssh.image == "local/amd64-addon-ssh"


async def test_addon_load_succeeds_with_docker_errors(
coresys: CoreSys,
install_addon_ssh: Addon,
container: MagicMock,
caplog: pytest.LogCaptureFixture,
mock_amd64_arch_supported,
):
"""Docker errors while building/pulling an image during load should not raise and fail setup."""
# Build env invalid failure
coresys.docker.images.get.side_effect = ImageNotFound("missing")
caplog.clear()
await install_addon_ssh.load()
assert "Invalid build environment" in caplog.text

# Image build failure
coresys.docker.images.build.side_effect = DockerException()
caplog.clear()
with patch("pathlib.Path.is_file", return_value=True):
await install_addon_ssh.load()
assert "Can't build local/amd64-addon-ssh:9.2.1" in caplog.text

# Image pull failure
install_addon_ssh.data["image"] = "test/amd64-addon-ssh"
coresys.docker.images.build.reset_mock(side_effect=True)
coresys.docker.images.pull.side_effect = DockerException()
caplog.clear()
await install_addon_ssh.load()
assert "Unknown error with test/amd64-addon-ssh:9.2.1" in caplog.text

0 comments on commit f0e2fb3

Please sign in to comment.