mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-20 13:15:14 +02:00
api: add controller endpoint to load Docker images on a compute
Add POST /computes/{compute_id}/docker/images/load. It streams an
uploaded docker save tar (plain or gzip) to the compute, which loads
it into its Docker daemon. Clients can now install image packages
such as iol-xe-17-18-02.tar.gz without SSH access to the server.
The body is proxied without buffering (async iterable to chunked
transfer) and runs with no total timeout, like the existing image
sync path between computes.
This commit is contained in:
2 files changed
+41
-1
No files matched your search
@@ -197,6 +197,26 @@ 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_load_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.post(
|
||||
app.url_path_for("docker_load_image", compute_id=test_compute.compute_id),
|
||||
content=b"docker save tar data",
|
||||
headers={"Content-Type": "application/octet-stream"},
|
||||
)
|
||||
compute.http_query.assert_called_once()
|
||||
args, kwargs = compute.http_query.call_args
|
||||
assert args[0] == "POST"
|
||||
assert args[1] == "docker/images/load"
|
||||
assert kwargs["timeout"] is None
|
||||
# the request body must be streamed, not buffered
|
||||
assert hasattr(kwargs["data"], "__aiter__")
|
||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||
|
||||
async def test_compute_list_virtualbox_vms(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
params = {"protocol": "http", "host": "localhost", "port": 4242, "user": "julien", "password": "secure"}
|
||||
|
||||
Reference in new issue
Block a user