mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Handlers: cleanup and fixes.
This commit is contained in:
1 parent
885d93be02
commit
f81d35cc29
33 files changed
+723
-766
No files matched your search
@@ -71,7 +71,7 @@ def test_vboxmanage_path(manager, tmpdir):
|
||||
assert manager.find_vboxmanage() == path
|
||||
|
||||
|
||||
def test_list_images(manager, loop):
|
||||
def test_list_vms(manager, loop):
|
||||
vm_list = ['"Windows 8.1" {27b4d095-ff5f-4ac4-bb9d-5f2c7861c1f1}',
|
||||
'"Carriage',
|
||||
'Return" {27b4d095-ff5f-4ac4-bb9d-5f2c7861c1f1}',
|
||||
@@ -92,7 +92,7 @@ def test_list_images(manager, loop):
|
||||
|
||||
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute") as mock:
|
||||
mock.side_effect = execute_mock
|
||||
vms = loop.run_until_complete(asyncio.async(manager.list_images()))
|
||||
vms = loop.run_until_complete(asyncio.async(manager.list_vms()))
|
||||
assert vms == [
|
||||
{"vmname": "Windows 8.1", "ram": 512},
|
||||
{"vmname": "Linux Microcore 4.7.1", "ram": 256}
|
||||
|
||||
@@ -121,18 +121,18 @@ def test_addProject(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
uuid2 = str(uuid.uuid4())
|
||||
|
||||
async_run(controller.addProject(project_id=uuid1))
|
||||
async_run(controller.add_project(project_id=uuid1))
|
||||
assert len(controller.projects) == 1
|
||||
async_run(controller.addProject(project_id=uuid1))
|
||||
async_run(controller.add_project(project_id=uuid1))
|
||||
assert len(controller.projects) == 1
|
||||
async_run(controller.addProject(project_id=uuid2))
|
||||
async_run(controller.add_project(project_id=uuid2))
|
||||
assert len(controller.projects) == 2
|
||||
|
||||
|
||||
def test_remove_project(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
|
||||
project1 = async_run(controller.addProject(project_id=uuid1))
|
||||
project1 = async_run(controller.add_project(project_id=uuid1))
|
||||
assert len(controller.projects) == 1
|
||||
|
||||
controller.remove_project(project1)
|
||||
@@ -146,13 +146,13 @@ def test_addProject_with_compute(controller, async_run):
|
||||
compute.post = MagicMock()
|
||||
controller._computes = {"test1": compute}
|
||||
|
||||
project1 = async_run(controller.addProject(project_id=uuid1))
|
||||
project1 = async_run(controller.add_project(project_id=uuid1))
|
||||
|
||||
|
||||
def test_getProject(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
|
||||
project = async_run(controller.addProject(project_id=uuid1))
|
||||
project = async_run(controller.add_project(project_id=uuid1))
|
||||
assert controller.get_project(uuid1) == project
|
||||
with pytest.raises(aiohttp.web.HTTPNotFound):
|
||||
assert controller.get_project("dsdssd")
|
||||
|
||||
@@ -96,9 +96,16 @@ def test_docker_delete(http_compute, vm):
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_docker_reload(http_compute, vm):
|
||||
def test_docker_pause(http_compute, vm):
|
||||
with asyncio_patch("gns3server.compute.docker.docker_vm.DockerVM.pause", return_value=True) as mock:
|
||||
response = http_compute.post("/projects/{project_id}/docker/nodes/{node_id}/suspend".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
response = http_compute.post("/projects/{project_id}/docker/nodes/{node_id}/pause".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_docker_unpause(http_compute, vm):
|
||||
with asyncio_patch("gns3server.compute.docker.docker_vm.DockerVM.unpause", return_value=True) as mock:
|
||||
response = http_compute.post("/projects/{project_id}/docker/nodes/{node_id}/unpause".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
@@ -151,17 +151,17 @@ def fake_file(tmpdir):
|
||||
return path
|
||||
|
||||
|
||||
def test_vms(http_compute, tmpdir, fake_dynamips, fake_file):
|
||||
def test_images(http_compute, tmpdir, fake_dynamips, fake_file):
|
||||
|
||||
with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir), example=True):
|
||||
response = http_compute.get("/dynamips/nodes")
|
||||
response = http_compute.get("/dynamips/images")
|
||||
assert response.status == 200
|
||||
assert response.json == [{"filename": "7200.bin", "path": "7200.bin"}]
|
||||
|
||||
|
||||
def test_upload_vm(http_compute, tmpdir):
|
||||
def test_upload_image(http_compute, tmpdir):
|
||||
with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir),):
|
||||
response = http_compute.post("/dynamips/nodes/test2", body="TEST", raw=True)
|
||||
response = http_compute.post("/dynamips/images/test2", body="TEST", raw=True)
|
||||
assert response.status == 204
|
||||
|
||||
with open(str(tmpdir / "test2")) as f:
|
||||
@@ -172,11 +172,11 @@ def test_upload_vm(http_compute, tmpdir):
|
||||
assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf"
|
||||
|
||||
|
||||
def test_upload_vm_permission_denied(http_compute, tmpdir):
|
||||
def test_upload_image_permission_denied(http_compute, tmpdir):
|
||||
with open(str(tmpdir / "test2.tmp"), "w+") as f:
|
||||
f.write("")
|
||||
os.chmod(str(tmpdir / "test2.tmp"), 0)
|
||||
|
||||
with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir),):
|
||||
response = http_compute.post("/dynamips/nodes/test2", body="TEST", raw=True)
|
||||
response = http_compute.post("/dynamips/images/test2", body="TEST", raw=True)
|
||||
assert response.status == 409
|
||||
@@ -328,17 +328,17 @@ def test_get_configs_with_startup_config_file(http_compute, project, vm):
|
||||
assert response.json["startup_config_content"] == "TEST"
|
||||
|
||||
|
||||
def test_vms(http_compute, tmpdir, fake_iou_bin):
|
||||
def test_images(http_compute, tmpdir, fake_iou_bin):
|
||||
|
||||
with patch("gns3server.compute.IOU.get_images_directory", return_value=str(tmpdir)):
|
||||
response = http_compute.get("/iou/nodes", example=True)
|
||||
response = http_compute.get("/iou/images", example=True)
|
||||
assert response.status == 200
|
||||
assert response.json == [{"filename": "iou.bin", "path": "iou.bin"}]
|
||||
|
||||
|
||||
def test_upload_vm(http_compute, tmpdir):
|
||||
def test_image_vm(http_compute, tmpdir):
|
||||
with patch("gns3server.compute.IOU.get_images_directory", return_value=str(tmpdir),):
|
||||
response = http_compute.post("/iou/nodes/test2", body="TEST", raw=True)
|
||||
response = http_compute.post("/iou/images/test2", body="TEST", raw=True)
|
||||
assert response.status == 204
|
||||
|
||||
with open(str(tmpdir / "test2")) as f:
|
||||
|
||||
@@ -224,16 +224,16 @@ def test_qemu_list_binaries_filter(http_compute, vm):
|
||||
assert response.json == ret
|
||||
|
||||
|
||||
def test_vms(http_compute, tmpdir, fake_qemu_vm):
|
||||
def test_images(http_compute, tmpdir, fake_qemu_vm):
|
||||
|
||||
response = http_compute.get("/qemu/nodes")
|
||||
response = http_compute.get("/qemu/images")
|
||||
assert response.status == 200
|
||||
assert response.json == [{"filename": "linux载.img", "path": "linux载.img"}]
|
||||
|
||||
|
||||
def test_upload_vm(http_compute, tmpdir):
|
||||
def test_upload_image(http_compute, tmpdir):
|
||||
with patch("gns3server.compute.Qemu.get_images_directory", return_value=str(tmpdir),):
|
||||
response = http_compute.post("/qemu/nodes/test2", body="TEST", raw=True)
|
||||
response = http_compute.post("/qemu/images/test2", body="TEST", raw=True)
|
||||
assert response.status == 204
|
||||
|
||||
with open(str(tmpdir / "test2")) as f:
|
||||
@@ -244,9 +244,9 @@ def test_upload_vm(http_compute, tmpdir):
|
||||
assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf"
|
||||
|
||||
|
||||
def test_upload_vm_ova(http_compute, tmpdir):
|
||||
def test_upload_image_ova(http_compute, tmpdir):
|
||||
with patch("gns3server.compute.Qemu.get_images_directory", return_value=str(tmpdir),):
|
||||
response = http_compute.post("/qemu/nodes/test2.ova/test2.vmdk", body="TEST", raw=True)
|
||||
response = http_compute.post("/qemu/images/test2.ova/test2.vmdk", body="TEST", raw=True)
|
||||
assert response.status == 204
|
||||
|
||||
with open(str(tmpdir / "test2.ova" / "test2.vmdk")) as f:
|
||||
@@ -257,19 +257,19 @@ def test_upload_vm_ova(http_compute, tmpdir):
|
||||
assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf"
|
||||
|
||||
|
||||
def test_upload_vm_forbiden_location(http_compute, tmpdir):
|
||||
def test_upload_image_forbiden_location(http_compute, tmpdir):
|
||||
with patch("gns3server.compute.Qemu.get_images_directory", return_value=str(tmpdir),):
|
||||
response = http_compute.post("/qemu/nodes/../../test2", body="TEST", raw=True)
|
||||
response = http_compute.post("/qemu/images/../../test2", body="TEST", raw=True)
|
||||
assert response.status == 403
|
||||
|
||||
|
||||
def test_upload_vm_permission_denied(http_compute, tmpdir):
|
||||
def test_upload_image_permission_denied(http_compute, tmpdir):
|
||||
with open(str(tmpdir / "test2.tmp"), "w+") as f:
|
||||
f.write("")
|
||||
os.chmod(str(tmpdir / "test2.tmp"), 0)
|
||||
|
||||
with patch("gns3server.compute.Qemu.get_images_directory", return_value=str(tmpdir),):
|
||||
response = http_compute.post("/qemu/nodes/test2", body="TEST", raw=True)
|
||||
response = http_compute.post("/qemu/images/test2", body="TEST", raw=True)
|
||||
assert response.status == 409
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ def compute(http_controller, async_run):
|
||||
|
||||
@pytest.fixture
|
||||
def project(http_controller, async_run):
|
||||
return async_run(Controller.instance().addProject())
|
||||
return async_run(Controller.instance().add_project())
|
||||
|
||||
|
||||
def test_create_link(http_controller, tmpdir, project, compute, async_run):
|
||||
|
||||
@@ -44,7 +44,7 @@ def compute(http_controller, async_run):
|
||||
|
||||
@pytest.fixture
|
||||
def project(http_controller, async_run):
|
||||
return async_run(Controller.instance().addProject())
|
||||
return async_run(Controller.instance().add_project())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -103,7 +103,7 @@ def test_update_node(http_controller, tmpdir, project, compute, node):
|
||||
"startup_script": "echo test"
|
||||
}
|
||||
}, example=True)
|
||||
assert response.status == 201
|
||||
assert response.status == 200
|
||||
assert response.json["name"] == "test"
|
||||
assert "name" not in response.json["properties"]
|
||||
|
||||
@@ -113,17 +113,14 @@ def test_start_node(http_controller, tmpdir, project, compute, node):
|
||||
compute.post = AsyncioMagicMock()
|
||||
|
||||
response = http_controller.post("/projects/{}/nodes/{}/start".format(project.id, node.id), example=True)
|
||||
assert response.status == 201
|
||||
assert response.json["name"] == node.name
|
||||
|
||||
assert response.status == 204
|
||||
|
||||
def test_stop_node(http_controller, tmpdir, project, compute, node):
|
||||
response = MagicMock()
|
||||
compute.post = AsyncioMagicMock()
|
||||
|
||||
response = http_controller.post("/projects/{}/nodes/{}/stop".format(project.id, node.id), example=True)
|
||||
assert response.status == 201
|
||||
assert response.json["name"] == node.name
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_suspend_node(http_controller, tmpdir, project, compute, node):
|
||||
@@ -131,8 +128,7 @@ def test_suspend_node(http_controller, tmpdir, project, compute, node):
|
||||
compute.post = AsyncioMagicMock()
|
||||
|
||||
response = http_controller.post("/projects/{}/nodes/{}/suspend".format(project.id, node.id), example=True)
|
||||
assert response.status == 201
|
||||
assert response.json["name"] == node.name
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_reload_node(http_controller, tmpdir, project, compute, node):
|
||||
@@ -140,8 +136,7 @@ def test_reload_node(http_controller, tmpdir, project, compute, node):
|
||||
compute.post = AsyncioMagicMock()
|
||||
|
||||
response = http_controller.post("/projects/{}/nodes/{}/reload".format(project.id, node.id), example=True)
|
||||
assert response.status == 201
|
||||
assert response.json["name"] == node.name
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_delete_node(http_controller, tmpdir, project, compute, node):
|
||||
@@ -149,4 +144,4 @@ def test_delete_node(http_controller, tmpdir, project, compute, node):
|
||||
compute.post = AsyncioMagicMock()
|
||||
|
||||
response = http_controller.delete("/projects/{}/nodes/{}".format(project.id, node.id), example=True)
|
||||
assert response.status == 201
|
||||
assert response.status == 204
|
||||
@@ -33,7 +33,7 @@ def test_index(http_root):
|
||||
|
||||
|
||||
def test_controller(http_root, async_run):
|
||||
project = async_run(Controller.instance().addProject(name="test"))
|
||||
project = async_run(Controller.instance().add_project(name="test"))
|
||||
response = http_root.get('/controller')
|
||||
assert "test" in response.html
|
||||
assert response.status == 200
|
||||
@@ -45,7 +45,7 @@ def test_compute(http_root):
|
||||
|
||||
|
||||
def test_project(http_root, async_run):
|
||||
project = async_run(Controller.instance().addProject(name="test"))
|
||||
project = async_run(Controller.instance().add_project(name="test"))
|
||||
response = http_root.get('/projects/{}'.format(project.id))
|
||||
assert response.status == 200
|
||||
|
||||
|
||||
Reference in new issue
Block a user