mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Fix tests to work with new version of aiohttp (>= 3.0)
This commit is contained in:
1 parent
9ae9209881
commit
ab8dc52ece
18 files changed
+218
-184
No files matched your search
@@ -200,9 +200,11 @@ def test_reload(loop, vm, fake_iou_bin):
|
||||
|
||||
|
||||
def test_close(vm, port_manager, loop):
|
||||
vm._start_ubridge = AsyncioMagicMock(return_value=True)
|
||||
vm._ubridge_send = AsyncioMagicMock()
|
||||
with asyncio_patch("gns3server.compute.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
vm.start()
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||
port = vm.console
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.close()))
|
||||
# Raise an exception if the port is not free
|
||||
|
||||
@@ -150,7 +150,7 @@ def test_stop(loop, vm, running_subprocess_mock):
|
||||
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.adapter_add_nio_binding(0, nio)
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||
assert vm.is_running()
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
|
||||
|
||||
@@ -55,7 +55,7 @@ def test_vm_invalid_traceng_path(vm, manager, loop):
|
||||
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"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.port_add_nio_binding(0, nio)))
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||
assert vm.name == "test"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
||||
@@ -164,16 +164,18 @@ def test_add_nio_binding_udp(vm, async_run):
|
||||
assert nio.lport == 4242
|
||||
|
||||
|
||||
def test_port_remove_nio_binding(vm):
|
||||
def test_port_remove_nio_binding(loop, vm):
|
||||
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
vm.port_remove_nio_binding(0)
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.port_add_nio_binding(0, nio)))
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.port_remove_nio_binding(0)))
|
||||
assert vm._ethernet_adapter.ports[0] is None
|
||||
|
||||
|
||||
def test_close(vm, port_manager, loop):
|
||||
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
vm.start()
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.close()))
|
||||
assert vm.is_running() is False
|
||||
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()):
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.start("192.168.1.2")))
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.close()))
|
||||
assert vm.is_running() is False
|
||||
@@ -70,7 +70,7 @@ def test_vm_invalid_vpcs_version(loop, manager, vm):
|
||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.1"):
|
||||
with pytest.raises(VPCSError):
|
||||
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.port_add_nio_binding(0, nio)))
|
||||
loop.run_until_complete(asyncio.ensure_future(vm._check_vpcs_version()))
|
||||
assert vm.name == "test"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
@@ -80,7 +80,7 @@ def test_vm_invalid_vpcs_path(vm, manager, loop):
|
||||
with patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._vpcs_path", return_value="/tmp/fake/path/vpcs"):
|
||||
with pytest.raises(VPCSError):
|
||||
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.port_add_nio_binding(0, nio)))
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||
assert vm.name == "test"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
||||
@@ -220,17 +220,17 @@ def test_add_nio_binding_udp(vm, async_run):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||
def test_add_nio_binding_tap(vm, ethernet_device):
|
||||
def test_add_nio_binding_tap(vm, ethernet_device, loop):
|
||||
with patch("gns3server.compute.base_manager.BaseManager.has_privileged_access", return_value=True):
|
||||
nio = VPCS.instance().create_nio({"type": "nio_tap", "tap_device": ethernet_device})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.port_add_nio_binding(0, nio)))
|
||||
assert nio.tap_device == ethernet_device
|
||||
|
||||
|
||||
def test_port_remove_nio_binding(vm):
|
||||
def test_port_remove_nio_binding(vm, loop):
|
||||
nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
vm.port_remove_nio_binding(0)
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.port_add_nio_binding(0, nio)))
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.port_remove_nio_binding(0)))
|
||||
assert vm._ethernet_adapter.ports[0] is None
|
||||
|
||||
|
||||
@@ -297,8 +297,10 @@ def test_change_name(vm, tmpdir):
|
||||
|
||||
|
||||
def test_close(vm, port_manager, loop):
|
||||
|
||||
with asyncio_patch("gns3server.compute.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.ensure_future(vm.close()))
|
||||
assert vm.is_running() is False
|
||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||
loop.run_until_complete(asyncio.ensure_future(vm.close()))
|
||||
assert vm.is_running() is False
|
||||
Reference in new issue
Block a user