mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-23 22:34:35 +02:00
api: list Docker image details and delete images
GET /computes/{compute_id}/docker/images now returns the daemon image
id, size and creation date in addition to the tag, so a UI can show
and compare images instead of bare names. The fields are optional to
keep the response compatible with older computes.
Add DELETE /computes/{compute_id}/docker/images/{image} which removes
the image from the compute Docker daemon. The image name is passed as
a path so names with a slash or a tag separator work. A daemon that
refuses because a container uses the image answers a conflict; the
force query parameter removes it anyway.
The compute also drops the controller digest to local id translation
recorded when the image was synced, since it no longer matches
anything on the daemon.
This commit is contained in:
7 files changed
+145
-7
No files matched your search
@@ -55,6 +55,25 @@ class TestImagesRoutes:
|
||||
assert hasattr(stream, "__aiter__")
|
||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||
|
||||
async def test_delete_docker_image(self, app: FastAPI, compute_client: AsyncClient) -> None:
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.delete_image") as mock:
|
||||
response = await compute_client.delete(
|
||||
app.url_path_for("compute:delete_docker_image", image="ios-xr/xrd-control-plane:24.4.1")
|
||||
)
|
||||
mock.assert_called_once_with("ios-xr/xrd-control-plane:24.4.1", force=False)
|
||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||
|
||||
async def test_delete_docker_image_force(self, app: FastAPI, compute_client: AsyncClient) -> None:
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.delete_image") as mock:
|
||||
response = await compute_client.delete(
|
||||
app.url_path_for("compute:delete_docker_image", image="ubuntu:latest"),
|
||||
params={"force": "true"},
|
||||
)
|
||||
mock.assert_called_once_with("ubuntu:latest", force=True)
|
||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||
|
||||
async def test_load_docker_image_with_image_and_digest(self, app: FastAPI, compute_client: AsyncClient) -> None:
|
||||
|
||||
digest = "sha256:" + "a" * 64
|
||||
|
||||
@@ -182,7 +182,10 @@ class TestComputeFeatures:
|
||||
) as mock:
|
||||
response = await client.get(app.url_path_for("docker_get_images", compute_id=compute_id))
|
||||
mock.assert_called_with("GET", "docker", "images")
|
||||
assert response.json() == [{"image": "docker1"}, {"image": "docker2"}]
|
||||
assert response.json() == [
|
||||
{"image": "docker1", "id": None, "size": None, "created": None},
|
||||
{"image": "docker2", "id": None, "size": None, "created": None},
|
||||
]
|
||||
|
||||
async def test_compute_pull_docker_image(self, app: FastAPI, client: AsyncClient, test_compute: Compute) -> None:
|
||||
|
||||
@@ -197,6 +200,27 @@ class TestComputeFeatures:
|
||||
compute.forward.assert_called_with("POST", "docker", "images/pull", data={"image": "nginx:latest"})
|
||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||
|
||||
async def test_compute_delete_docker_image(self, app: FastAPI, client: AsyncClient, test_compute: Compute) -> None:
|
||||
|
||||
compute = MagicMock()
|
||||
compute.http_query = AsyncioMagicMock(return_value={})
|
||||
with patch("gns3server.api.routes.controller.computes.Controller.instance") as controller:
|
||||
controller.return_value.get_compute.return_value = compute
|
||||
response = await client.delete(
|
||||
app.url_path_for(
|
||||
"docker_delete_image",
|
||||
compute_id=test_compute.compute_id,
|
||||
image="ios-xr/xrd-control-plane:24.4.1",
|
||||
),
|
||||
params={"force": True},
|
||||
)
|
||||
compute.http_query.assert_called_once_with(
|
||||
"DELETE",
|
||||
"/docker/images/ios-xr/xrd-control-plane:24.4.1",
|
||||
params={"force": "true"},
|
||||
)
|
||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||
|
||||
async def test_compute_load_docker_image(self, app: FastAPI, client: AsyncClient, test_compute: Compute) -> None:
|
||||
|
||||
compute = MagicMock()
|
||||
|
||||
Reference in new issue
Block a user