mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Migration to FastAPI
This commit is contained in:
1 parent
c12b675691
commit
eb3cb8a41f
224 files changed
+11254
-13517
No files matched your search
Whitespace-only changes.
@@ -31,13 +31,15 @@ def nio():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop):
|
||||
@pytest.mark.asyncio
|
||||
async def manager():
|
||||
|
||||
m = MagicMock()
|
||||
m.module_name = "builtins"
|
||||
return m
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_json_with_ports(on_gns3vm, compute_project, manager):
|
||||
|
||||
ports = [
|
||||
@@ -115,7 +117,8 @@ def test_json_without_ports(on_gns3vm, compute_project, manager):
|
||||
}
|
||||
|
||||
|
||||
async def test_update_port_mappings(loop, on_gns3vm, compute_project):
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_port_mappings(on_gns3vm, compute_project):
|
||||
"""
|
||||
We don't allow an empty interface in the middle of port list
|
||||
"""
|
||||
@@ -155,7 +158,8 @@ async def test_update_port_mappings(loop, on_gns3vm, compute_project):
|
||||
assert cloud.ports_mapping == ports1
|
||||
|
||||
|
||||
async def test_linux_ethernet_raw_add_nio(loop, linux_platform, compute_project, nio):
|
||||
@pytest.mark.asyncio
|
||||
async def test_linux_ethernet_raw_add_nio(linux_platform, compute_project, nio):
|
||||
ports = [
|
||||
{
|
||||
"interface": "eth0",
|
||||
@@ -182,7 +186,8 @@ async def test_linux_ethernet_raw_add_nio(loop, linux_platform, compute_project,
|
||||
])
|
||||
|
||||
|
||||
async def test_linux_ethernet_raw_add_nio_bridge(loop, linux_platform, compute_project, nio):
|
||||
@pytest.mark.asyncio
|
||||
async def test_linux_ethernet_raw_add_nio_bridge(linux_platform, compute_project, nio):
|
||||
"""
|
||||
Bridge can't be connected directly to a cloud we use a tap in the middle
|
||||
"""
|
||||
|
||||
@@ -24,7 +24,8 @@ from gns3server.compute.docker.docker_error import DockerError, DockerHttp404Err
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def vm(loop):
|
||||
@pytest.mark.asyncio
|
||||
async def vm():
|
||||
|
||||
vm = Docker()
|
||||
vm._connected = True
|
||||
@@ -33,6 +34,7 @@ async def vm(loop):
|
||||
return vm
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_query_success(vm):
|
||||
|
||||
response = MagicMock()
|
||||
@@ -55,6 +57,7 @@ async def test_query_success(vm):
|
||||
assert data == {"c": False}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_query_error(vm):
|
||||
|
||||
response = MagicMock()
|
||||
@@ -75,6 +78,7 @@ async def test_query_error(vm):
|
||||
timeout=300)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_query_error_json(vm):
|
||||
|
||||
response = MagicMock()
|
||||
@@ -95,6 +99,7 @@ async def test_query_error_json(vm):
|
||||
timeout=300)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_images():
|
||||
|
||||
response = [
|
||||
@@ -134,6 +139,7 @@ async def test_list_images():
|
||||
assert {"image": "ubuntu:quantal"} in images
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pull_image():
|
||||
|
||||
class Response:
|
||||
@@ -162,6 +168,7 @@ async def test_pull_image():
|
||||
mock.assert_called_with("POST", "images/create", params={"fromImage": "ubuntu"}, timeout=None)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_docker_check_connection_docker_minimum_version(vm):
|
||||
|
||||
response = {
|
||||
@@ -176,6 +183,7 @@ async def test_docker_check_connection_docker_minimum_version(vm):
|
||||
await vm._check_connection()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_docker_check_connection_docker_preferred_version_against_newer(vm):
|
||||
|
||||
response = {
|
||||
@@ -189,6 +197,7 @@ async def test_docker_check_connection_docker_preferred_version_against_newer(vm
|
||||
assert vm._api_version == DOCKER_PREFERRED_API_VERSION
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_docker_check_connection_docker_preferred_version_against_older(vm):
|
||||
|
||||
response = {
|
||||
|
||||
@@ -34,7 +34,8 @@ from unittest.mock import patch, MagicMock, call
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = Docker.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -42,7 +43,8 @@ async def manager(loop, port_manager):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def vm(loop, compute_project, manager):
|
||||
@pytest.mark.asyncio
|
||||
async def vm(compute_project, manager):
|
||||
|
||||
vm = DockerVM("test", str(uuid.uuid4()), compute_project, manager, "ubuntu:latest", aux_type="none")
|
||||
vm._cid = "e90e34656842"
|
||||
@@ -85,6 +87,7 @@ def test_start_command(vm):
|
||||
assert vm.start_command is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -126,6 +129,7 @@ async def test_create(compute_project, manager):
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_tag(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -167,6 +171,7 @@ async def test_create_with_tag(compute_project, manager):
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_vnc(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -216,6 +221,7 @@ async def test_create_vnc(compute_project, manager):
|
||||
assert vm._console_type == "vnc"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_hosts(compute_project, manager):
|
||||
|
||||
extra_hosts = "test:199.199.199.1\ntest2:199.199.199.1"
|
||||
@@ -233,6 +239,7 @@ async def test_create_with_extra_hosts(compute_project, manager):
|
||||
assert vm._extra_hosts == extra_hosts
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_hosts_wrong_format(compute_project, manager):
|
||||
extra_hosts = "test"
|
||||
|
||||
@@ -248,6 +255,7 @@ async def test_create_with_extra_hosts_wrong_format(compute_project, manager):
|
||||
await vm.create()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_empty_extra_hosts(compute_project, manager):
|
||||
extra_hosts = "test:\n"
|
||||
|
||||
@@ -264,6 +272,7 @@ async def test_create_with_empty_extra_hosts(compute_project, manager):
|
||||
assert len([ e for e in called_kwargs["data"]["Env"] if "GNS3_EXTRA_HOSTS" in e]) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_project_variables(compute_project, manager):
|
||||
response = {
|
||||
"Id": "e90e34656806",
|
||||
@@ -287,6 +296,7 @@ async def test_create_with_project_variables(compute_project, manager):
|
||||
compute_project.variables = None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_start_cmd(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -329,6 +339,7 @@ async def test_create_start_cmd(compute_project, manager):
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_environment(compute_project, manager):
|
||||
"""
|
||||
Allow user to pass an environment. User can't override our
|
||||
@@ -353,6 +364,7 @@ async def test_create_environment(compute_project, manager):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_environment_with_last_new_line_character(compute_project, manager):
|
||||
"""
|
||||
Allow user to pass an environment. User can't override our
|
||||
@@ -377,6 +389,7 @@ async def test_create_environment_with_last_new_line_character(compute_project,
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_image_not_available(compute_project, manager):
|
||||
|
||||
call = 0
|
||||
@@ -431,6 +444,7 @@ async def test_create_image_not_available(compute_project, manager):
|
||||
mock_pull.assert_called_with("ubuntu:latest")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_user(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -476,6 +490,8 @@ async def test_create_with_user(compute_project, manager):
|
||||
})
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes_invalid_format_1(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -489,6 +505,7 @@ async def test_create_with_extra_volumes_invalid_format_1(compute_project, manag
|
||||
await vm.create()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes_invalid_format_2(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -502,6 +519,7 @@ async def test_create_with_extra_volumes_invalid_format_2(compute_project, manag
|
||||
await vm.create()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes_invalid_format_3(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -515,6 +533,7 @@ async def test_create_with_extra_volumes_invalid_format_3(compute_project, manag
|
||||
await vm.create()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes_duplicate_1_image(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -562,6 +581,7 @@ async def test_create_with_extra_volumes_duplicate_1_image(compute_project, mana
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes_duplicate_2_user(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -604,6 +624,7 @@ async def test_create_with_extra_volumes_duplicate_2_user(compute_project, manag
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes_duplicate_3_subdir(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -646,6 +667,7 @@ async def test_create_with_extra_volumes_duplicate_3_subdir(compute_project, man
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes_duplicate_4_backslash(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -688,6 +710,7 @@ async def test_create_with_extra_volumes_duplicate_4_backslash(compute_project,
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes_duplicate_5_subdir_issue_1595(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -729,6 +752,7 @@ async def test_create_with_extra_volumes_duplicate_5_subdir_issue_1595(compute_p
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes_duplicate_6_subdir_issue_1595(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -770,6 +794,7 @@ async def test_create_with_extra_volumes_duplicate_6_subdir_issue_1595(compute_p
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_with_extra_volumes(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -819,6 +844,7 @@ async def test_create_with_extra_volumes(compute_project, manager):
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_container_state(vm):
|
||||
|
||||
response = {
|
||||
@@ -848,6 +874,7 @@ async def test_get_container_state(vm):
|
||||
assert await vm._get_container_state() == "exited"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_is_running(vm):
|
||||
|
||||
response = {
|
||||
@@ -864,6 +891,7 @@ async def test_is_running(vm):
|
||||
assert await vm.is_running() is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pause(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
|
||||
@@ -873,6 +901,7 @@ async def test_pause(vm):
|
||||
assert vm.status == "suspended"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unpause(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
|
||||
@@ -880,6 +909,7 @@ async def test_unpause(vm):
|
||||
mock.assert_called_with("POST", "containers/e90e34656842/unpause")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start(vm, manager, free_console_port):
|
||||
|
||||
assert vm.status != "started"
|
||||
@@ -908,6 +938,7 @@ async def test_start(vm, manager, free_console_port):
|
||||
assert vm.status == "started"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_namespace_failed(vm, manager, free_console_port):
|
||||
|
||||
assert vm.status != "started"
|
||||
@@ -932,6 +963,7 @@ async def test_start_namespace_failed(vm, manager, free_console_port):
|
||||
assert vm.status == "stopped"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_without_nio(vm):
|
||||
"""
|
||||
If no nio exists we will create one.
|
||||
@@ -955,6 +987,7 @@ async def test_start_without_nio(vm):
|
||||
assert vm.status == "started"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_unpause(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"):
|
||||
@@ -964,6 +997,7 @@ async def test_start_unpause(vm):
|
||||
assert vm.status == "started"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_restart(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
|
||||
@@ -971,6 +1005,7 @@ async def test_restart(vm):
|
||||
mock.assert_called_with("POST", "containers/e90e34656842/restart")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop(vm):
|
||||
|
||||
mock = MagicMock()
|
||||
@@ -987,6 +1022,7 @@ async def test_stop(vm):
|
||||
assert vm._fix_permissions.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_paused_container(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"):
|
||||
@@ -997,6 +1033,7 @@ async def test_stop_paused_container(vm):
|
||||
assert mock_unpause.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update(vm):
|
||||
|
||||
response = {
|
||||
@@ -1045,6 +1082,7 @@ async def test_update(vm):
|
||||
assert vm.aux == original_aux
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_vnc(vm):
|
||||
|
||||
response = {
|
||||
@@ -1068,6 +1106,7 @@ async def test_update_vnc(vm):
|
||||
assert vm.aux == original_aux
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_running(vm):
|
||||
|
||||
response = {
|
||||
@@ -1117,6 +1156,7 @@ async def test_update_running(vm):
|
||||
assert vm.start.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||
@@ -1125,6 +1165,7 @@ async def test_delete(vm):
|
||||
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close(vm, port_manager):
|
||||
|
||||
nio = {"type": "nio_udp",
|
||||
@@ -1143,6 +1184,7 @@ async def test_close(vm, port_manager):
|
||||
assert "4242" not in port_manager.udp_ports
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close_vnc(vm):
|
||||
|
||||
vm._console_type = "vnc"
|
||||
@@ -1158,6 +1200,7 @@ async def test_close_vnc(vm):
|
||||
assert vm._xvfb_process.terminate.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_namespace(vm):
|
||||
|
||||
response = {
|
||||
@@ -1170,6 +1213,7 @@ async def test_get_namespace(vm):
|
||||
mock_query.assert_called_with("GET", "containers/e90e34656842/json")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_ubridge_connection(vm):
|
||||
|
||||
nio = {"type": "nio_udp",
|
||||
@@ -1195,6 +1239,7 @@ async def test_add_ubridge_connection(vm):
|
||||
vm._ubridge_hypervisor.assert_has_calls(calls, any_order=True)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_ubridge_connection_none_nio(vm):
|
||||
|
||||
nio = None
|
||||
@@ -1214,6 +1259,7 @@ async def test_add_ubridge_connection_none_nio(vm):
|
||||
vm._ubridge_hypervisor.assert_has_calls(calls, any_order=True)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_ubridge_connection_invalid_adapter_number(vm):
|
||||
|
||||
nio = {"type": "nio_udp",
|
||||
@@ -1225,6 +1271,7 @@ async def test_add_ubridge_connection_invalid_adapter_number(vm):
|
||||
await vm._add_ubridge_connection(nio, 12)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_ubridge_connection_no_free_interface(vm):
|
||||
|
||||
nio = {"type": "nio_udp",
|
||||
@@ -1241,6 +1288,7 @@ async def test_add_ubridge_connection_no_free_interface(vm):
|
||||
await vm._add_ubridge_connection(nio, 0)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_adapter_add_nio_binding_1(vm):
|
||||
|
||||
nio = {"type": "nio_udp",
|
||||
@@ -1252,6 +1300,7 @@ async def test_adapter_add_nio_binding_1(vm):
|
||||
assert vm._ethernet_adapters[0].get_nio(0) == nio
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_adapter_udpate_nio_binding_bridge_not_started(vm):
|
||||
|
||||
vm._ubridge_apply_filters = AsyncioMagicMock()
|
||||
@@ -1266,6 +1315,7 @@ async def test_adapter_udpate_nio_binding_bridge_not_started(vm):
|
||||
assert vm._ubridge_apply_filters.called is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_adapter_add_nio_binding_invalid_adapter(vm):
|
||||
|
||||
nio = {"type": "nio_udp",
|
||||
@@ -1277,6 +1327,7 @@ async def test_adapter_add_nio_binding_invalid_adapter(vm):
|
||||
await vm.adapter_add_nio_binding(12, nio)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_adapter_remove_nio_binding(vm):
|
||||
|
||||
vm.ubridge = MagicMock()
|
||||
@@ -1296,12 +1347,14 @@ async def test_adapter_remove_nio_binding(vm):
|
||||
delete_ubridge_mock.assert_any_call('bridge remove_nio_udp bridge0 4242 127.0.0.1 4343')
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_adapter_remove_nio_binding_invalid_adapter(vm):
|
||||
|
||||
with pytest.raises(DockerError):
|
||||
await vm.adapter_remove_nio_binding(12)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_capture(vm, tmpdir, manager, free_console_port):
|
||||
|
||||
output_file = str(tmpdir / "test.pcap")
|
||||
@@ -1311,6 +1364,7 @@ async def test_start_capture(vm, tmpdir, manager, free_console_port):
|
||||
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_capture(vm, tmpdir, manager, free_console_port):
|
||||
|
||||
output_file = str(tmpdir / "test.pcap")
|
||||
@@ -1322,6 +1376,7 @@ async def test_stop_capture(vm, tmpdir, manager, free_console_port):
|
||||
assert vm._ethernet_adapters[0].get_nio(0).capturing is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_log(vm):
|
||||
|
||||
async def read():
|
||||
@@ -1335,6 +1390,7 @@ async def test_get_log(vm):
|
||||
mock.assert_called_with("GET", "containers/e90e34656842/logs", params={"stderr": 1, "stdout": 1}, data={})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_image_information(compute_project, manager):
|
||||
|
||||
response = {}
|
||||
@@ -1345,6 +1401,7 @@ async def test_get_image_information(compute_project, manager):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
@pytest.mark.asyncio
|
||||
async def test_mount_binds(vm):
|
||||
|
||||
image_infos = {
|
||||
@@ -1366,6 +1423,7 @@ async def test_mount_binds(vm):
|
||||
assert os.path.exists(dst)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_vnc(vm):
|
||||
|
||||
vm.console_resolution = "1280x1024"
|
||||
@@ -1378,6 +1436,7 @@ async def test_start_vnc(vm):
|
||||
mock_wait.assert_called_with("/tmp/.X11-unix/X{}".format(vm._display))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_vnc_missing(vm):
|
||||
|
||||
with patch("shutil.which", return_value=None):
|
||||
@@ -1385,6 +1444,7 @@ async def test_start_vnc_missing(vm):
|
||||
await vm._start_vnc()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_aux(vm):
|
||||
|
||||
with asyncio_patch("asyncio.subprocess.create_subprocess_exec", return_value=MagicMock()) as mock_exec:
|
||||
@@ -1392,6 +1452,7 @@ async def test_start_aux(vm):
|
||||
mock_exec.assert_called_with('docker', 'exec', '-i', 'e90e34656842', '/gns3/bin/busybox', 'script', '-qfc', 'while true; do TERM=vt100 /gns3/bin/busybox sh; done', '/dev/null', stderr=asyncio.subprocess.STDOUT, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_network_interfaces(vm):
|
||||
|
||||
vm.adapters = 5
|
||||
@@ -1407,6 +1468,7 @@ async def test_create_network_interfaces(vm):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
@pytest.mark.asyncio
|
||||
async def test_fix_permission(vm):
|
||||
|
||||
vm._volumes = ["/etc"]
|
||||
@@ -1419,6 +1481,7 @@ async def test_fix_permission(vm):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
@pytest.mark.asyncio
|
||||
async def test_fix_permission_not_running(vm):
|
||||
|
||||
vm._volumes = ["/etc"]
|
||||
@@ -1432,6 +1495,7 @@ async def test_fix_permission_not_running(vm):
|
||||
assert process.wait.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_read_console_output_with_binary_mode(vm):
|
||||
|
||||
class InputStreamMock(object):
|
||||
@@ -1456,6 +1520,7 @@ async def test_read_console_output_with_binary_mode(vm):
|
||||
output_stream.feed_data.assert_called_once_with(b"test")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cpus(compute_project, manager):
|
||||
|
||||
response = {
|
||||
@@ -1497,6 +1562,7 @@ async def test_cpus(compute_project, manager):
|
||||
assert vm._cid == "e90e34656806"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_memory(compute_project, manager):
|
||||
|
||||
response = {
|
||||
|
||||
@@ -29,7 +29,8 @@ from tests.utils import asyncio_patch, AsyncioMagicMock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = Dynamips.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -85,6 +86,7 @@ def test_release_dynamips_id(manager):
|
||||
manager.release_dynamips_id(project_2, 0)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_project_closed(manager, compute_project):
|
||||
|
||||
manager._dynamips_ids[compute_project.id] = set([1, 2, 3])
|
||||
@@ -97,6 +99,7 @@ async def test_project_closed(manager, compute_project):
|
||||
assert compute_project.id not in manager._dynamips_ids
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_duplicate_node(manager, compute_project):
|
||||
"""
|
||||
Duplicate dynamips do nothing it's manage outside the
|
||||
|
||||
@@ -27,7 +27,8 @@ from gns3server.config import Config
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = Dynamips.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -64,6 +65,7 @@ def test_convert_project_before_2_0_0_b3(compute_project, manager):
|
||||
assert not os.path.exists(os.path.join(wdir, node_id, "c7200_i2_nvram"))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_router_invalid_dynamips_path(compute_project, manager):
|
||||
|
||||
config = Config.instance()
|
||||
|
||||
@@ -37,7 +37,8 @@ if not sys.platform.startswith("win"):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = IOU.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -45,7 +46,8 @@ async def manager(loop, port_manager):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def vm(loop, compute_project, manager, tmpdir, fake_iou_bin, iourc_file):
|
||||
@pytest.mark.asyncio
|
||||
async def vm(compute_project, manager, tmpdir, fake_iou_bin, iourc_file):
|
||||
|
||||
vm = IOUVM("test", str(uuid.uuid4()), compute_project, manager, application_id=1)
|
||||
config = manager.config.get_section_config("IOU")
|
||||
@@ -92,6 +94,7 @@ def test_vm_startup_config_content(compute_project, manager):
|
||||
assert vm.id == "00010203-0405-0607-0808-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start(vm):
|
||||
|
||||
mock_process = MagicMock()
|
||||
@@ -114,6 +117,7 @@ async def test_start(vm):
|
||||
vm._ubridge_send.assert_any_call("iol_bridge start IOL-BRIDGE-513")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_with_iourc(vm, tmpdir):
|
||||
|
||||
fake_file = str(tmpdir / "iourc")
|
||||
@@ -136,6 +140,7 @@ async def test_start_with_iourc(vm, tmpdir):
|
||||
assert kwargs["env"]["IOURC"] == fake_file
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rename_nvram_file(vm):
|
||||
"""
|
||||
It should rename the nvram file to the correct name before launching the VM
|
||||
@@ -152,6 +157,7 @@ async def test_rename_nvram_file(vm):
|
||||
assert os.path.exists(os.path.join(vm.working_dir, "vlan.dat-0000{}".format(vm.application_id)))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop(vm):
|
||||
|
||||
process = MagicMock()
|
||||
@@ -176,6 +182,7 @@ async def test_stop(vm):
|
||||
process.terminate.assert_called_with()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reload(vm, fake_iou_bin):
|
||||
|
||||
process = MagicMock()
|
||||
@@ -200,6 +207,7 @@ async def test_reload(vm, fake_iou_bin):
|
||||
process.terminate.assert_called_with()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close(vm, port_manager):
|
||||
|
||||
vm._start_ubridge = AsyncioMagicMock(return_value=True)
|
||||
@@ -252,6 +260,7 @@ def test_create_netmap_config(vm):
|
||||
assert "513:15/3 1:15/3" in content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command(vm):
|
||||
|
||||
assert await vm._build_command() == [vm.path, str(vm.application_id)]
|
||||
@@ -316,6 +325,7 @@ def test_change_name(vm):
|
||||
assert f.read() == "no service password-encryption\nhostname charlie\nno ip icmp rate-limit unreachable"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_library_check(vm):
|
||||
|
||||
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value=""):
|
||||
@@ -326,6 +336,7 @@ async def test_library_check(vm):
|
||||
await vm._library_check()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_enable_l1_keepalives(vm):
|
||||
|
||||
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="***************************************************************\n\n-l Enable Layer 1 keepalive messages\n-u <n> UDP port base for distributed networks\n"):
|
||||
@@ -341,6 +352,7 @@ async def test_enable_l1_keepalives(vm):
|
||||
assert command == ["test"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_capture(vm, tmpdir, manager, free_console_port):
|
||||
|
||||
output_file = str(tmpdir / "test.pcap")
|
||||
@@ -350,6 +362,7 @@ async def test_start_capture(vm, tmpdir, manager, free_console_port):
|
||||
assert vm._adapters[0].get_nio(0).capturing
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_capture(vm, tmpdir, manager, free_console_port):
|
||||
|
||||
output_file = str(tmpdir / "test.pcap")
|
||||
@@ -366,6 +379,7 @@ def test_get_legacy_vm_workdir():
|
||||
assert IOU.get_legacy_vm_workdir(42, "bla") == "iou/device-42"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_iou_file(vm, iourc_file):
|
||||
|
||||
hostname = socket.gethostname()
|
||||
|
||||
@@ -66,7 +66,8 @@ def test_invalid_empty_file(tmpdir):
|
||||
|
||||
|
||||
@pytest.mark.skipif(qemu_img() is None, reason="qemu-img is not available")
|
||||
async def test_rebase(loop, tmpdir):
|
||||
@pytest.mark.asyncio
|
||||
async def test_rebase(tmpdir):
|
||||
|
||||
shutil.copy("tests/resources/empty8G.qcow2", str(tmpdir / "empty16G.qcow2"))
|
||||
shutil.copy("tests/resources/linked.qcow2", str(tmpdir / "linked.qcow2"))
|
||||
|
||||
@@ -38,6 +38,7 @@ def fake_qemu_img_binary(tmpdir):
|
||||
return bin_path
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_qemu_version():
|
||||
|
||||
with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard"):
|
||||
@@ -48,6 +49,7 @@ async def test_get_qemu_version():
|
||||
assert version == "2.2.0"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_binary_list(monkeypatch, tmpdir):
|
||||
|
||||
monkeypatch.setenv("PATH", str(tmpdir))
|
||||
@@ -88,6 +90,7 @@ async def test_binary_list(monkeypatch, tmpdir):
|
||||
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_img_binary_list(monkeypatch, tmpdir):
|
||||
|
||||
monkeypatch.setenv("PATH", str(tmpdir))
|
||||
@@ -117,6 +120,7 @@ def test_get_legacy_vm_workdir():
|
||||
assert Qemu.get_legacy_vm_workdir(42, "bla") == os.path.join("qemu", "vm-42")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_image_abs_path(tmpdir, fake_qemu_img_binary):
|
||||
|
||||
options = {
|
||||
@@ -148,6 +152,7 @@ async def test_create_image_abs_path(tmpdir, fake_qemu_img_binary):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_image_relative_path(tmpdir, fake_qemu_img_binary):
|
||||
|
||||
options = {
|
||||
@@ -168,6 +173,7 @@ async def test_create_image_relative_path(tmpdir, fake_qemu_img_binary):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_image_exist(tmpdir, fake_qemu_img_binary):
|
||||
|
||||
open(str(tmpdir / "hda.qcow2"), "w+").close()
|
||||
@@ -182,6 +188,7 @@ async def test_create_image_exist(tmpdir, fake_qemu_img_binary):
|
||||
assert not process.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_image_with_not_supported_characters_by_filesystem(tmpdir, fake_qemu_img_binary):
|
||||
|
||||
open(str(tmpdir / "hda.qcow2"), "w+").close()
|
||||
@@ -202,6 +209,7 @@ async def test_create_image_with_not_supported_characters_by_filesystem(tmpdir,
|
||||
assert not process.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_kvm_archs_kvm_ok():
|
||||
|
||||
with patch("os.path.exists", return_value=True):
|
||||
|
||||
@@ -34,7 +34,8 @@ from gns3server.compute.notification_manager import NotificationManager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = Qemu.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -67,6 +68,7 @@ def fake_qemu_binary(monkeypatch, tmpdir):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@pytest.mark.asyncio
|
||||
async def vm(compute_project, manager, fake_qemu_binary, fake_qemu_img_binary):
|
||||
|
||||
manager.port_manager.console_host = "127.0.0.1"
|
||||
@@ -87,6 +89,7 @@ def running_subprocess_mock():
|
||||
return mm
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm(compute_project, manager, fake_qemu_binary):
|
||||
|
||||
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, qemu_path=fake_qemu_binary)
|
||||
@@ -94,6 +97,7 @@ async def test_vm(compute_project, manager, fake_qemu_binary):
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_create(tmpdir, compute_project, manager, fake_qemu_binary):
|
||||
|
||||
fake_img = str(tmpdir / 'hello')
|
||||
@@ -110,6 +114,7 @@ async def test_vm_create(tmpdir, compute_project, manager, fake_qemu_binary):
|
||||
assert os.path.exists(str(tmpdir / 'hello.md5sum'))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_invalid_qemu_with_platform(compute_project, manager, fake_qemu_binary):
|
||||
|
||||
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, qemu_path="/usr/fake/bin/qemu-system-64", platform="x86_64")
|
||||
@@ -118,6 +123,7 @@ async def test_vm_invalid_qemu_with_platform(compute_project, manager, fake_qemu
|
||||
assert vm.platform == "x86_64"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_invalid_qemu_without_platform(compute_project, manager, fake_qemu_binary):
|
||||
|
||||
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, qemu_path="/usr/fake/bin/qemu-system-x86_64")
|
||||
@@ -126,6 +132,7 @@ async def test_vm_invalid_qemu_without_platform(compute_project, manager, fake_q
|
||||
assert vm.platform == "x86_64"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_is_running(vm, running_subprocess_mock):
|
||||
|
||||
vm._process = None
|
||||
@@ -136,6 +143,7 @@ async def test_is_running(vm, running_subprocess_mock):
|
||||
assert vm.is_running() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start(vm, running_subprocess_mock):
|
||||
|
||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
|
||||
@@ -146,6 +154,7 @@ async def test_start(vm, running_subprocess_mock):
|
||||
assert vm.command_line == ' '.join(mock.call_args[0])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop(vm, running_subprocess_mock):
|
||||
|
||||
process = running_subprocess_mock
|
||||
@@ -166,6 +175,7 @@ async def test_stop(vm, running_subprocess_mock):
|
||||
process.terminate.assert_called_with()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_termination_callback(vm):
|
||||
|
||||
vm.status = "started"
|
||||
@@ -181,6 +191,7 @@ async def test_termination_callback(vm):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
@pytest.mark.asyncio
|
||||
async def test_termination_callback_error(vm, tmpdir):
|
||||
|
||||
with open(str(tmpdir / "qemu.log"), "w+") as f:
|
||||
@@ -204,6 +215,7 @@ async def test_termination_callback_error(vm, tmpdir):
|
||||
assert event["message"] == "QEMU process has stopped, return code: 1\nBOOMM"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reload(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm") as mock:
|
||||
@@ -211,6 +223,7 @@ async def test_reload(vm):
|
||||
assert mock.called_with("system_reset")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_suspend(vm):
|
||||
|
||||
control_vm_result = MagicMock()
|
||||
@@ -220,6 +233,7 @@ async def test_suspend(vm):
|
||||
assert mock.called_with("system_reset")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_nio_binding_udp(vm):
|
||||
|
||||
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||
@@ -228,6 +242,7 @@ async def test_add_nio_binding_udp(vm):
|
||||
assert nio.lport == 4242
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_port_remove_nio_binding(vm):
|
||||
|
||||
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||
@@ -236,6 +251,7 @@ async def test_port_remove_nio_binding(vm):
|
||||
assert vm._ethernet_adapters[0].ports[0] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close(vm, port_manager):
|
||||
|
||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
|
||||
@@ -335,6 +351,7 @@ def test_set_qemu_path_kvm_binary(vm, fake_qemu_binary):
|
||||
assert vm.platform == "x86_64"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_platform(compute_project, manager):
|
||||
|
||||
manager.config_disk = None # avoids conflict with config.img support
|
||||
@@ -349,6 +366,7 @@ async def test_set_platform(compute_project, manager):
|
||||
assert vm.qemu_path == "/bin/qemu-system-x86_64"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_disk_options(vm, tmpdir, fake_qemu_img_binary):
|
||||
|
||||
vm._hda_disk_image = str(tmpdir / "test.qcow2")
|
||||
@@ -363,6 +381,7 @@ async def test_disk_options(vm, tmpdir, fake_qemu_img_binary):
|
||||
assert options == ['-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk,id=drive0']
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cdrom_option(vm, tmpdir, fake_qemu_img_binary):
|
||||
|
||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
|
||||
@@ -374,6 +393,7 @@ async def test_cdrom_option(vm, tmpdir, fake_qemu_img_binary):
|
||||
assert ' '.join(['-cdrom', str(tmpdir / "test.iso")]) in ' '.join(options)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bios_option(vm, tmpdir, fake_qemu_img_binary):
|
||||
|
||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
|
||||
@@ -383,6 +403,7 @@ async def test_bios_option(vm, tmpdir, fake_qemu_img_binary):
|
||||
assert ' '.join(['-bios', str(tmpdir / "test.img")]) in ' '.join(options)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vnc_option(vm, fake_qemu_img_binary):
|
||||
|
||||
vm._console_type = 'vnc'
|
||||
@@ -391,6 +412,7 @@ async def test_vnc_option(vm, fake_qemu_img_binary):
|
||||
assert '-vnc 127.0.0.1:5' in ' '.join(options)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_spice_option(vm, fake_qemu_img_binary):
|
||||
|
||||
vm._console_type = 'spice'
|
||||
@@ -400,6 +422,7 @@ async def test_spice_option(vm, fake_qemu_img_binary):
|
||||
assert '-vga qxl' in ' '.join(options)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_disk_options_multiple_disk(vm, tmpdir, fake_qemu_img_binary):
|
||||
|
||||
vm._hda_disk_image = str(tmpdir / "test0.qcow2")
|
||||
@@ -423,6 +446,7 @@ async def test_disk_options_multiple_disk(vm, tmpdir, fake_qemu_img_binary):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_process_priority(vm, fake_qemu_img_binary):
|
||||
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||
@@ -436,6 +460,7 @@ async def test_set_process_priority(vm, fake_qemu_img_binary):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_process_priority_normal(vm, fake_qemu_img_binary):
|
||||
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||
@@ -452,6 +477,7 @@ def test_json(vm, compute_project):
|
||||
assert json["project_id"] == compute_project.id
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_control_vm(vm):
|
||||
|
||||
vm._process = MagicMock()
|
||||
@@ -463,6 +489,7 @@ async def test_control_vm(vm):
|
||||
assert res is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_control_vm_expect_text(vm, running_subprocess_mock):
|
||||
|
||||
vm._process = running_subprocess_mock
|
||||
@@ -481,6 +508,7 @@ async def test_control_vm_expect_text(vm, running_subprocess_mock):
|
||||
assert res == "epic product"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command(vm, fake_qemu_binary):
|
||||
|
||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="3.1.0")
|
||||
@@ -513,6 +541,7 @@ async def test_build_command(vm, fake_qemu_binary):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command_manual_uuid(vm):
|
||||
"""
|
||||
If user has set a uuid we keep it
|
||||
@@ -527,6 +556,7 @@ async def test_build_command_manual_uuid(vm):
|
||||
assert vm.id not in cmd
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command_kvm(linux_platform, vm, fake_qemu_binary):
|
||||
"""
|
||||
Qemu 2.4 introduce an issue with KVM
|
||||
@@ -563,6 +593,7 @@ async def test_build_command_kvm(linux_platform, vm, fake_qemu_binary):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command_kvm_2_4(linux_platform, vm, fake_qemu_binary):
|
||||
"""
|
||||
Qemu 2.4 introduce an issue with KVM
|
||||
@@ -602,6 +633,7 @@ async def test_build_command_kvm_2_4(linux_platform, vm, fake_qemu_binary):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command_without_display(vm):
|
||||
|
||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.5.0")
|
||||
@@ -611,6 +643,7 @@ async def test_build_command_without_display(vm):
|
||||
assert "-nographic" in cmd
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command_two_adapters(vm, fake_qemu_binary):
|
||||
|
||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.5.0")
|
||||
@@ -648,6 +681,7 @@ async def test_build_command_two_adapters(vm, fake_qemu_binary):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command_two_adapters_mac_address(vm):
|
||||
"""
|
||||
Should support multiple base vmac address
|
||||
@@ -675,6 +709,7 @@ async def test_build_command_two_adapters_mac_address(vm):
|
||||
assert "e1000,mac={},netdev=gns3-1".format(mac_1) in cmd
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command_large_number_of_adapters(vm):
|
||||
"""
|
||||
When we have more than 28 interface we need to add a pci bridge for
|
||||
@@ -721,6 +756,7 @@ async def test_build_command_large_number_of_adapters(vm):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_command_with_invalid_options(vm):
|
||||
|
||||
vm.options = "'test"
|
||||
@@ -738,6 +774,7 @@ def test_hda_disk_image(vm, images_dir):
|
||||
assert vm.hda_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hda_disk_image_non_linked_clone(vm, images_dir, compute_project, manager, fake_qemu_binary):
|
||||
"""
|
||||
Two non linked can't use the same image at the same time
|
||||
@@ -854,18 +891,21 @@ def test_get_qemu_img(vm, tmpdir):
|
||||
# vm._get_qemu_img()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_with_hardware_acceleration_darwin(darwin_platform, vm):
|
||||
|
||||
vm.manager.config.set("Qemu", "enable_hardware_acceleration", False)
|
||||
assert await vm._run_with_hardware_acceleration("qemu-system-x86_64", "") is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_with_hardware_acceleration_windows(windows_platform, vm):
|
||||
|
||||
vm.manager.config.set("Qemu", "enable_hardware_acceleration", False)
|
||||
assert await vm._run_with_hardware_acceleration("qemu-system-x86_64", "") is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_with_kvm_linux(linux_platform, vm):
|
||||
|
||||
with patch("os.path.exists", return_value=True) as os_path:
|
||||
@@ -874,6 +914,7 @@ async def test_run_with_kvm_linux(linux_platform, vm):
|
||||
os_path.assert_called_with("/dev/kvm")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_with_kvm_linux_options_no_kvm(linux_platform, vm):
|
||||
|
||||
with patch("os.path.exists", return_value=True) as os_path:
|
||||
@@ -881,6 +922,7 @@ async def test_run_with_kvm_linux_options_no_kvm(linux_platform, vm):
|
||||
assert await vm._run_with_hardware_acceleration("qemu-system-x86_64", "-no-kvm") is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_with_kvm_not_x86(linux_platform, vm):
|
||||
|
||||
with patch("os.path.exists", return_value=True):
|
||||
@@ -889,6 +931,7 @@ async def test_run_with_kvm_not_x86(linux_platform, vm):
|
||||
await vm._run_with_hardware_acceleration("qemu-system-arm", "")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_with_kvm_linux_dev_kvm_missing(linux_platform, vm):
|
||||
|
||||
with patch("os.path.exists", return_value=False):
|
||||
|
||||
@@ -30,7 +30,8 @@ from gns3server.compute.nios.nio_udp import NIOUDP
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = VPCS.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -78,6 +79,7 @@ def test_console_vnc_invalid(compute_project, manager):
|
||||
node.console = 2012
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close(node, port_manager):
|
||||
|
||||
assert node.console is not None
|
||||
@@ -132,6 +134,7 @@ def test_change_aux_port(compute_project, manager, port_manager):
|
||||
port_manager.reserve_tcp_port(port1, node.project)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_ubridge_udp_connection(node):
|
||||
|
||||
filters = {
|
||||
@@ -146,6 +149,7 @@ async def test_update_ubridge_udp_connection(node):
|
||||
mock.assert_called_with("VPCS-10", filters)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ubridge_apply_filters(node):
|
||||
|
||||
filters = OrderedDict((
|
||||
@@ -158,6 +162,7 @@ async def test_ubridge_apply_filters(node):
|
||||
node._ubridge_send.assert_any_call("bridge add_packet_filter VPCS-10 filter0 latency 10")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ubridge_apply_bpf_filters(node):
|
||||
|
||||
filters = {
|
||||
|
||||
@@ -29,7 +29,8 @@ from gns3server.utils import force_unix_path
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def vpcs(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def vpcs(port_manager):
|
||||
|
||||
VPCS._instance = None
|
||||
vpcs = VPCS.instance()
|
||||
@@ -38,7 +39,8 @@ async def vpcs(loop, port_manager):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def qemu(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def qemu(port_manager):
|
||||
|
||||
Qemu._instance = None
|
||||
Qemu._init_config_disk = MagicMock() # do not create the config.img image
|
||||
@@ -47,6 +49,7 @@ async def qemu(loop, port_manager):
|
||||
return qemu
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_node_new_topology(compute_project, vpcs):
|
||||
|
||||
node_id = str(uuid.uuid4())
|
||||
@@ -54,6 +57,7 @@ async def test_create_node_new_topology(compute_project, vpcs):
|
||||
assert node in compute_project.nodes
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_twice_same_node_new_topology(compute_project, vpcs):
|
||||
|
||||
compute_project._nodes = set()
|
||||
@@ -65,6 +69,7 @@ async def test_create_twice_same_node_new_topology(compute_project, vpcs):
|
||||
assert len(compute_project.nodes) == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_node_new_topology_without_uuid(compute_project, vpcs):
|
||||
|
||||
node = await vpcs.create_node("PC 1", compute_project.id, None)
|
||||
@@ -72,6 +77,7 @@ async def test_create_node_new_topology_without_uuid(compute_project, vpcs):
|
||||
assert len(node.id) == 36
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_node_old_topology(compute_project, tmpdir, vpcs):
|
||||
|
||||
with patch("gns3server.compute.project.Project.is_local", return_value=True):
|
||||
@@ -232,6 +238,7 @@ def test_get_relative_image_path(qemu, tmpdir, config):
|
||||
assert qemu.get_relative_image_path(path5) == path5
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_images(qemu, tmpdir):
|
||||
|
||||
fake_images = ["a.qcow2", "b.qcow2", ".blu.qcow2", "a.qcow2.md5sum"]
|
||||
@@ -248,6 +255,7 @@ async def test_list_images(qemu, tmpdir):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_images_recursives(qemu, tmpdir):
|
||||
|
||||
tmp_images_dir = os.path.join(tmpdir, "images")
|
||||
@@ -271,18 +279,21 @@ async def test_list_images_recursives(qemu, tmpdir):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_images_empty(qemu, tmpdir):
|
||||
|
||||
with patch("gns3server.compute.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||
assert await qemu.list_images() == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_images_directory_not_exist(qemu):
|
||||
|
||||
with patch("gns3server.compute.Qemu.get_images_directory", return_value="/bla"):
|
||||
assert await qemu.list_images() == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_node(vpcs, compute_project):
|
||||
|
||||
compute_project._nodes = set()
|
||||
@@ -295,6 +306,7 @@ async def test_delete_node(vpcs, compute_project):
|
||||
assert node not in compute_project.nodes
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_duplicate_vpcs(vpcs, compute_project):
|
||||
|
||||
source_node_id = str(uuid.uuid4())
|
||||
@@ -309,6 +321,7 @@ async def test_duplicate_vpcs(vpcs, compute_project):
|
||||
assert startup == "set pcname PC-2\nip dhcp\n".strip()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_duplicate_ethernet_switch(compute_project):
|
||||
|
||||
with asyncio_patch('gns3server.compute.dynamips.nodes.ethernet_switch.EthernetSwitch.create'):
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import uuid
|
||||
|
||||
from gns3server.compute.notification_manager import NotificationManager
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_queue():
|
||||
|
||||
NotificationManager.reset()
|
||||
@@ -37,6 +39,7 @@ async def test_queue():
|
||||
assert len(notifications._listeners) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_queue_json():
|
||||
|
||||
NotificationManager.reset()
|
||||
@@ -54,6 +57,7 @@ async def test_queue_json():
|
||||
assert len(notifications._listeners) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_queue_json_meta():
|
||||
|
||||
NotificationManager.reset()
|
||||
@@ -72,6 +76,7 @@ async def test_queue_json_meta():
|
||||
assert len(notifications._listeners) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_queue_ping():
|
||||
"""
|
||||
If we don't send a message during a long time (0.5 seconds)
|
||||
|
||||
@@ -19,21 +19,21 @@
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
import asyncio
|
||||
import pytest
|
||||
import aiohttp
|
||||
from uuid import uuid4
|
||||
from unittest.mock import patch
|
||||
|
||||
from tests.utils import asyncio_patch
|
||||
from gns3server.compute.project import Project
|
||||
from gns3server.compute.notification_manager import NotificationManager
|
||||
from gns3server.compute.compute_error import ComputeError, ComputeForbiddenError
|
||||
from gns3server.compute.vpcs import VPCS, VPCSVM
|
||||
from gns3server.config import Config
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = VPCS.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -41,18 +41,21 @@ async def manager(loop, port_manager):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@pytest.mark.asyncio
|
||||
async def node(compute_project, manager):
|
||||
|
||||
node = manager.create_node("test", compute_project.id, "00010203-0405-0607-0809-0a0b0c0d0e0f")
|
||||
return await node
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_affect_uuid():
|
||||
|
||||
p = Project(project_id='00010203-0405-0607-0809-0a0b0c0d0e0f')
|
||||
assert p.id == '00010203-0405-0607-0809-0a0b0c0d0e0f'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_clean_tmp_directory():
|
||||
"""
|
||||
The tmp directory should be clean at project open and close
|
||||
@@ -69,6 +72,7 @@ async def test_clean_tmp_directory():
|
||||
assert not os.path.exists(path)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_path(projects_dir):
|
||||
|
||||
directory = projects_dir
|
||||
@@ -79,6 +83,7 @@ async def test_path(projects_dir):
|
||||
assert os.path.exists(os.path.join(directory, p.id))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_init_path(tmpdir):
|
||||
|
||||
with patch("gns3server.compute.project.Project.is_local", return_value=True):
|
||||
@@ -86,14 +91,16 @@ async def test_init_path(tmpdir):
|
||||
assert p.path == str(tmpdir)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_changing_path_not_allowed(tmpdir):
|
||||
|
||||
with patch("gns3server.compute.project.Project.is_local", return_value=False):
|
||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||
with pytest.raises(ComputeForbiddenError):
|
||||
p = Project(project_id=str(uuid4()))
|
||||
p.path = str(tmpdir)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_variables():
|
||||
|
||||
variables = [{"name": "VAR1", "value": "VAL1"}]
|
||||
@@ -101,6 +108,7 @@ async def test_variables():
|
||||
assert p.variables == variables
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_json():
|
||||
|
||||
p = Project(project_id=str(uuid4()))
|
||||
@@ -111,6 +119,7 @@ async def test_json():
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_json_with_variables():
|
||||
|
||||
variables = [{"name": "VAR1", "value": "VAL1"}]
|
||||
@@ -122,6 +131,7 @@ async def test_json_with_variables():
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_node_working_directory(node, projects_dir):
|
||||
|
||||
directory = projects_dir
|
||||
@@ -131,6 +141,7 @@ async def test_node_working_directory(node, projects_dir):
|
||||
assert os.path.exists(p.node_working_directory(node))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_node_working_path(node, projects_dir):
|
||||
|
||||
directory = projects_dir
|
||||
@@ -141,6 +152,7 @@ async def test_node_working_path(node, projects_dir):
|
||||
assert not os.path.exists(p.node_working_path(node))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_project_delete():
|
||||
|
||||
project = Project(project_id=str(uuid4()))
|
||||
@@ -151,17 +163,19 @@ async def test_project_delete():
|
||||
|
||||
|
||||
@pytest.mark.skipif(not sys.platform.startswith("win") and os.getuid() == 0, reason="Root can delete any project")
|
||||
@pytest.mark.asyncio
|
||||
async def test_project_delete_permission_issue():
|
||||
|
||||
project = Project(project_id=str(uuid4()))
|
||||
directory = project.path
|
||||
assert os.path.exists(directory)
|
||||
os.chmod(directory, 0)
|
||||
with pytest.raises(aiohttp.web.HTTPInternalServerError):
|
||||
with pytest.raises(ComputeError):
|
||||
await project.delete()
|
||||
os.chmod(directory, 700)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_project_add_node(manager):
|
||||
|
||||
project = Project(project_id=str(uuid4()))
|
||||
@@ -170,6 +184,7 @@ async def test_project_add_node(manager):
|
||||
assert len(project.nodes) == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_project_close(node, compute_project):
|
||||
|
||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.close") as mock:
|
||||
@@ -178,6 +193,7 @@ async def test_project_close(node, compute_project):
|
||||
assert node.id not in node.manager._nodes
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_files(tmpdir):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"projects_path": str(tmpdir)}):
|
||||
@@ -204,6 +220,7 @@ async def test_list_files(tmpdir):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_emit():
|
||||
|
||||
with NotificationManager.instance().queue() as queue:
|
||||
@@ -216,6 +233,7 @@ async def test_emit():
|
||||
assert context["project_id"] == project.id
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_project():
|
||||
|
||||
variables = [{"name": "TEST", "value": "VAL"}]
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import aiohttp
|
||||
import pytest
|
||||
|
||||
from gns3server.compute.compute_error import ComputeNotFoundError
|
||||
from gns3server.compute.project_manager import ProjectManager
|
||||
|
||||
|
||||
@@ -31,5 +31,5 @@ def test_create_project():
|
||||
def test_project_not_found():
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
with pytest.raises(aiohttp.web.HTTPNotFound):
|
||||
with pytest.raises(ComputeNotFoundError):
|
||||
pm.get_project('00010203-0405-0607-0809-000000000000')
|
||||
@@ -1,187 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import asyncio
|
||||
|
||||
from tests.utils import asyncio_patch, AsyncioMagicMock
|
||||
from unittest.mock import patch, MagicMock, ANY
|
||||
|
||||
from gns3server.compute.traceng.traceng_vm import TraceNGVM
|
||||
from gns3server.compute.traceng.traceng_error import TraceNGError
|
||||
from gns3server.compute.traceng import TraceNG
|
||||
from gns3server.compute.notification_manager import NotificationManager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
|
||||
m = TraceNG.instance()
|
||||
m.port_manager = port_manager
|
||||
return m
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def vm(compute_project, manager, ubridge_path):
|
||||
|
||||
vm = TraceNGVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager)
|
||||
vm._start_ubridge = AsyncioMagicMock()
|
||||
vm._ubridge_hypervisor = MagicMock()
|
||||
vm._ubridge_hypervisor.is_running.return_value = True
|
||||
return vm
|
||||
|
||||
|
||||
async def test_vm(project, manager):
|
||||
|
||||
vm = TraceNGVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
assert vm.name == "test"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
async def test_vm_invalid_traceng_path(vm, manager):
|
||||
|
||||
with patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._traceng_path", return_value="/tmp/fake/path/traceng"):
|
||||
with pytest.raises(TraceNGError):
|
||||
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
await vm.port_add_nio_binding(0, nio)
|
||||
await vm.start()
|
||||
assert vm.name == "test"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
||||
|
||||
|
||||
async def test_start(vm):
|
||||
|
||||
process = MagicMock()
|
||||
process.returncode = None
|
||||
|
||||
with NotificationManager.instance().queue() as queue:
|
||||
await queue.get(1) # Ping
|
||||
|
||||
vm.ip_address = "192.168.1.1"
|
||||
with patch("sys.platform", return_value="win"):
|
||||
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
|
||||
await vm.start("192.168.1.2")
|
||||
assert mock_exec.call_args[0] == (vm._traceng_path(),
|
||||
'-u',
|
||||
'-c',
|
||||
ANY,
|
||||
'-v',
|
||||
ANY,
|
||||
'-b',
|
||||
'127.0.0.1',
|
||||
'-s',
|
||||
'ICMP',
|
||||
'-f',
|
||||
'192.168.1.1',
|
||||
'192.168.1.2')
|
||||
assert vm.is_running()
|
||||
assert vm.command_line == ' '.join(mock_exec.call_args[0])
|
||||
(action, event, kwargs) = await queue.get(1)
|
||||
assert action == "node.updated"
|
||||
assert event == vm
|
||||
|
||||
|
||||
async def test_stop(vm):
|
||||
|
||||
process = MagicMock()
|
||||
# Wait process kill success
|
||||
future = asyncio.Future()
|
||||
future.set_result(True)
|
||||
process.wait.return_value = future
|
||||
process.returncode = None
|
||||
|
||||
vm.ip_address = "192.168.1.1"
|
||||
with NotificationManager.instance().queue() as queue:
|
||||
with patch("sys.platform", return_value="win"):
|
||||
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||
await vm.port_add_nio_binding(0, nio)
|
||||
|
||||
vm._ubridge_send = AsyncioMagicMock()
|
||||
await vm.start("192.168.1.2")
|
||||
assert vm.is_running()
|
||||
|
||||
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||
await vm.stop()
|
||||
assert vm.is_running() is False
|
||||
|
||||
process.terminate.assert_called_with()
|
||||
|
||||
await queue.get(1) # Ping
|
||||
await queue.get(1) # Started
|
||||
|
||||
(action, event, kwargs) = await queue.get(1)
|
||||
assert action == "node.updated"
|
||||
assert event == vm
|
||||
|
||||
|
||||
async def test_reload(vm):
|
||||
|
||||
process = MagicMock()
|
||||
# Wait process kill success
|
||||
future = asyncio.Future()
|
||||
future.set_result(True)
|
||||
process.wait.return_value = future
|
||||
process.returncode = None
|
||||
|
||||
vm.ip_address = "192.168.1.1"
|
||||
with patch("sys.platform", return_value="win"):
|
||||
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||
await vm.port_add_nio_binding(0, nio)
|
||||
|
||||
vm._ubridge_send = AsyncioMagicMock()
|
||||
await vm.start("192.168.1.2")
|
||||
assert vm.is_running()
|
||||
|
||||
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||
await vm.reload()
|
||||
assert vm.is_running() is True
|
||||
|
||||
#if sys.platform.startswith("win"):
|
||||
# process.send_signal.assert_called_with(1)
|
||||
#else:
|
||||
process.terminate.assert_called_with()
|
||||
|
||||
|
||||
async def test_add_nio_binding_udp(vm):
|
||||
|
||||
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||
await vm.port_add_nio_binding(0, nio)
|
||||
assert nio.lport == 4242
|
||||
|
||||
|
||||
async def test_port_remove_nio_binding(vm):
|
||||
|
||||
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
await vm.port_add_nio_binding(0, nio)
|
||||
await vm.port_remove_nio_binding(0)
|
||||
assert vm._ethernet_adapter.ports[0] is None
|
||||
|
||||
|
||||
async def test_close(vm):
|
||||
|
||||
vm.ip_address = "192.168.1.1"
|
||||
with patch("sys.platform", return_value="win"):
|
||||
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
await vm.start("192.168.1.2")
|
||||
await vm.close()
|
||||
assert vm.is_running() is False
|
||||
@@ -29,7 +29,7 @@ from tests.utils import asyncio_patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
async def manager(port_manager):
|
||||
|
||||
m = VirtualBox.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -72,6 +72,7 @@ def test_vboxmanage_path(manager, tmpdir):
|
||||
assert manager.find_vboxmanage() == path
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_vms(manager):
|
||||
|
||||
vm_list = ['"Windows 8.1" {27b4d095-ff5f-4ac4-bb9d-5f2c7861c1f1}',
|
||||
|
||||
@@ -25,7 +25,8 @@ from gns3server.compute.virtualbox import VirtualBox
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = VirtualBox.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -33,11 +34,13 @@ async def manager(loop, port_manager):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@pytest.mark.asyncio
|
||||
async def vm(compute_project, manager):
|
||||
|
||||
return VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, "test", False)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm(compute_project, manager):
|
||||
|
||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, "test", False)
|
||||
@@ -46,6 +49,7 @@ async def test_vm(compute_project, manager):
|
||||
assert vm.vmname == "test"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rename_vmname(compute_project, manager):
|
||||
"""
|
||||
Rename a VM is not allowed when using a running linked clone
|
||||
@@ -75,6 +79,7 @@ async def test_rename_vmname(compute_project, manager):
|
||||
assert vm._modify_vm.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_valid_virtualbox_api_version(compute_project, manager):
|
||||
|
||||
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute", return_value=["API version: 4_3"]):
|
||||
@@ -83,6 +88,7 @@ async def test_vm_valid_virtualbox_api_version(compute_project, manager):
|
||||
await vm.create()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_invalid_virtualbox_api_version(compute_project, manager):
|
||||
|
||||
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute", return_value=["API version: 4_2"]):
|
||||
@@ -91,6 +97,7 @@ async def test_vm_invalid_virtualbox_api_version(compute_project, manager):
|
||||
await vm.create()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_adapter_add_nio_binding_adapter_not_exist(vm, manager, free_console_port):
|
||||
|
||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||
|
||||
@@ -22,7 +22,8 @@ from gns3server.compute.vmware import VMware
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = VMware.instance()
|
||||
m.port_manager = port_manager
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import asyncio
|
||||
|
||||
from gns3server.compute.vmware.vmware_vm import VMwareVM
|
||||
from gns3server.compute.vmware import VMware
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = VMware.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -31,6 +31,7 @@ async def manager(loop, port_manager):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@pytest.mark.asyncio
|
||||
async def vm(compute_project, manager, tmpdir):
|
||||
|
||||
fake_vmx = str(tmpdir / "test.vmx")
|
||||
@@ -38,12 +39,14 @@ async def vm(compute_project, manager, tmpdir):
|
||||
return VMwareVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, fake_vmx, False)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm(vm):
|
||||
|
||||
assert vm.name == "test"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_json(vm, tmpdir, compute_project):
|
||||
|
||||
assert vm.__json__()["node_directory"] is not None
|
||||
@@ -52,6 +55,7 @@ async def test_json(vm, tmpdir, compute_project):
|
||||
assert vm.__json__()["node_directory"] is not None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_capture(vm, tmpdir, manager, free_console_port):
|
||||
|
||||
output_file = str(tmpdir / "test.pcap")
|
||||
@@ -62,6 +66,7 @@ async def test_start_capture(vm, tmpdir, manager, free_console_port):
|
||||
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_capture(vm, tmpdir, manager, free_console_port):
|
||||
|
||||
output_file = str(tmpdir / "test.pcap")
|
||||
|
||||
@@ -25,6 +25,7 @@ from gns3server.compute.vpcs.vpcs_error import VPCSError
|
||||
from gns3server.compute.project_manager import ProjectManager
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_mac_id(compute_project, port_manager):
|
||||
|
||||
# Cleanup the VPCS object
|
||||
@@ -44,6 +45,7 @@ async def test_get_mac_id(compute_project, port_manager):
|
||||
assert vpcs.get_mac_id(vm3_id) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_mac_id_multiple_project(port_manager):
|
||||
|
||||
# Cleanup the VPCS object
|
||||
@@ -63,6 +65,7 @@ async def test_get_mac_id_multiple_project(port_manager):
|
||||
assert vpcs.get_mac_id(vm3_id) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_mac_id_no_id_available(compute_project, port_manager):
|
||||
|
||||
# Cleanup the VPCS object
|
||||
|
||||
@@ -31,7 +31,8 @@ from gns3server.compute.notification_manager import NotificationManager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def manager(loop, port_manager):
|
||||
@pytest.mark.asyncio
|
||||
async def manager(port_manager):
|
||||
|
||||
m = VPCS.instance()
|
||||
m.port_manager = port_manager
|
||||
@@ -39,7 +40,8 @@ async def manager(loop, port_manager):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def vm(loop, compute_project, manager, tmpdir, ubridge_path):
|
||||
@pytest.mark.asyncio
|
||||
async def vm(compute_project, manager, tmpdir, ubridge_path):
|
||||
|
||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager)
|
||||
vm._vpcs_version = parse_version("0.9")
|
||||
@@ -49,6 +51,7 @@ async def vm(loop, compute_project, manager, tmpdir, ubridge_path):
|
||||
return vm
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm(compute_project, manager):
|
||||
|
||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager)
|
||||
@@ -56,6 +59,7 @@ async def test_vm(compute_project, manager):
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_check_vpcs_version(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.9"):
|
||||
@@ -63,6 +67,7 @@ async def test_vm_check_vpcs_version(vm):
|
||||
assert vm._vpcs_version == parse_version("0.9")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_check_vpcs_version_0_6_1(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.6.1"):
|
||||
@@ -70,6 +75,7 @@ async def test_vm_check_vpcs_version_0_6_1(vm):
|
||||
assert vm._vpcs_version == parse_version("0.6.1")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_invalid_vpcs_version(vm, manager):
|
||||
|
||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.1"):
|
||||
@@ -81,6 +87,7 @@ async def test_vm_invalid_vpcs_version(vm, manager):
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vm_invalid_vpcs_path(vm, manager):
|
||||
|
||||
with patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._vpcs_path", return_value="/tmp/fake/path/vpcs"):
|
||||
@@ -92,6 +99,7 @@ async def test_vm_invalid_vpcs_path(vm, manager):
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start(vm):
|
||||
|
||||
process = MagicMock()
|
||||
@@ -125,6 +133,7 @@ async def test_start(vm):
|
||||
assert event == vm
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_0_6_1(vm):
|
||||
"""
|
||||
Version 0.6.1 doesn't have the -R options. It's not require
|
||||
@@ -157,6 +166,7 @@ async def test_start_0_6_1(vm):
|
||||
assert vm.is_running()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop(vm):
|
||||
|
||||
process = MagicMock()
|
||||
@@ -193,6 +203,7 @@ async def test_stop(vm):
|
||||
assert event == vm
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reload(vm):
|
||||
|
||||
process = MagicMock()
|
||||
@@ -221,6 +232,7 @@ async def test_reload(vm):
|
||||
process.terminate.assert_called_with()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_nio_binding_udp(vm):
|
||||
|
||||
nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||
@@ -229,6 +241,7 @@ async def test_add_nio_binding_udp(vm):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_nio_binding_tap(vm, ethernet_device):
|
||||
|
||||
with patch("gns3server.compute.base_manager.BaseManager.has_privileged_access", return_value=True):
|
||||
@@ -237,6 +250,7 @@ async def test_add_nio_binding_tap(vm, ethernet_device):
|
||||
assert nio.tap_device == ethernet_device
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_port_remove_nio_binding(vm):
|
||||
|
||||
nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
@@ -312,6 +326,7 @@ def test_change_name(vm):
|
||||
assert f.read() == "set pcname beta"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close(vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
|
||||
Reference in new issue
Block a user