Rename modules => hypervisor

This commit is contained in:
Julien Duponchelle committed 2016-03-08 16:12:46 +01:00
1 parent 6fa2491255
commit 3296b97f59
145 files changed
+308 -307

No files matched your search

+20 -20
View File
@@ -24,7 +24,7 @@ import aiohttp
from tests.utils import asyncio_patch
from unittest.mock import patch, MagicMock, PropertyMock
from gns3server.modules.docker import Docker
from gns3server.hypervisor.docker import Docker
@pytest.fixture
@@ -44,8 +44,8 @@ def mock_connection():
@pytest.fixture
def vm(http_hypervisor, project, base_params):
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "nginx"}]) as mock_list:
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value={"Id": "8bd8153ea8f5"}) as mock:
with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "nginx"}]) as mock_list:
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value={"Id": "8bd8153ea8f5"}) as mock:
response = http_hypervisor.post("/projects/{project_id}/docker/vms".format(project_id=project.id), base_params)
if response.status != 201:
print(response.body)
@@ -54,8 +54,8 @@ def vm(http_hypervisor, project, base_params):
def test_docker_create(http_hypervisor, project, base_params):
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "nginx"}]) as mock_list:
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value={"Id": "8bd8153ea8f5"}) as mock:
with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "nginx"}]) as mock_list:
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value={"Id": "8bd8153ea8f5"}) as mock:
response = http_hypervisor.post("/projects/{project_id}/docker/vms".format(project_id=project.id), base_params)
assert response.status == 201
assert response.route == "/projects/{project_id}/docker/vms"
@@ -68,35 +68,35 @@ def test_docker_create(http_hypervisor, project, base_params):
def test_docker_start(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.start", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.start", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
assert mock.called
assert response.status == 204
def test_docker_stop(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.stop", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.stop", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
assert mock.called
assert response.status == 204
def test_docker_reload(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.restart", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.restart", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
assert mock.called
assert response.status == 204
def test_docker_delete(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.delete", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.delete", return_value=True) as mock:
response = http_hypervisor.delete("/projects/{project_id}/docker/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
assert mock.called
assert response.status == 204
def test_docker_reload(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.pause", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.pause", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/suspend".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
assert mock.called
assert response.status == 204
@@ -114,14 +114,14 @@ def test_docker_nio_create_udp(http_hypervisor, vm):
def test_docker_delete_nio(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.adapter_remove_nio_binding") as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.adapter_remove_nio_binding") as mock:
response = http_hypervisor.delete("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert response.status == 204
assert response.route == "/projects/{project_id}/docker/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
def test_docker_update(http_hypervisor, vm, tmpdir, free_console_port):
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.update") as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.update") as mock:
response = http_hypervisor.put("/projects/{project_id}/docker/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"name": "test",
"console": free_console_port,
"start_command": "yes",
@@ -137,8 +137,8 @@ def test_docker_update(http_hypervisor, vm, tmpdir, free_console_port):
def test_docker_start_capture(http_hypervisor, vm, tmpdir, project):
with patch("gns3server.modules.docker.docker_vm.DockerVM.is_running", return_value=True) as mock:
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.start_capture") as start_capture:
with patch("gns3server.hypervisor.docker.docker_vm.DockerVM.is_running", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.start_capture") as start_capture:
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params, example=True)
@@ -151,8 +151,8 @@ def test_docker_start_capture(http_hypervisor, vm, tmpdir, project):
def test_docker_start_capture_not_started(http_hypervisor, vm, tmpdir):
with patch("gns3server.modules.docker.docker_vm.DockerVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.start_capture") as start_capture:
with patch("gns3server.hypervisor.docker.docker_vm.DockerVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.start_capture") as start_capture:
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params)
@@ -163,8 +163,8 @@ def test_docker_start_capture_not_started(http_hypervisor, vm, tmpdir):
def test_docker_stop_capture(http_hypervisor, vm, tmpdir, project):
with patch("gns3server.modules.docker.docker_vm.DockerVM.is_running", return_value=True) as mock:
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.stop_capture") as stop_capture:
with patch("gns3server.hypervisor.docker.docker_vm.DockerVM.is_running", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.stop_capture") as stop_capture:
response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
@@ -175,8 +175,8 @@ def test_docker_stop_capture(http_hypervisor, vm, tmpdir, project):
def test_docker_stop_capture_not_started(http_hypervisor, vm, tmpdir):
with patch("gns3server.modules.docker.docker_vm.DockerVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.modules.docker.docker_vm.DockerVM.stop_capture") as stop_capture:
with patch("gns3server.hypervisor.docker.docker_vm.DockerVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.DockerVM.stop_capture") as stop_capture:
response = http_hypervisor.post("/projects/{project_id}/docker/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
+12 -12
View File
@@ -27,7 +27,7 @@ from tests.utils import asyncio_patch
# def vm(http_hypervisor, project):
#
# dynamips_path = "/fake/dynamips"
# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.create", return_value=True) as mock:
# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.create", return_value=True) as mock:
# response = http_hypervisor.post("/projects/{project_id}/dynamips/vms".format(project_id=project.id), {"name": "My router",
# "platform": "c3745",
# "image": "somewhere",
@@ -35,13 +35,13 @@ from tests.utils import asyncio_patch
# assert mock.called
# assert response.status == 201
#
# with asyncio_patch("gns3server.modules.dynamips.Dynamips.find_dynamips", return_value=dynamips_path):
# with asyncio_patch("gns3server.hypervisor.dynamips.Dynamips.find_dynamips", return_value=dynamips_path):
# yield response.json
#
#
# def test_dynamips_vm_create(http_hypervisor, project):
#
# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.create", return_value=True):
# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.create", return_value=True):
# response = http_hypervisor.post("/projects/{project_id}/dynamips/vms".format(project_id=project.id), {"name": "My router",
# "platform": "c3745",
# "image": "somewhere",
@@ -62,28 +62,28 @@ from tests.utils import asyncio_patch
#
#
# def test_dynamips_vm_start(http_hypervisor, vm):
# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.start", return_value=True) as mock:
# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.start", return_value=True) as mock:
# response = http_hypervisor.post("/projects/{project_id}/dynamips/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
# assert mock.called
# assert response.status == 204
#
#
# def test_dynamips_vm_stop(http_hypervisor, vm):
# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.stop", return_value=True) as mock:
# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.stop", return_value=True) as mock:
# response = http_hypervisor.post("/projects/{project_id}/dynamips/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
# assert mock.called
# assert response.status == 204
#
#
# def test_dynamips_vm_suspend(http_hypervisor, vm):
# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.suspend", return_value=True) as mock:
# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.suspend", return_value=True) as mock:
# response = http_hypervisor.post("/projects/{project_id}/dynamips/vms/{vm_id}/suspend".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
# assert mock.called
# assert response.status == 204
#
#
# def test_dynamips_vm_resume(http_hypervisor, vm):
# with asyncio_patch("gns3server.modules.dynamips.nodes.router.Router.resume", return_value=True) as mock:
# with asyncio_patch("gns3server.hypervisor.dynamips.nodes.router.Router.resume", return_value=True) as mock:
# response = http_hypervisor.post("/projects/{project_id}/dynamips/vms/{vm_id}/resume".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
# assert mock.called
# assert response.status == 204
@@ -91,7 +91,7 @@ from tests.utils import asyncio_patch
# def test_vbox_nio_create_udp(http_hypervisor, vm):
#
# with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_add_nio_binding') as mock:
# with asyncio_patch('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_add_nio_binding') as mock:
# response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"],
# vm_id=vm["vm_id"]), {"type": "nio_udp",
# "lport": 4242,
@@ -110,7 +110,7 @@ from tests.utils import asyncio_patch
#
# def test_vbox_delete_nio(http_hypervisor, vm):
#
# with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_remove_nio_binding') as mock:
# with asyncio_patch('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_remove_nio_binding') as mock:
# response = http_hypervisor.delete("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
#
# assert mock.called
@@ -153,14 +153,14 @@ def fake_file(tmpdir):
def test_vms(http_hypervisor, tmpdir, fake_dynamips, fake_file):
with patch("gns3server.modules.Dynamips.get_images_directory", return_value=str(tmpdir), example=True):
with patch("gns3server.hypervisor.Dynamips.get_images_directory", return_value=str(tmpdir), example=True):
response = http_hypervisor.get("/dynamips/vms")
assert response.status == 200
assert response.json == [{"filename": "7200.bin", "path": "7200.bin"}]
def test_upload_vm(http_hypervisor, tmpdir):
with patch("gns3server.modules.Dynamips.get_images_directory", return_value=str(tmpdir),):
with patch("gns3server.hypervisor.Dynamips.get_images_directory", return_value=str(tmpdir),):
response = http_hypervisor.post("/dynamips/vms/test2", body="TEST", raw=True)
assert response.status == 204
@@ -177,6 +177,6 @@ def test_upload_vm_permission_denied(http_hypervisor, tmpdir):
f.write("")
os.chmod(str(tmpdir / "test2"), 0)
with patch("gns3server.modules.Dynamips.get_images_directory", return_value=str(tmpdir),):
with patch("gns3server.hypervisor.Dynamips.get_images_directory", return_value=str(tmpdir),):
response = http_hypervisor.post("/dynamips/vms/test2", body="TEST", raw=True)
assert response.status == 409
+17 -17
View File
@@ -136,7 +136,7 @@ def test_iou_get(http_hypervisor, project, vm):
def test_iou_start(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.start", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
assert mock.called
assert response.status == 200
@@ -146,7 +146,7 @@ def test_iou_start(http_hypervisor, vm):
def test_iou_start_with_iourc(http_hypervisor, vm, tmpdir):
body = {"iourc_content": "test"}
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.start", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=body, example=True)
assert mock.called
assert response.status == 200
@@ -158,21 +158,21 @@ def test_iou_start_with_iourc(http_hypervisor, vm, tmpdir):
def test_iou_stop(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.stop", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_iou_reload(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.reload", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.reload", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_iou_delete(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.iou.IOU.delete_vm", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.iou.IOU.delete_vm", return_value=True) as mock:
response = http_hypervisor.delete("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
@@ -242,7 +242,7 @@ def test_iou_nio_create_ethernet_different_port(http_hypervisor, vm, ethernet_de
def test_iou_nio_create_tap(http_hypervisor, vm, ethernet_device):
with patch("gns3server.modules.base_manager.BaseManager.has_privileged_access", return_value=True):
with patch("gns3server.hypervisor.base_manager.BaseManager.has_privileged_access", return_value=True):
response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap",
"tap_device": ethernet_device})
assert response.status == 201
@@ -262,8 +262,8 @@ def test_iou_delete_nio(http_hypervisor, vm):
def test_iou_start_capture(http_hypervisor, vm, tmpdir, project):
with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=True) as mock:
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start_capture") as start_capture:
with patch("gns3server.hypervisor.iou.iou_vm.IOUVM.is_running", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.start_capture") as start_capture:
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params, example=True)
@@ -276,8 +276,8 @@ def test_iou_start_capture(http_hypervisor, vm, tmpdir, project):
def test_iou_start_capture_not_started(http_hypervisor, vm, tmpdir):
with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start_capture") as start_capture:
with patch("gns3server.hypervisor.iou.iou_vm.IOUVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.start_capture") as start_capture:
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params)
@@ -288,8 +288,8 @@ def test_iou_start_capture_not_started(http_hypervisor, vm, tmpdir):
def test_iou_stop_capture(http_hypervisor, vm, tmpdir, project):
with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=True) as mock:
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop_capture") as stop_capture:
with patch("gns3server.hypervisor.iou.iou_vm.IOUVM.is_running", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.stop_capture") as stop_capture:
response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
@@ -300,8 +300,8 @@ def test_iou_stop_capture(http_hypervisor, vm, tmpdir, project):
def test_iou_stop_capture_not_started(http_hypervisor, vm, tmpdir):
with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop_capture") as stop_capture:
with patch("gns3server.hypervisor.iou.iou_vm.IOUVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM.stop_capture") as stop_capture:
response = http_hypervisor.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
@@ -330,14 +330,14 @@ def test_get_configs_with_startup_config_file(http_hypervisor, project, vm):
def test_vms(http_hypervisor, tmpdir, fake_iou_bin):
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir)):
with patch("gns3server.hypervisor.IOU.get_images_directory", return_value=str(tmpdir)):
response = http_hypervisor.get("/iou/vms", example=True)
assert response.status == 200
assert response.json == [{"filename": "iou.bin", "path": "iou.bin"}]
def test_upload_vm(http_hypervisor, tmpdir):
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir),):
with patch("gns3server.hypervisor.IOU.get_images_directory", return_value=str(tmpdir),):
response = http_hypervisor.post("/iou/vms/test2", body="TEST", raw=True)
assert response.status == 204
@@ -354,6 +354,6 @@ def test_upload_vm_permission_denied(http_hypervisor, tmpdir):
f.write("")
os.chmod(str(tmpdir / "test2"), 0)
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir),):
with patch("gns3server.hypervisor.IOU.get_images_directory", return_value=str(tmpdir),):
response = http_hypervisor.post("/iou/vms/test2", body="TEST", raw=True)
assert response.status == 409
+10 -10
View File
@@ -28,11 +28,11 @@ from unittest.mock import patch
from tests.utils import asyncio_patch
from gns3server.handlers.api.hypervisor.project_handler import ProjectHandler
from gns3server.modules.project_manager import ProjectManager
from gns3server.hypervisor.project_manager import ProjectManager
def test_create_project_with_path(http_hypervisor, tmpdir):
with patch("gns3server.modules.project.Project.is_local", return_value=True):
with patch("gns3server.hypervisor.project.Project.is_local", return_value=True):
response = http_hypervisor.post("/projects", {"name": "test", "path": str(tmpdir)})
assert response.status == 201
assert response.json["path"] == str(tmpdir)
@@ -114,7 +114,7 @@ def test_update_path_project_temporary(http_hypervisor, tmpdir):
os.makedirs(str(tmpdir / "a"))
os.makedirs(str(tmpdir / "b"))
with patch("gns3server.modules.project.Project.is_local", return_value=True):
with patch("gns3server.hypervisor.project.Project.is_local", return_value=True):
response = http_hypervisor.post("/projects", {"name": "first_name", "path": str(tmpdir / "a"), "temporary": True})
assert response.status == 201
assert response.json["name"] == "first_name"
@@ -133,7 +133,7 @@ def test_update_path_project_non_temporary(http_hypervisor, tmpdir):
os.makedirs(str(tmpdir / "a"))
os.makedirs(str(tmpdir / "b"))
with patch("gns3server.modules.project.Project.is_local", return_value=True):
with patch("gns3server.hypervisor.project.Project.is_local", return_value=True):
response = http_hypervisor.post("/projects", {"name": "first_name", "path": str(tmpdir / "a")})
assert response.status == 201
assert response.json["name"] == "first_name"
@@ -149,7 +149,7 @@ def test_update_path_project_non_temporary(http_hypervisor, tmpdir):
def test_update_path_project_non_local(http_hypervisor, tmpdir):
with patch("gns3server.modules.project.Project.is_local", return_value=False):
with patch("gns3server.hypervisor.project.Project.is_local", return_value=False):
response = http_hypervisor.post("/projects", {"name": "first_name"})
assert response.status == 201
query = {"name": "second_name", "path": str(tmpdir)}
@@ -158,7 +158,7 @@ def test_update_path_project_non_local(http_hypervisor, tmpdir):
def test_commit_project(http_hypervisor, project):
with asyncio_patch("gns3server.modules.project.Project.commit", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.project.Project.commit", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/commit".format(project_id=project.id), example=True)
assert response.status == 204
assert mock.called
@@ -170,7 +170,7 @@ def test_commit_project_invalid_uuid(http_hypervisor):
def test_delete_project(http_hypervisor, project):
with asyncio_patch("gns3server.modules.project.Project.delete", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.project.Project.delete", return_value=True) as mock:
response = http_hypervisor.delete("/projects/{project_id}".format(project_id=project.id), example=True)
assert response.status == 204
assert mock.called
@@ -182,7 +182,7 @@ def test_delete_project_invalid_uuid(http_hypervisor):
def test_close_project(http_hypervisor, project):
with asyncio_patch("gns3server.modules.project.Project.close", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.project.Project.close", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/close".format(project_id=project.id), example=True)
assert response.status == 204
assert mock.called
@@ -192,7 +192,7 @@ def test_close_project_two_client_connected(http_hypervisor, project):
ProjectHandler._notifications_listening = {project.id: 2}
with asyncio_patch("gns3server.modules.project.Project.close", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.project.Project.close", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/close".format(project_id=project.id), example=True)
assert response.status == 204
assert not mock.called
@@ -238,7 +238,7 @@ def test_list_files(http_hypervisor, project):
"md5sum": "098f6bcd4621d373cade4e832627b4f6"
}
]
with asyncio_patch("gns3server.modules.project.Project.list_files", return_value=files) as mock:
with asyncio_patch("gns3server.hypervisor.project.Project.list_files", return_value=files) as mock:
response = http_hypervisor.get("/projects/{project_id}/files".format(project_id=project.id), example=True)
assert response.status == 200
assert response.json == files
+16 -16
View File
@@ -112,7 +112,7 @@ def test_qemu_get(http_hypervisor, project, vm):
def test_qemu_start(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.start", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.start", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 200
@@ -120,35 +120,35 @@ def test_qemu_start(http_hypervisor, vm):
def test_qemu_stop(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.stop", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.stop", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_qemu_reload(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.reload", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.reload", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_qemu_suspend(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.suspend", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.suspend", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/suspend".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_qemu_resume(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.qemu.qemu_vm.QemuVM.resume", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.qemu.qemu_vm.QemuVM.resume", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/qemu/vms/{vm_id}/resume".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_qemu_delete(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.qemu.Qemu.delete_vm", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.qemu.Qemu.delete_vm", return_value=True) as mock:
response = http_hypervisor.delete("/projects/{project_id}/qemu/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
@@ -204,7 +204,7 @@ def test_qemu_delete_nio(http_hypervisor, vm):
def test_qemu_list_binaries(http_hypervisor, vm):
ret = [{"path": "/tmp/1", "version": "2.2.0"},
{"path": "/tmp/2", "version": "2.1.0"}]
with asyncio_patch("gns3server.modules.qemu.Qemu.binary_list", return_value=ret) as mock:
with asyncio_patch("gns3server.hypervisor.qemu.Qemu.binary_list", return_value=ret) as mock:
response = http_hypervisor.get("/qemu/binaries".format(project_id=vm["project_id"]), example=True)
assert mock.called_with(None)
assert response.status == 200
@@ -217,7 +217,7 @@ def test_qemu_list_binaries_filter(http_hypervisor, vm):
{"path": "/tmp/alpha", "version": "2.1.0"},
{"path": "/tmp/i386", "version": "2.1.0"}
]
with asyncio_patch("gns3server.modules.qemu.Qemu.binary_list", return_value=ret) as mock:
with asyncio_patch("gns3server.hypervisor.qemu.Qemu.binary_list", return_value=ret) as mock:
response = http_hypervisor.get("/qemu/binaries".format(project_id=vm["project_id"]), body={"archs": ["i386"]}, example=True)
assert response.status == 200
assert mock.called_with(["i386"])
@@ -232,7 +232,7 @@ def test_vms(http_hypervisor, tmpdir, fake_qemu_vm):
def test_upload_vm(http_hypervisor, tmpdir):
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir),):
with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir),):
response = http_hypervisor.post("/qemu/vms/test2", body="TEST", raw=True)
assert response.status == 204
@@ -245,7 +245,7 @@ def test_upload_vm(http_hypervisor, tmpdir):
def test_upload_vm_ova(http_hypervisor, tmpdir):
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir),):
with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir),):
response = http_hypervisor.post("/qemu/vms/test2.ova/test2.vmdk", body="TEST", raw=True)
assert response.status == 204
@@ -258,7 +258,7 @@ def test_upload_vm_ova(http_hypervisor, tmpdir):
def test_upload_vm_forbiden_location(http_hypervisor, tmpdir):
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir),):
with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir),):
response = http_hypervisor.post("/qemu/vms/../../test2", body="TEST", raw=True)
assert response.status == 403
@@ -268,7 +268,7 @@ def test_upload_vm_permission_denied(http_hypervisor, tmpdir):
f.write("")
os.chmod(str(tmpdir / "test2"), 0)
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir),):
with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir),):
response = http_hypervisor.post("/qemu/vms/test2", body="TEST", raw=True)
assert response.status == 409
@@ -284,7 +284,7 @@ def test_create_img_relative(http_hypervisor):
"lazy_refcounts": "off",
"size": 100
}
with asyncio_patch("gns3server.modules.Qemu.create_disk"):
with asyncio_patch("gns3server.hypervisor.Qemu.create_disk"):
response = http_hypervisor.post("/qemu/img", body=body, example=True)
assert response.status == 201
@@ -305,7 +305,7 @@ def test_create_img_absolute_non_local(http_hypervisor):
"lazy_refcounts": "off",
"size": 100
}
with asyncio_patch("gns3server.modules.Qemu.create_disk"):
with asyncio_patch("gns3server.hypervisor.Qemu.create_disk"):
response = http_hypervisor.post("/qemu/img", body=body, example=True)
assert response.status == 403
@@ -326,13 +326,13 @@ def test_create_img_absolute_local(http_hypervisor):
"lazy_refcounts": "off",
"size": 100
}
with asyncio_patch("gns3server.modules.Qemu.create_disk"):
with asyncio_patch("gns3server.hypervisor.Qemu.create_disk"):
response = http_hypervisor.post("/qemu/img", body=body, example=True)
assert response.status == 201
def test_capabilities(http_hypervisor):
with asyncio_patch("gns3server.modules.Qemu.get_kvm_archs", return_value=["x86_64"]):
with asyncio_patch("gns3server.hypervisor.Qemu.get_kvm_archs", return_value=["x86_64"]):
response = http_hypervisor.get("/qemu/capabilities", example=True)
assert response.json["kvm"] == ["x86_64"]
@@ -25,20 +25,20 @@ def vm(http_hypervisor, project, monkeypatch):
vboxmanage_path = "/fake/VboxManage"
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms".format(project_id=project.id), {"name": "VMTEST",
"vmname": "VMTEST",
"linked_clone": False})
assert mock.called
assert response.status == 201
with patch("gns3server.modules.virtualbox.VirtualBox.find_vboxmanage", return_value=vboxmanage_path):
with patch("gns3server.hypervisor.virtualbox.VirtualBox.find_vboxmanage", return_value=vboxmanage_path):
yield response.json
def test_vbox_create(http_hypervisor, project):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True):
with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True):
response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms".format(project_id=project.id), {"name": "VM1",
"vmname": "VM1",
"linked_clone": False},
@@ -57,36 +57,36 @@ def test_vbox_get(http_hypervisor, project, vm):
def test_vbox_start(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.check_hw_virtualization", return_value=True) as mock:
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.check_hw_virtualization", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_vbox_stop(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.stop", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.stop", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_vbox_suspend(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.suspend", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.suspend", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/suspend".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_vbox_resume(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.resume", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.resume", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/resume".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_vbox_reload(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.reload", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.reload", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
@@ -94,7 +94,7 @@ def test_vbox_reload(http_hypervisor, vm):
def test_vbox_nio_create_udp(http_hypervisor, vm):
with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_add_nio_binding') as mock:
with asyncio_patch('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_add_nio_binding') as mock:
response = http_hypervisor.post("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"],
vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242,
@@ -113,7 +113,7 @@ def test_vbox_nio_create_udp(http_hypervisor, vm):
def test_vbox_delete_nio(http_hypervisor, vm):
with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_remove_nio_binding') as mock:
with asyncio_patch('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_remove_nio_binding') as mock:
response = http_hypervisor.delete("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
+5 -5
View File
@@ -79,7 +79,7 @@ def test_vpcs_nio_create_udp(http_hypervisor, vm):
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_vpcs_nio_create_tap(http_hypervisor, vm, ethernet_device):
with patch("gns3server.modules.base_manager.BaseManager.has_privileged_access", return_value=True):
with patch("gns3server.hypervisor.base_manager.BaseManager.has_privileged_access", return_value=True):
response = http_hypervisor.post("/projects/{project_id}/vpcs/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap",
"tap_device": ethernet_device})
assert response.status == 201
@@ -99,7 +99,7 @@ def test_vpcs_delete_nio(http_hypervisor, vm):
def test_vpcs_start(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/vpcs/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 200
@@ -107,21 +107,21 @@ def test_vpcs_start(http_hypervisor, vm):
def test_vpcs_stop(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.stop", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.stop", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/vpcs/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_vpcs_reload(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.reload", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.reload", return_value=True) as mock:
response = http_hypervisor.post("/projects/{project_id}/vpcs/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204
def test_vpcs_delete(http_hypervisor, vm):
with asyncio_patch("gns3server.modules.vpcs.VPCS.delete_vm", return_value=True) as mock:
with asyncio_patch("gns3server.hypervisor.vpcs.VPCS.delete_vm", return_value=True) as mock:
response = http_hypervisor.delete("/projects/{project_id}/vpcs/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
assert response.status == 204