mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-20 10:28:45 +00:00
Await aiodocker import_image coroutine (#6378)
The aiodocker images.import_image() method returns a coroutine that needs to be awaited, but the code was iterating over it directly, causing "TypeError: 'coroutine' object is not iterable". Fixes SUPERVISOR-13D9 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -768,7 +768,7 @@ class DockerAPI(CoreSysAttributes):
|
|||||||
"""Import a tar file as image."""
|
"""Import a tar file as image."""
|
||||||
try:
|
try:
|
||||||
with tar_file.open("rb") as read_tar:
|
with tar_file.open("rb") as read_tar:
|
||||||
resp: list[dict[str, Any]] = self.images.import_image(read_tar)
|
resp: list[dict[str, Any]] = await self.images.import_image(read_tar)
|
||||||
except (aiodocker.DockerError, OSError) as err:
|
except (aiodocker.DockerError, OSError) as err:
|
||||||
raise DockerError(
|
raise DockerError(
|
||||||
f"Can't import image from tar: {err}", _LOGGER.error
|
f"Can't import image from tar: {err}", _LOGGER.error
|
||||||
|
|||||||
@@ -144,9 +144,9 @@ async def docker() -> DockerAPI:
|
|||||||
|
|
||||||
docker_images.inspect.return_value = image_inspect
|
docker_images.inspect.return_value = image_inspect
|
||||||
docker_images.list.return_value = [image_inspect]
|
docker_images.list.return_value = [image_inspect]
|
||||||
docker_images.import_image.return_value = [
|
docker_images.import_image = AsyncMock(
|
||||||
{"stream": "Loaded image: test:latest\n"}
|
return_value=[{"stream": "Loaded image: test:latest\n"}]
|
||||||
]
|
)
|
||||||
|
|
||||||
docker_images.pull.return_value = AsyncIterator([{}])
|
docker_images.pull.return_value = AsyncIterator([{}])
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
from docker.errors import APIError, DockerException, NotFound
|
from docker.errors import APIError, DockerException, NotFound
|
||||||
import pytest
|
import pytest
|
||||||
@@ -412,9 +412,9 @@ async def test_repair_failures(coresys: CoreSys, caplog: pytest.LogCaptureFixtur
|
|||||||
async def test_import_image(coresys: CoreSys, tmp_path: Path, log_starter: str):
|
async def test_import_image(coresys: CoreSys, tmp_path: Path, log_starter: str):
|
||||||
"""Test importing an image into docker."""
|
"""Test importing an image into docker."""
|
||||||
(test_tar := tmp_path / "test.tar").touch()
|
(test_tar := tmp_path / "test.tar").touch()
|
||||||
coresys.docker.images.import_image.return_value = [
|
coresys.docker.images.import_image = AsyncMock(
|
||||||
{"stream": f"{log_starter}: imported"}
|
return_value=[{"stream": f"{log_starter}: imported"}]
|
||||||
]
|
)
|
||||||
coresys.docker.images.inspect.return_value = {"Id": "imported"}
|
coresys.docker.images.inspect.return_value = {"Id": "imported"}
|
||||||
|
|
||||||
image = await coresys.docker.import_image(test_tar)
|
image = await coresys.docker.import_image(test_tar)
|
||||||
@@ -426,9 +426,9 @@ async def test_import_image(coresys: CoreSys, tmp_path: Path, log_starter: str):
|
|||||||
async def test_import_image_error(coresys: CoreSys, tmp_path: Path):
|
async def test_import_image_error(coresys: CoreSys, tmp_path: Path):
|
||||||
"""Test failure importing an image into docker."""
|
"""Test failure importing an image into docker."""
|
||||||
(test_tar := tmp_path / "test.tar").touch()
|
(test_tar := tmp_path / "test.tar").touch()
|
||||||
coresys.docker.images.import_image.return_value = [
|
coresys.docker.images.import_image = AsyncMock(
|
||||||
{"errorDetail": {"message": "fail"}}
|
return_value=[{"errorDetail": {"message": "fail"}}]
|
||||||
]
|
)
|
||||||
|
|
||||||
with pytest.raises(DockerError, match="Can't import image from tar: fail"):
|
with pytest.raises(DockerError, match="Can't import image from tar: fail"):
|
||||||
await coresys.docker.import_image(test_tar)
|
await coresys.docker.import_image(test_tar)
|
||||||
@@ -441,10 +441,12 @@ async def test_import_multiple_images_in_tar(
|
|||||||
):
|
):
|
||||||
"""Test importing an image into docker."""
|
"""Test importing an image into docker."""
|
||||||
(test_tar := tmp_path / "test.tar").touch()
|
(test_tar := tmp_path / "test.tar").touch()
|
||||||
coresys.docker.images.import_image.return_value = [
|
coresys.docker.images.import_image = AsyncMock(
|
||||||
|
return_value=[
|
||||||
{"stream": "Loaded image: imported-1"},
|
{"stream": "Loaded image: imported-1"},
|
||||||
{"stream": "Loaded image: imported-2"},
|
{"stream": "Loaded image: imported-2"},
|
||||||
]
|
]
|
||||||
|
)
|
||||||
|
|
||||||
assert await coresys.docker.import_image(test_tar) is None
|
assert await coresys.docker.import_image(test_tar) is None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user