mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-05 14:51:13 +02:00
Rename modules => hypervisor
This commit is contained in:
145 files changed
+308
-307
No files matched your search
+5
-5
@@ -37,9 +37,9 @@ from gns3server.config import Config
|
||||
from gns3server.web.route import Route
|
||||
# TODO: get rid of *
|
||||
from gns3server.handlers import *
|
||||
from gns3server.modules import MODULES
|
||||
from gns3server.modules.port_manager import PortManager
|
||||
from gns3server.modules.project_manager import ProjectManager
|
||||
from gns3server.hypervisor import MODULES
|
||||
from gns3server.hypervisor.port_manager import PortManager
|
||||
from gns3server.hypervisor.project_manager import ProjectManager
|
||||
from gns3server.controller import Controller
|
||||
from tests.handlers.api.base import Query
|
||||
|
||||
@@ -96,7 +96,7 @@ def http_server(request, loop, port_manager, monkeypatch):
|
||||
def tear_down():
|
||||
for module in MODULES:
|
||||
instance = module.instance()
|
||||
monkeypatch.setattr('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.close', lambda self: True)
|
||||
monkeypatch.setattr('gns3server.hypervisor.virtualbox.virtualbox_vm.VirtualBoxVM.close', lambda self: True)
|
||||
loop.run_until_complete(instance.unload())
|
||||
srv.close()
|
||||
srv.wait_closed()
|
||||
@@ -195,7 +195,7 @@ def run_around_tests(monkeypatch, port_manager, controller):
|
||||
# Force turn off KVM because it's not available on CI
|
||||
config.set("Qemu", "enable_kvm", False)
|
||||
|
||||
monkeypatch.setattr("gns3server.modules.project.Project._get_default_project_directory", lambda *args: os.path.join(tmppath, 'projects'))
|
||||
monkeypatch.setattr("gns3server.hypervisor.project.Project._get_default_project_directory", lambda *args: os.path.join(tmppath, 'projects'))
|
||||
|
||||
# Force sys.platform to the original value. Because it seem not be restore correctly at each tests
|
||||
sys.platform = sys.original_platform
|
||||
|
||||
@@ -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"]))
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -20,8 +20,8 @@ import asyncio
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from tests.utils import asyncio_patch
|
||||
from gns3server.modules.docker import Docker
|
||||
from gns3server.modules.docker.docker_error import DockerError
|
||||
from gns3server.hypervisor.docker import Docker
|
||||
from gns3server.hypervisor.docker.docker_error import DockerError
|
||||
|
||||
|
||||
def test_query_success(loop):
|
||||
@@ -125,7 +125,7 @@ def test_list_images(loop):
|
||||
}
|
||||
]
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
images = loop.run_until_complete(asyncio.async(Docker.instance().list_images()))
|
||||
mock.assert_called_with("GET", "images/json", params={"all": 0})
|
||||
assert len(images) == 5
|
||||
+67
-67
@@ -22,9 +22,9 @@ import os
|
||||
from tests.utils import asyncio_patch, AsyncioMagicMock
|
||||
|
||||
from gns3server.ubridge.ubridge_error import UbridgeNamespaceError
|
||||
from gns3server.modules.docker.docker_vm import DockerVM
|
||||
from gns3server.modules.docker.docker_error import *
|
||||
from gns3server.modules.docker import Docker
|
||||
from gns3server.hypervisor.docker.docker_vm import DockerVM
|
||||
from gns3server.hypervisor.docker.docker_error import *
|
||||
from gns3server.hypervisor.docker import Docker
|
||||
from gns3server.utils.get_resource import get_resource
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ def test_create(loop, project, manager):
|
||||
"Id": "e90e34656806",
|
||||
"Warnings": []
|
||||
}
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
mock.assert_called_with("POST", "containers/create", data={
|
||||
@@ -89,7 +89,7 @@ def test_create(loop, project, manager):
|
||||
"HostConfig":
|
||||
{
|
||||
"CapAdd": ["ALL"],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))],
|
||||
"Privileged": True
|
||||
},
|
||||
"Volumes": {},
|
||||
@@ -110,8 +110,8 @@ def test_create_vnc(loop, project, manager):
|
||||
"Warnings": []
|
||||
}
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", console_type="vnc")
|
||||
vm._start_vnc = MagicMock()
|
||||
vm._display = 42
|
||||
@@ -124,7 +124,7 @@ def test_create_vnc(loop, project, manager):
|
||||
{
|
||||
"CapAdd": ["ALL"],
|
||||
"Binds": [
|
||||
"{}:/gns3:ro".format(get_resource("modules/docker/resources")),
|
||||
"{}:/gns3:ro".format(get_resource("hypervisor/docker/resources")),
|
||||
'/tmp/.X11-unix/:/tmp/.X11-unix/'
|
||||
],
|
||||
"Privileged": True
|
||||
@@ -147,8 +147,8 @@ def test_create_start_cmd(loop, project, manager):
|
||||
"Id": "e90e34656806",
|
||||
"Warnings": []
|
||||
}
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
||||
vm._start_command = "/bin/ls"
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
@@ -159,7 +159,7 @@ def test_create_start_cmd(loop, project, manager):
|
||||
"HostConfig":
|
||||
{
|
||||
"CapAdd": ["ALL"],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))],
|
||||
"Privileged": True
|
||||
},
|
||||
"Volumes": {},
|
||||
@@ -179,8 +179,8 @@ def test_create_environment(loop, project, manager):
|
||||
"Id": "e90e34656806",
|
||||
"Warnings": []
|
||||
}
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
||||
vm.environment = "YES=1\nNO=0"
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
@@ -191,7 +191,7 @@ def test_create_environment(loop, project, manager):
|
||||
"HostConfig":
|
||||
{
|
||||
"CapAdd": ["ALL"],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))],
|
||||
"Privileged": True
|
||||
},
|
||||
"Env": ["YES=1", "NO=0"],
|
||||
@@ -227,8 +227,8 @@ def test_create_image_not_available(loop, project, manager):
|
||||
vm._get_image_informations = MagicMock()
|
||||
vm._get_image_informations.side_effect = informations
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM.pull_image", return_value=True) as mock_pull:
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM.pull_image", return_value=True) as mock_pull:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
mock.assert_called_with("POST", "containers/create", data={
|
||||
"Tty": True,
|
||||
@@ -237,7 +237,7 @@ def test_create_image_not_available(loop, project, manager):
|
||||
"HostConfig":
|
||||
{
|
||||
"CapAdd": ["ALL"],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))],
|
||||
"Privileged": True
|
||||
},
|
||||
"Volumes": {},
|
||||
@@ -266,17 +266,17 @@ def test_get_container_state(loop, vm):
|
||||
"StartedAt": "2015-01-06T15:47:32.072697474Z"
|
||||
}
|
||||
}
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "running"
|
||||
|
||||
response["State"]["Running"] = False
|
||||
response["State"]["Paused"] = True
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "paused"
|
||||
|
||||
response["State"]["Running"] = False
|
||||
response["State"]["Paused"] = False
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "exited"
|
||||
|
||||
|
||||
@@ -287,17 +287,17 @@ def test_is_running(loop, vm):
|
||||
"Paused": False
|
||||
}
|
||||
}
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
assert loop.run_until_complete(asyncio.async(vm.is_running())) is False
|
||||
|
||||
response["State"]["Running"] = True
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
assert loop.run_until_complete(asyncio.async(vm.is_running())) is True
|
||||
|
||||
|
||||
def test_pause(loop, vm):
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock:
|
||||
loop.run_until_complete(asyncio.async(vm.pause()))
|
||||
|
||||
mock.assert_called_with("POST", "containers/e90e34656842/pause")
|
||||
@@ -306,7 +306,7 @@ def test_pause(loop, vm):
|
||||
|
||||
def test_unpause(loop, vm):
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock:
|
||||
loop.run_until_complete(asyncio.async(vm.unpause()))
|
||||
|
||||
mock.assert_called_with("POST", "containers/e90e34656842/unpause")
|
||||
@@ -329,7 +329,7 @@ def test_start(loop, vm, manager, free_console_port):
|
||||
nio = manager.create_nio(0, {"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query:
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
|
||||
mock_query.assert_called_with("POST", "containers/e90e34656842/start")
|
||||
@@ -348,12 +348,12 @@ def test_start_namespace_failed(loop, vm, manager, free_console_port):
|
||||
nio = manager.create_nio(0, {"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._start_ubridge") as mock_start_ubridge:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_namespace", return_value=42) as mock_namespace:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._add_ubridge_connection", side_effect=UbridgeNamespaceError()) as mock_add_ubridge_connection:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_log", return_value='Hello not available') as mock_log:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._start_ubridge") as mock_start_ubridge:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_namespace", return_value=42) as mock_namespace:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._add_ubridge_connection", side_effect=UbridgeNamespaceError()) as mock_add_ubridge_connection:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_log", return_value='Hello not available') as mock_log:
|
||||
|
||||
with pytest.raises(DockerError):
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
@@ -372,12 +372,12 @@ def test_start_without_nio(loop, vm, manager, free_console_port):
|
||||
assert vm.status != "started"
|
||||
vm.adapters = 1
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._start_ubridge") as mock_start_ubridge:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_namespace", return_value=42) as mock_namespace:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._add_ubridge_connection") as mock_add_ubridge_connection:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._start_console") as mock_start_console:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._start_ubridge") as mock_start_ubridge:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_namespace", return_value=42) as mock_namespace:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._add_ubridge_connection") as mock_add_ubridge_connection:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._start_console") as mock_start_console:
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
|
||||
mock_query.assert_called_with("POST", "containers/e90e34656842/start")
|
||||
@@ -389,8 +389,8 @@ def test_start_without_nio(loop, vm, manager, free_console_port):
|
||||
|
||||
def test_start_unpause(loop, vm, manager, free_console_port):
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="paused"):
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM.unpause", return_value="paused") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="paused"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM.unpause", return_value="paused") as mock:
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert mock.called
|
||||
assert vm.status == "started"
|
||||
@@ -398,7 +398,7 @@ def test_start_unpause(loop, vm, manager, free_console_port):
|
||||
|
||||
def test_restart(loop, vm):
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock:
|
||||
loop.run_until_complete(asyncio.async(vm.restart()))
|
||||
|
||||
mock.assert_called_with("POST", "containers/e90e34656842/restart")
|
||||
@@ -408,8 +408,8 @@ def test_stop(loop, vm):
|
||||
vm._ubridge_hypervisor = MagicMock()
|
||||
vm._ubridge_hypervisor.is_running.return_value = True
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="running"):
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="running"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query:
|
||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
||||
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
|
||||
assert vm._ubridge_hypervisor.stop.called
|
||||
@@ -417,9 +417,9 @@ def test_stop(loop, vm):
|
||||
|
||||
def test_stop_paused_container(loop, vm):
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="paused"):
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM.unpause") as mock_unpause:
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="paused"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM.unpause") as mock_unpause:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query:
|
||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
||||
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
|
||||
assert mock_unpause.called
|
||||
@@ -434,9 +434,9 @@ def test_update(loop, vm):
|
||||
|
||||
original_console = vm.console
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock_query:
|
||||
loop.run_until_complete(asyncio.async(vm.update()))
|
||||
|
||||
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1})
|
||||
@@ -447,7 +447,7 @@ def test_update(loop, vm):
|
||||
"HostConfig":
|
||||
{
|
||||
"CapAdd": ["ALL"],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))],
|
||||
"Privileged": True
|
||||
},
|
||||
"Volumes": {},
|
||||
@@ -471,9 +471,9 @@ def test_update_running(loop, vm):
|
||||
original_console = vm.console
|
||||
vm.start = MagicMock()
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="running"):
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="running"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock_query:
|
||||
loop.run_until_complete(asyncio.async(vm.update()))
|
||||
|
||||
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1})
|
||||
@@ -484,7 +484,7 @@ def test_update_running(loop, vm):
|
||||
"HostConfig":
|
||||
{
|
||||
"CapAdd": ["ALL"],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("modules/docker/resources"))],
|
||||
"Binds": ["{}:/gns3:ro".format(get_resource("hypervisor/docker/resources"))],
|
||||
"Privileged": True
|
||||
},
|
||||
"Volumes": {},
|
||||
@@ -502,8 +502,8 @@ def test_update_running(loop, vm):
|
||||
|
||||
def test_delete(loop, vm):
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query:
|
||||
loop.run_until_complete(asyncio.async(vm.delete()))
|
||||
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1})
|
||||
|
||||
@@ -516,8 +516,8 @@ def test_close(loop, vm, port_manager):
|
||||
nio = vm.manager.create_nio(0, nio)
|
||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query:
|
||||
loop.run_until_complete(asyncio.async(vm.close()))
|
||||
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1})
|
||||
|
||||
@@ -531,8 +531,8 @@ def test_close_vnc(loop, vm, port_manager):
|
||||
vm._x11vnc_process = MagicMock()
|
||||
vm._xvfb_process = MagicMock()
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query") as mock_query:
|
||||
loop.run_until_complete(asyncio.async(vm.close()))
|
||||
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1})
|
||||
|
||||
@@ -546,7 +546,7 @@ def test_get_namespace(loop, vm):
|
||||
"Pid": 42
|
||||
}
|
||||
}
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock_query:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock_query:
|
||||
assert loop.run_until_complete(asyncio.async(vm._get_namespace())) == 42
|
||||
mock_query.assert_called_with("GET", "containers/e90e34656842/json")
|
||||
|
||||
@@ -664,7 +664,7 @@ def test_adapter_remove_nio_binding(vm, loop):
|
||||
"rhost": "127.0.0.1"}
|
||||
nio = vm.manager.create_nio(0, nio)
|
||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
||||
with asyncio_patch("gns3server.modules.docker.DockerVM._delete_ubridge_connection") as delete_ubridge_mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.DockerVM._delete_ubridge_connection") as delete_ubridge_mock:
|
||||
loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(0)))
|
||||
assert vm._ethernet_adapters[0].get_nio(0) is None
|
||||
delete_ubridge_mock.assert_called_with(0)
|
||||
@@ -697,7 +697,7 @@ def test_pull_image(loop, vm):
|
||||
mock_query = MagicMock()
|
||||
mock_query.content.return_value = Response()
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.http_query", return_value=mock_query) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.http_query", return_value=mock_query) as mock:
|
||||
images = loop.run_until_complete(asyncio.async(vm.pull_image("ubuntu")))
|
||||
mock.assert_called_with("POST", "images/create", params={"fromImage": "ubuntu"})
|
||||
|
||||
@@ -730,7 +730,7 @@ def test_get_log(loop, vm):
|
||||
mock_query = MagicMock()
|
||||
mock_query.read = read
|
||||
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.http_query", return_value=mock_query) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.http_query", return_value=mock_query) as mock:
|
||||
images = loop.run_until_complete(asyncio.async(vm._get_log()))
|
||||
mock.assert_called_with("GET", "containers/e90e34656842/logs", params={"stderr": 1, "stdout": 1}, data={})
|
||||
|
||||
@@ -738,7 +738,7 @@ def test_get_log(loop, vm):
|
||||
def test_get_image_informations(project, manager, loop):
|
||||
response = {
|
||||
}
|
||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.Docker.query", return_value=response) as mock:
|
||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
||||
loop.run_until_complete(asyncio.async(vm._get_image_informations()))
|
||||
mock.assert_called_with("GET", "images/ubuntu/json")
|
||||
@@ -755,7 +755,7 @@ def test_mount_binds(vm, tmpdir):
|
||||
|
||||
dst = os.path.join(vm.working_dir, "test/experimental")
|
||||
assert vm._mount_binds(image_infos) == [
|
||||
"{}:/gns3:ro".format(get_resource("modules/docker/resources")),
|
||||
"{}:/gns3:ro".format(get_resource("hypervisor/docker/resources")),
|
||||
"{}:{}".format(dst, "/test/experimental")
|
||||
]
|
||||
|
||||
@@ -764,7 +764,7 @@ def test_mount_binds(vm, tmpdir):
|
||||
|
||||
def test_start_vnc(vm, loop):
|
||||
with patch("shutil.which", return_value="/bin/x"):
|
||||
with asyncio_patch("gns3server.modules.docker.docker_vm.wait_for_file_creation") as mock_wait:
|
||||
with asyncio_patch("gns3server.hypervisor.docker.docker_vm.wait_for_file_creation") as mock_wait:
|
||||
with asyncio_patch("asyncio.create_subprocess_exec") as mock_exec:
|
||||
loop.run_until_complete(asyncio.async(vm._start_vnc()))
|
||||
assert vm._display is not None
|
||||
+2
-2
@@ -23,8 +23,8 @@ import uuid
|
||||
import os
|
||||
import asyncio
|
||||
|
||||
from gns3server.modules.dynamips import Dynamips
|
||||
from gns3server.modules.dynamips.dynamips_error import DynamipsError
|
||||
from gns3server.hypervisor.dynamips import Dynamips
|
||||
from gns3server.hypervisor.dynamips.dynamips_error import DynamipsError
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
+3
-3
@@ -20,9 +20,9 @@ import asyncio
|
||||
import configparser
|
||||
|
||||
from unittest.mock import patch
|
||||
from gns3server.modules.dynamips.nodes.router import Router
|
||||
from gns3server.modules.dynamips.dynamips_error import DynamipsError
|
||||
from gns3server.modules.dynamips import Dynamips
|
||||
from gns3server.hypervisor.dynamips.nodes.router import Router
|
||||
from gns3server.hypervisor.dynamips.dynamips_error import DynamipsError
|
||||
from gns3server.hypervisor.dynamips import Dynamips
|
||||
from gns3server.config import Config
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ import sys
|
||||
pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
|
||||
if not sys.platform.startswith("win"):
|
||||
from gns3server.modules.iou import IOU
|
||||
from gns3server.modules.iou.iou_error import IOUError
|
||||
from gns3server.hypervisor.iou import IOU
|
||||
from gns3server.hypervisor.iou.iou_error import IOUError
|
||||
|
||||
from gns3server.modules.project_manager import ProjectManager
|
||||
from gns3server.hypervisor.project_manager import ProjectManager
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@@ -32,9 +32,9 @@ from unittest.mock import patch, MagicMock, PropertyMock
|
||||
pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
|
||||
if not sys.platform.startswith("win"):
|
||||
from gns3server.modules.iou.iou_vm import IOUVM
|
||||
from gns3server.modules.iou.iou_error import IOUError
|
||||
from gns3server.modules.iou import IOU
|
||||
from gns3server.hypervisor.iou.iou_vm import IOUVM
|
||||
from gns3server.hypervisor.iou.iou_error import IOUError
|
||||
from gns3server.hypervisor.iou import IOU
|
||||
|
||||
from gns3server.config import Config
|
||||
|
||||
@@ -108,16 +108,17 @@ def test_vm_invalid_iouyap_path(project, manager, loop, fake_iou_bin):
|
||||
def test_start(loop, vm, monkeypatch):
|
||||
|
||||
mock_process = MagicMock()
|
||||
with patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_iou_licence", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_iou_licence", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as mock_exec:
|
||||
mock_process.returncode = None
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert vm.is_running()
|
||||
assert vm.command_line == ' '.join(mock_exec.call_args[0])
|
||||
|
||||
|
||||
def test_start_with_iourc(loop, vm, monkeypatch, tmpdir):
|
||||
|
||||
fake_file = str(tmpdir / "iourc")
|
||||
@@ -125,10 +126,10 @@ def test_start_with_iourc(loop, vm, monkeypatch, tmpdir):
|
||||
f.write("1")
|
||||
mock_process = MagicMock()
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"iourc_path": fake_file, "iouyap_path": vm.iouyap_path}):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_iou_licence", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_iou_licence", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as exec_mock:
|
||||
mock_process.returncode = None
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
@@ -161,9 +162,9 @@ def test_stop(loop, vm):
|
||||
future.set_result(True)
|
||||
process.wait.return_value = future
|
||||
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
@@ -183,9 +184,9 @@ def test_reload(loop, vm, fake_iou_bin):
|
||||
process.wait.return_value = future
|
||||
process.returncode = None
|
||||
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
@@ -196,7 +197,7 @@ def test_reload(loop, vm, fake_iou_bin):
|
||||
|
||||
|
||||
def test_close(vm, port_manager, loop):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
vm.start()
|
||||
port = vm.console
|
||||
+7
-7
@@ -22,8 +22,8 @@ import sys
|
||||
import pytest
|
||||
import platform
|
||||
|
||||
from gns3server.modules.qemu import Qemu
|
||||
from gns3server.modules.qemu.qemu_error import QemuError
|
||||
from gns3server.hypervisor.qemu import Qemu
|
||||
from gns3server.hypervisor.qemu.qemu_error import QemuError
|
||||
from tests.utils import asyncio_patch
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
@@ -40,7 +40,7 @@ def fake_qemu_img_binary(tmpdir):
|
||||
|
||||
def test_get_qemu_version(loop):
|
||||
|
||||
with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
|
||||
version = loop.run_until_complete(asyncio.async(Qemu.get_qemu_version("/tmp/qemu-test")))
|
||||
if sys.platform.startswith("win"):
|
||||
assert version == ""
|
||||
@@ -58,7 +58,7 @@ def test_binary_list(loop):
|
||||
f.write("1")
|
||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||
|
||||
with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
|
||||
if sys.platform.startswith("win"):
|
||||
version = ""
|
||||
else:
|
||||
@@ -97,7 +97,7 @@ def test_img_binary_list(loop):
|
||||
f.write("1")
|
||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||
|
||||
with asyncio_patch("gns3server.modules.qemu.subprocess_check_output", return_value="qemu-img version 2.2.0, Copyright (c) 2004-2008 Fabrice Bellard") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.qemu.subprocess_check_output", return_value="qemu-img version 2.2.0, Copyright (c) 2004-2008 Fabrice Bellard") as mock:
|
||||
qemus = loop.run_until_complete(asyncio.async(Qemu.img_binary_list()))
|
||||
|
||||
version = "2.2.0"
|
||||
@@ -151,7 +151,7 @@ def test_create_image_relative_path(loop, tmpdir, fake_qemu_img_binary):
|
||||
"size": 100
|
||||
}
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||
with patch("gns3server.modules.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||
with patch("gns3server.hypervisor.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
|
||||
args, kwargs = process.call_args
|
||||
assert args == (
|
||||
@@ -172,7 +172,7 @@ def test_create_image_exist(loop, tmpdir, fake_qemu_img_binary):
|
||||
"size": 100
|
||||
}
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||
with patch("gns3server.modules.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||
with patch("gns3server.hypervisor.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||
with pytest.raises(QemuError):
|
||||
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
|
||||
assert not process.called
|
||||
@@ -28,9 +28,9 @@ from tests.utils import asyncio_patch
|
||||
from unittest import mock
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from gns3server.modules.qemu.qemu_vm import QemuVM
|
||||
from gns3server.modules.qemu.qemu_error import QemuError
|
||||
from gns3server.modules.qemu import Qemu
|
||||
from gns3server.hypervisor.qemu.qemu_vm import QemuVM
|
||||
from gns3server.hypervisor.qemu.qemu_error import QemuError
|
||||
from gns3server.hypervisor.qemu import Qemu
|
||||
from gns3server.utils import force_unix_path
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ def test_termination_callback_error(vm, tmpdir):
|
||||
|
||||
def test_reload(loop, vm):
|
||||
|
||||
with asyncio_patch("gns3server.modules.qemu.QemuVM._control_vm") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.qemu.QemuVM._control_vm") as mock:
|
||||
loop.run_until_complete(asyncio.async(vm.reload()))
|
||||
assert mock.called_with("system_reset")
|
||||
|
||||
@@ -184,7 +184,7 @@ def test_suspend(loop, vm):
|
||||
|
||||
control_vm_result = MagicMock()
|
||||
control_vm_result.match.group.decode.return_value = "running"
|
||||
with asyncio_patch("gns3server.modules.qemu.QemuVM._control_vm", return_value=control_vm_result) as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.qemu.QemuVM._control_vm", return_value=control_vm_result) as mock:
|
||||
loop.run_until_complete(asyncio.async(vm.suspend()))
|
||||
assert mock.called_with("system_reset")
|
||||
|
||||
@@ -197,7 +197,7 @@ def test_add_nio_binding_udp(vm, loop):
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
def test_add_nio_binding_ethernet(vm, loop, 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):
|
||||
nio = Qemu.instance().create_nio(vm.qemu_path, {"type": "nio_generic_ethernet", "ethernet_device": ethernet_device})
|
||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
||||
assert nio.ethernet_device == ethernet_device
|
||||
@@ -305,7 +305,7 @@ def test_set_qemu_path_kvm_binary(vm, tmpdir, fake_qemu_binary):
|
||||
def test_set_platform(project, manager):
|
||||
|
||||
with patch("shutil.which", return_value="/bin/qemu-system-x86_64") as which_mock:
|
||||
with patch("gns3server.modules.qemu.QemuVM._check_qemu_path"):
|
||||
with patch("gns3server.hypervisor.qemu.QemuVM._check_qemu_path"):
|
||||
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, platform="x86_64")
|
||||
if sys.platform.startswith("win"):
|
||||
which_mock.assert_called_with("qemu-system-x86_64w.exe", path=mock.ANY)
|
||||
@@ -480,7 +480,7 @@ def test_initrd(vm, tmpdir):
|
||||
|
||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
||||
|
||||
with patch("gns3server.modules.project.Project.emit") as mock:
|
||||
with patch("gns3server.hypervisor.project.Project.emit") as mock:
|
||||
vm.initrd = str(tmpdir / "test")
|
||||
assert vm.initrd == force_unix_path(str(tmpdir / "test"))
|
||||
vm.initrd = "test"
|
||||
@@ -492,7 +492,7 @@ def test_initrd_asa(vm, tmpdir):
|
||||
|
||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
||||
|
||||
with patch("gns3server.modules.project.Project.emit") as mock:
|
||||
with patch("gns3server.hypervisor.project.Project.emit") as mock:
|
||||
vm.initrd = str(tmpdir / "asa842-initrd.gz")
|
||||
assert vm.initrd == force_unix_path(str(tmpdir / "asa842-initrd.gz"))
|
||||
vm.initrd = "asa842-initrd.gz"
|
||||
@@ -23,11 +23,11 @@ from tests.utils import asyncio_patch
|
||||
|
||||
|
||||
from unittest.mock import patch, MagicMock
|
||||
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
|
||||
from gns3server.modules.docker.docker_vm import DockerVM
|
||||
from gns3server.modules.vpcs.vpcs_error import VPCSError
|
||||
from gns3server.modules.vm_error import VMError
|
||||
from gns3server.modules.vpcs import VPCS
|
||||
from gns3server.hypervisor.vpcs.vpcs_vm import VPCSVM
|
||||
from gns3server.hypervisor.docker.docker_vm import DockerVM
|
||||
from gns3server.hypervisor.vpcs.vpcs_error import VPCSError
|
||||
from gns3server.hypervisor.vm_error import VMError
|
||||
from gns3server.hypervisor.vpcs import VPCS
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@@ -21,9 +21,9 @@ import pytest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
from gns3server.modules.vpcs import VPCS
|
||||
from gns3server.modules.qemu import Qemu
|
||||
from gns3server.modules.vm_error import VMError
|
||||
from gns3server.hypervisor.vpcs import VPCS
|
||||
from gns3server.hypervisor.qemu import Qemu
|
||||
from gns3server.hypervisor.vm_error import VMError
|
||||
from gns3server.utils import force_unix_path
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ def test_create_vm_new_topology_without_uuid(loop, project, vpcs):
|
||||
|
||||
def test_create_vm_old_topology(loop, project, tmpdir, vpcs):
|
||||
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
with patch("gns3server.hypervisor.project.Project.is_local", return_value=True):
|
||||
# Create an old topology directory
|
||||
project_dir = str(tmpdir / "testold")
|
||||
vm_dir = os.path.join(project_dir, "testold-files", "vpcs", "pc-1")
|
||||
@@ -158,7 +158,7 @@ def test_list_images(loop, qemu, tmpdir):
|
||||
with open(str(tmpdir / image), "w+") as f:
|
||||
f.write("1")
|
||||
|
||||
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||
with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||
assert loop.run_until_complete(qemu.list_images()) == [
|
||||
{"filename": "a.bin", "path": "a.bin"},
|
||||
{"filename": "b.bin", "path": "b.bin"}
|
||||
@@ -177,7 +177,7 @@ def test_list_images_recursives(loop, qemu, tmpdir):
|
||||
with open(str(tmpdir / "c" / image), "w+") as f:
|
||||
f.write("1")
|
||||
|
||||
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||
with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||
assert loop.run_until_complete(qemu.list_images()) == [
|
||||
{"filename": "a.bin", "path": "a.bin"},
|
||||
{"filename": "b.bin", "path": "b.bin"},
|
||||
@@ -186,10 +186,10 @@ def test_list_images_recursives(loop, qemu, tmpdir):
|
||||
|
||||
|
||||
def test_list_images_empty(loop, qemu, 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)):
|
||||
assert loop.run_until_complete(qemu.list_images()) == []
|
||||
|
||||
|
||||
def test_list_images_directory_not_exist(loop, qemu):
|
||||
with patch("gns3server.modules.Qemu.get_images_directory", return_value="/bla"):
|
||||
with patch("gns3server.hypervisor.Qemu.get_images_directory", return_value="/bla"):
|
||||
assert loop.run_until_complete(qemu.list_images()) == []
|
||||
@@ -19,15 +19,15 @@ import aiohttp
|
||||
import pytest
|
||||
import sys
|
||||
from unittest.mock import patch
|
||||
from gns3server.modules.port_manager import PortManager
|
||||
from gns3server.modules.project import Project
|
||||
from gns3server.hypervisor.port_manager import PortManager
|
||||
from gns3server.hypervisor.project import Project
|
||||
|
||||
|
||||
def test_reserve_tcp_port():
|
||||
pm = PortManager()
|
||||
project = Project()
|
||||
pm.reserve_tcp_port(2001, project)
|
||||
with patch("gns3server.modules.project.Project.emit") as mock_emit:
|
||||
with patch("gns3server.hypervisor.project.Project.emit") as mock_emit:
|
||||
port = pm.reserve_tcp_port(2001, project)
|
||||
assert port != 2001
|
||||
assert mock_emit.call_args[0][0] == "log.warning"
|
||||
@@ -36,7 +36,7 @@ def test_reserve_tcp_port():
|
||||
def test_reserve_tcp_port_outside_range():
|
||||
pm = PortManager()
|
||||
project = Project()
|
||||
with patch("gns3server.modules.project.Project.emit") as mock_emit:
|
||||
with patch("gns3server.hypervisor.project.Project.emit") as mock_emit:
|
||||
port = pm.reserve_tcp_port(80, project)
|
||||
assert port != 80
|
||||
assert mock_emit.call_args[0][0] == "log.warning"
|
||||
@@ -50,7 +50,7 @@ def test_reserve_tcp_port_already_used_by_another_program():
|
||||
|
||||
pm = PortManager()
|
||||
project = Project()
|
||||
with patch("gns3server.modules.port_manager.PortManager._check_port") as mock_check:
|
||||
with patch("gns3server.hypervisor.port_manager.PortManager._check_port") as mock_check:
|
||||
|
||||
def execute_mock(host, port, *args):
|
||||
if port == 2001:
|
||||
@@ -60,7 +60,7 @@ def test_reserve_tcp_port_already_used_by_another_program():
|
||||
|
||||
mock_check.side_effect = execute_mock
|
||||
|
||||
with patch("gns3server.modules.project.Project.emit") as mock_emit:
|
||||
with patch("gns3server.hypervisor.project.Project.emit") as mock_emit:
|
||||
port = pm.reserve_tcp_port(2001, project)
|
||||
assert port != 2001
|
||||
assert mock_emit.call_args[0][0] == "log.warning"
|
||||
@@ -74,7 +74,7 @@ def test_reserve_tcp_port_already_used():
|
||||
|
||||
pm = PortManager()
|
||||
project = Project()
|
||||
with patch("gns3server.modules.port_manager.PortManager._check_port") as mock_check:
|
||||
with patch("gns3server.hypervisor.port_manager.PortManager._check_port") as mock_check:
|
||||
|
||||
def execute_mock(host, port, *args):
|
||||
if port == 2001:
|
||||
@@ -84,7 +84,7 @@ def test_reserve_tcp_port_already_used():
|
||||
|
||||
mock_check.side_effect = execute_mock
|
||||
|
||||
with patch("gns3server.modules.project.Project.emit") as mock_emit:
|
||||
with patch("gns3server.hypervisor.project.Project.emit") as mock_emit:
|
||||
port = pm.reserve_tcp_port(2001, project)
|
||||
assert port != 2001
|
||||
assert mock_emit.call_args[0][0] == "log.warning"
|
||||
@@ -24,8 +24,8 @@ from uuid import uuid4
|
||||
from unittest.mock import patch
|
||||
|
||||
from tests.utils import asyncio_patch
|
||||
from gns3server.modules.project import Project
|
||||
from gns3server.modules.vpcs import VPCS, VPCSVM
|
||||
from gns3server.hypervisor.project import Project
|
||||
from gns3server.hypervisor.vpcs import VPCS, VPCSVM
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@@ -50,7 +50,7 @@ def test_affect_uuid():
|
||||
|
||||
|
||||
def test_path(tmpdir):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
with patch("gns3server.hypervisor.project.Project.is_local", return_value=True):
|
||||
p = Project(location=str(tmpdir))
|
||||
assert p.path == os.path.join(str(tmpdir), p.id)
|
||||
assert os.path.exists(os.path.join(str(tmpdir), p.id))
|
||||
@@ -59,14 +59,14 @@ def test_path(tmpdir):
|
||||
|
||||
def test_init_path(tmpdir):
|
||||
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
with patch("gns3server.hypervisor.project.Project.is_local", return_value=True):
|
||||
p = Project(path=str(tmpdir))
|
||||
assert p.path == str(tmpdir)
|
||||
|
||||
|
||||
def test_changing_path_temporary_flag(tmpdir):
|
||||
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
with patch("gns3server.hypervisor.project.Project.is_local", return_value=True):
|
||||
p = Project(temporary=True)
|
||||
assert os.path.exists(p.path)
|
||||
original_path = p.path
|
||||
@@ -90,20 +90,20 @@ def test_remove_temporary_flag():
|
||||
|
||||
|
||||
def test_changing_location_not_allowed(tmpdir):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=False):
|
||||
with patch("gns3server.hypervisor.project.Project.is_local", return_value=False):
|
||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||
p = Project(location=str(tmpdir))
|
||||
|
||||
|
||||
def test_changing_path_not_allowed(tmpdir):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=False):
|
||||
with patch("gns3server.hypervisor.project.Project.is_local", return_value=False):
|
||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||
p = Project()
|
||||
p.path = str(tmpdir)
|
||||
|
||||
|
||||
def test_changing_path_with_quote_not_allowed(tmpdir):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
with patch("gns3server.hypervisor.project.Project.is_local", return_value=True):
|
||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||
p = Project()
|
||||
p.path = str(tmpdir / "project\"53")
|
||||
@@ -115,7 +115,7 @@ def test_json(tmpdir):
|
||||
|
||||
|
||||
def test_vm_working_directory(tmpdir, vm):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
with patch("gns3server.hypervisor.project.Project.is_local", return_value=True):
|
||||
p = Project(location=str(tmpdir))
|
||||
assert p.vm_working_directory(vm) == os.path.join(str(tmpdir), p.id, 'project-files', vm.module_name, vm.id)
|
||||
assert os.path.exists(p.vm_working_directory(vm))
|
||||
@@ -184,7 +184,7 @@ def test_project_add_vm(manager):
|
||||
|
||||
def test_project_close(loop, vm, project):
|
||||
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.close") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.close") as mock:
|
||||
loop.run_until_complete(asyncio.async(project.close()))
|
||||
assert mock.called
|
||||
assert vm.id not in vm.manager._vms
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import aiohttp
|
||||
import pytest
|
||||
from gns3server.modules.project_manager import ProjectManager
|
||||
from gns3server.hypervisor.project_manager import ProjectManager
|
||||
|
||||
|
||||
def test_create_project():
|
||||
+3
-3
@@ -25,8 +25,8 @@ import asyncio
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from gns3server.modules.virtualbox import VirtualBox
|
||||
from gns3server.modules.virtualbox.virtualbox_error import VirtualBoxError
|
||||
from gns3server.hypervisor.virtualbox import VirtualBox
|
||||
from gns3server.hypervisor.virtualbox.virtualbox_error import VirtualBoxError
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ def test_list_images(manager, loop):
|
||||
return ["memory=256"]
|
||||
assert False, "Unknow {} {}".format(cmd, args)
|
||||
|
||||
with asyncio_patch("gns3server.modules.virtualbox.VirtualBox.execute") as mock:
|
||||
with asyncio_patch("gns3server.hypervisor.virtualbox.VirtualBox.execute") as mock:
|
||||
mock.side_effect = execute_mock
|
||||
vms = loop.run_until_complete(asyncio.async(manager.list_images()))
|
||||
assert vms == [
|
||||
+5
-5
@@ -19,9 +19,9 @@ import pytest
|
||||
import asyncio
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
from gns3server.modules.virtualbox.virtualbox_vm import VirtualBoxVM
|
||||
from gns3server.modules.virtualbox.virtualbox_error import VirtualBoxError
|
||||
from gns3server.modules.virtualbox import VirtualBox
|
||||
from gns3server.hypervisor.virtualbox.virtualbox_vm import VirtualBoxVM
|
||||
from gns3server.hypervisor.virtualbox.virtualbox_error import VirtualBoxError
|
||||
from gns3server.hypervisor.virtualbox import VirtualBox
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@@ -44,13 +44,13 @@ def test_vm(project, manager):
|
||||
|
||||
|
||||
def test_vm_valid_virtualbox_api_version(loop, project, manager):
|
||||
with asyncio_patch("gns3server.modules.virtualbox.VirtualBox.execute", return_value=["API version: 4_3"]):
|
||||
with asyncio_patch("gns3server.hypervisor.virtualbox.VirtualBox.execute", return_value=["API version: 4_3"]):
|
||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
|
||||
|
||||
def test_vm_invalid_virtualbox_api_version(loop, project, manager):
|
||||
with asyncio_patch("gns3server.modules.virtualbox.VirtualBox.execute", return_value=["API version: 4_2"]):
|
||||
with asyncio_patch("gns3server.hypervisor.virtualbox.VirtualBox.execute", return_value=["API version: 4_2"]):
|
||||
with pytest.raises(VirtualBoxError):
|
||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
+1
-1
@@ -25,7 +25,7 @@ import asyncio
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from gns3server.modules.vmware import VMware
|
||||
from gns3server.hypervisor.vmware import VMware
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ import pytest
|
||||
import asyncio
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
from gns3server.modules.vmware.vmware_vm import VMwareVM
|
||||
from gns3server.modules.vmware.vmware_error import VMwareError
|
||||
from gns3server.modules.vmware import VMware
|
||||
from gns3server.hypervisor.vmware.vmware_vm import VMwareVM
|
||||
from gns3server.hypervisor.vmware.vmware_error import VMwareError
|
||||
from gns3server.hypervisor.vmware import VMware
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
+3
-3
@@ -20,9 +20,9 @@ import pytest
|
||||
import uuid
|
||||
|
||||
|
||||
from gns3server.modules.vpcs import VPCS
|
||||
from gns3server.modules.vpcs.vpcs_error import VPCSError
|
||||
from gns3server.modules.project_manager import ProjectManager
|
||||
from gns3server.hypervisor.vpcs import VPCS
|
||||
from gns3server.hypervisor.vpcs.vpcs_error import VPCSError
|
||||
from gns3server.hypervisor.project_manager import ProjectManager
|
||||
|
||||
|
||||
def test_get_mac_id(loop, project, port_manager):
|
||||
@@ -25,9 +25,9 @@ from tests.utils import asyncio_patch
|
||||
from pkg_resources import parse_version
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
|
||||
from gns3server.modules.vpcs.vpcs_error import VPCSError
|
||||
from gns3server.modules.vpcs import VPCS
|
||||
from gns3server.hypervisor.vpcs.vpcs_vm import VPCSVM
|
||||
from gns3server.hypervisor.vpcs.vpcs_error import VPCSError
|
||||
from gns3server.hypervisor.vpcs import VPCS
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@@ -51,19 +51,19 @@ def test_vm(project, manager):
|
||||
|
||||
|
||||
def test_vm_check_vpcs_version(loop, vm, manager):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.9"):
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.9"):
|
||||
loop.run_until_complete(asyncio.async(vm._check_vpcs_version()))
|
||||
assert vm._vpcs_version == parse_version("0.9")
|
||||
|
||||
|
||||
def test_vm_check_vpcs_version_0_6_1(loop, vm, manager):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.6.1"):
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.6.1"):
|
||||
loop.run_until_complete(asyncio.async(vm._check_vpcs_version()))
|
||||
assert vm._vpcs_version == parse_version("0.6.1")
|
||||
|
||||
|
||||
def test_vm_invalid_vpcs_version(loop, manager, vm):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.1"):
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.1"):
|
||||
with pytest.raises(VPCSError):
|
||||
nio = manager.create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
@@ -73,7 +73,7 @@ def test_vm_invalid_vpcs_version(loop, manager, vm):
|
||||
|
||||
|
||||
def test_vm_invalid_vpcs_path(vm, manager, loop):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.vpcs_path", return_value="/tmp/fake/path/vpcs"):
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM.vpcs_path", return_value="/tmp/fake/path/vpcs"):
|
||||
with pytest.raises(VPCSError):
|
||||
nio = manager.create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
@@ -87,7 +87,7 @@ def test_start(loop, vm):
|
||||
process.returncode = None
|
||||
queue = vm.project.get_listen_queue()
|
||||
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
|
||||
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
@@ -123,7 +123,7 @@ def test_start_0_6_1(loop, vm):
|
||||
queue = vm.project.get_listen_queue()
|
||||
vm._vpcs_version = parse_version("0.6.1")
|
||||
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
|
||||
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
@@ -156,7 +156,7 @@ def test_stop(loop, vm):
|
||||
process.wait.return_value = future
|
||||
process.returncode = None
|
||||
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
@@ -189,7 +189,7 @@ def test_reload(loop, vm):
|
||||
process.wait.return_value = future
|
||||
process.returncode = None
|
||||
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
@@ -214,14 +214,14 @@ def test_add_nio_binding_udp(vm):
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
def test_add_nio_binding_tap(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):
|
||||
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_tap", "tap_device": ethernet_device})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
assert nio.tap_device == ethernet_device
|
||||
|
||||
|
||||
# def test_add_nio_binding_tap_no_privileged_access(vm):
|
||||
# with patch("gns3server.modules.base_manager.BaseManager.has_privileged_access", return_value=False):
|
||||
# with patch("gns3server.hypervisor.base_manager.BaseManager.has_privileged_access", return_value=False):
|
||||
# with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||
# nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_tap", "tap_device": "test"})
|
||||
# vm.port_add_nio_binding(0, nio)
|
||||
@@ -285,7 +285,7 @@ def test_change_name(vm, tmpdir):
|
||||
|
||||
|
||||
def test_close(vm, port_manager, loop):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.hypervisor.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
vm.start()
|
||||
loop.run_until_complete(asyncio.async(vm.close()))
|
||||
Reference in new issue
Block a user