mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 22:11:14 +02:00
Add controller endpoints to get VirtualBox VMs, VMware VMs and Docker images
This commit is contained in:
1 parent
3b7dfe5929
commit
7d49b80e6b
6 files changed
+91
-66
No files matched your search
@@ -109,7 +109,7 @@ class TestComputeRoutes:
|
||||
|
||||
class TestComputeFeatures:
|
||||
|
||||
async def test_compute_list_images(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
async def test_compute_list_docker_images(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
params = {
|
||||
"protocol": "http",
|
||||
@@ -123,12 +123,12 @@ class TestComputeFeatures:
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
compute_id = response.json()["compute_id"]
|
||||
|
||||
with asyncio_patch("gns3server.controller.compute.Compute.images", return_value=[{"filename": "linux.qcow2"}, {"filename": "asav.qcow2"}]) as mock:
|
||||
response = await client.get(app.url_path_for("delete_compute", compute_id=compute_id) + "/qemu/images")
|
||||
assert response.json() == [{"filename": "linux.qcow2"}, {"filename": "asav.qcow2"}]
|
||||
mock.assert_called_with("qemu")
|
||||
with asyncio_patch("gns3server.controller.compute.Compute.forward", return_value=[{"image": "docker1"}, {"image": "docker2"}]) 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"}]
|
||||
|
||||
async def test_compute_list_vms(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
async def test_compute_list_virtualbox_vms(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
params = {
|
||||
"protocol": "http",
|
||||
@@ -142,10 +142,28 @@ class TestComputeFeatures:
|
||||
compute_id = response.json()["compute_id"]
|
||||
|
||||
with asyncio_patch("gns3server.controller.compute.Compute.forward", return_value=[]) as mock:
|
||||
response = await client.get(app.url_path_for("get_compute", compute_id=compute_id) + "/virtualbox/vms")
|
||||
response = await client.get(app.url_path_for("virtualbox_vms", compute_id=compute_id))
|
||||
mock.assert_called_with("GET", "virtualbox", "vms")
|
||||
assert response.json() == []
|
||||
|
||||
async def test_compute_list_vmware_vms(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
params = {
|
||||
"protocol": "http",
|
||||
"host": "localhost",
|
||||
"port": 4243,
|
||||
"user": "julien",
|
||||
"password": "secure"
|
||||
}
|
||||
response = await client.post(app.url_path_for("get_computes"), json=params)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
compute_id = response.json()["compute_id"]
|
||||
|
||||
with asyncio_patch("gns3server.controller.compute.Compute.forward", return_value=[]) as mock:
|
||||
response = await client.get(app.url_path_for("vmware_vms", compute_id=compute_id))
|
||||
mock.assert_called_with("GET", "vmware", "vms")
|
||||
assert response.json() == []
|
||||
|
||||
async def test_compute_create_img(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
params = {
|
||||
|
||||
@@ -397,29 +397,6 @@ async def test_forward_post(compute):
|
||||
await compute.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_images(compute):
|
||||
"""
|
||||
Will return image on compute
|
||||
"""
|
||||
|
||||
response = MagicMock()
|
||||
response.status = 200
|
||||
response.read = AsyncioMagicMock(return_value=json.dumps([{
|
||||
"filename": "linux.qcow2",
|
||||
"path": "linux.qcow2",
|
||||
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
|
||||
"filesize": 0}]).encode())
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
images = await compute.images("qemu")
|
||||
mock.assert_called_with("GET", "https://example.com:84/v3/compute/qemu/images", auth=None, data=None, headers={'content-type': 'application/json'}, chunked=None, timeout=None)
|
||||
await compute.close()
|
||||
|
||||
assert images == [
|
||||
{"filename": "linux.qcow2", "path": "linux.qcow2", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "filesize": 0}
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_files(project, compute):
|
||||
|
||||
|
||||
Reference in new issue
Block a user