Fix local Add-on restore on blank instance (#3403)

Make sure to not reference version attribute from the DockerAddon
instance since it is not yet populated in case this instance hadn't
installed that Add-on previously.

Use the higher level Images.load() API which returns a list of images
instead of loading with the lower level API and then search for the
image we just imported.
This commit is contained in:
Stefan Agner 2022-01-11 16:55:19 +01:00 committed by GitHub
parent c8b49aba42
commit 69c2517d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -582,9 +582,15 @@ class DockerAddon(DockerInterface):
"""
try:
with tar_file.open("rb") as read_tar:
self.sys_docker.api.load_image(read_tar, quiet=True)
docker_image_list = self.sys_docker.images.load(read_tar)
docker_image = self.sys_docker.images.get(f"{self.image}:{self.version}")
if len(docker_image_list) != 1:
_LOGGER.warning(
"Unexpected image count %d while importing image from tar",
len(docker_image_list),
)
return
docker_image = docker_image_list[0]
except (docker.errors.DockerException, OSError) as err:
_LOGGER.error("Can't import image %s: %s", self.image, err)
raise DockerError() from err