mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Fix tests
This commit is contained in:
parent
64152c1af8
commit
2e72bc2d3a
@ -590,6 +590,7 @@ class IOUVM(BaseVM):
|
|||||||
self._ioucon_thread = None
|
self._ioucon_thread = None
|
||||||
|
|
||||||
self._terminate_process_iou()
|
self._terminate_process_iou()
|
||||||
|
|
||||||
if self._iou_process.returncode is None:
|
if self._iou_process.returncode is None:
|
||||||
try:
|
try:
|
||||||
yield from gns3server.utils.asyncio.wait_for_process_termination(self._iou_process, timeout=3)
|
yield from gns3server.utils.asyncio.wait_for_process_termination(self._iou_process, timeout=3)
|
||||||
|
@ -24,7 +24,7 @@ import socket
|
|||||||
from tests.utils import asyncio_patch
|
from tests.utils import asyncio_patch
|
||||||
|
|
||||||
|
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock, PropertyMock
|
||||||
from gns3server.modules.iou.iou_vm import IOUVM
|
from gns3server.modules.iou.iou_vm import IOUVM
|
||||||
from gns3server.modules.iou.iou_error import IOUError
|
from gns3server.modules.iou.iou_error import IOUError
|
||||||
from gns3server.modules.iou import IOU
|
from gns3server.modules.iou import IOU
|
||||||
@ -97,11 +97,13 @@ def test_vm_invalid_iouyap_path(project, manager, loop):
|
|||||||
|
|
||||||
def test_start(loop, vm, monkeypatch):
|
def test_start(loop, vm, monkeypatch):
|
||||||
|
|
||||||
|
mock_process = MagicMock()
|
||||||
with patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
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._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_ioucon", return_value=True):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process):
|
||||||
|
mock_process.returncode = None
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
|
|
||||||
@ -111,13 +113,14 @@ def test_start_with_iourc(loop, vm, monkeypatch, tmpdir):
|
|||||||
fake_file = str(tmpdir / "iourc")
|
fake_file = str(tmpdir / "iourc")
|
||||||
with open(fake_file, "w+") as f:
|
with open(fake_file, "w+") as f:
|
||||||
f.write("1")
|
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 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_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._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_ioucon", return_value=True):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as exec_mock:
|
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()))
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
arsgs, kwargs = exec_mock.call_args
|
arsgs, kwargs = exec_mock.call_args
|
||||||
@ -152,11 +155,13 @@ def test_stop(loop, vm):
|
|||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", 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.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||||
assert vm.is_running()
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
process.returncode = None
|
||||||
assert vm.is_running() is False
|
assert vm.is_running()
|
||||||
process.terminate.assert_called_with()
|
loop.run_until_complete(asyncio.async(vm.stop()))
|
||||||
|
assert vm.is_running() is False
|
||||||
|
process.terminate.assert_called_with()
|
||||||
|
|
||||||
|
|
||||||
def test_reload(loop, vm, fake_iou_bin):
|
def test_reload(loop, vm, fake_iou_bin):
|
||||||
@ -166,16 +171,18 @@ def test_reload(loop, vm, fake_iou_bin):
|
|||||||
future = asyncio.Future()
|
future = asyncio.Future()
|
||||||
future.set_result(True)
|
future.set_result(True)
|
||||||
process.wait.return_value = future
|
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._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_ioucon", return_value=True):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||||
assert vm.is_running()
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
loop.run_until_complete(asyncio.async(vm.reload()))
|
assert vm.is_running()
|
||||||
assert vm.is_running() is True
|
loop.run_until_complete(asyncio.async(vm.reload()))
|
||||||
process.terminate.assert_called_with()
|
assert vm.is_running() is True
|
||||||
|
process.terminate.assert_called_with()
|
||||||
|
|
||||||
|
|
||||||
def test_close(vm, port_manager, loop):
|
def test_close(vm, port_manager, loop):
|
||||||
@ -239,7 +246,7 @@ def test_build_command_initial_config(vm, loop):
|
|||||||
with open(filepath, "w+") as f:
|
with open(filepath, "w+") as f:
|
||||||
f.write("service timestamps debug datetime msec\nservice timestamps log datetime msec\nno service password-encryption")
|
f.write("service timestamps debug datetime msec\nservice timestamps log datetime msec\nno service password-encryption")
|
||||||
|
|
||||||
assert loop.run_until_complete(asyncio.async(vm._build_command())) == [vm.path, "-L", "-c", vm.initial_config_file, str(vm.application_id)]
|
assert loop.run_until_complete(asyncio.async(vm._build_command())) == [vm.path, "-L", "-c", os.path.basename(vm.initial_config_file), str(vm.application_id)]
|
||||||
|
|
||||||
|
|
||||||
def test_get_initial_config(vm):
|
def test_get_initial_config(vm):
|
||||||
|
@ -69,8 +69,11 @@ def test_vm_invalid_vpcs_path(project, manager, loop):
|
|||||||
|
|
||||||
|
|
||||||
def test_start(loop, vm):
|
def test_start(loop, vm):
|
||||||
|
process = MagicMock()
|
||||||
|
process.returncode = None
|
||||||
|
|
||||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
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"})
|
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)
|
vm.port_add_nio_binding(0, nio)
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
@ -84,13 +87,16 @@ def test_stop(loop, vm):
|
|||||||
future = asyncio.Future()
|
future = asyncio.Future()
|
||||||
future.set_result(True)
|
future.set_result(True)
|
||||||
process.wait.return_value = future
|
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.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
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"})
|
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)
|
vm.port_add_nio_binding(0, nio)
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.async(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
loop.run_until_complete(asyncio.async(vm.stop()))
|
||||||
assert vm.is_running() is False
|
assert vm.is_running() is False
|
||||||
process.terminate.assert_called_with()
|
process.terminate.assert_called_with()
|
||||||
@ -103,6 +109,7 @@ def test_reload(loop, vm):
|
|||||||
future = asyncio.Future()
|
future = asyncio.Future()
|
||||||
future.set_result(True)
|
future.set_result(True)
|
||||||
process.wait.return_value = future
|
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.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||||
|
Loading…
Reference in New Issue
Block a user