mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-16 16:54:51 +02:00
Fix traceng tests.
This commit is contained in:
parent
47e5dfabd8
commit
297bbd91ec
@ -59,6 +59,7 @@ class TraceNGVM(BaseNode):
|
|||||||
self._process = None
|
self._process = None
|
||||||
self._started = False
|
self._started = False
|
||||||
self._ip_address = None
|
self._ip_address = None
|
||||||
|
self._destination = None
|
||||||
self._local_udp_tunnel = None
|
self._local_udp_tunnel = None
|
||||||
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
|
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
|
||||||
|
|
||||||
@ -181,7 +182,9 @@ class TraceNGVM(BaseNode):
|
|||||||
yield from self._stop_ubridge() # make use we start with a fresh uBridge instance
|
yield from self._stop_ubridge() # make use we start with a fresh uBridge instance
|
||||||
try:
|
try:
|
||||||
log.info("Starting TraceNG: {}".format(command))
|
log.info("Starting TraceNG: {}".format(command))
|
||||||
flags = subprocess.CREATE_NEW_CONSOLE
|
flags = 0
|
||||||
|
if hasattr(subprocess, "CREATE_NEW_CONSOLE"):
|
||||||
|
flags = subprocess.CREATE_NEW_CONSOLE
|
||||||
self.command_line = ' '.join(command)
|
self.command_line = ' '.join(command)
|
||||||
self._process = yield from asyncio.create_subprocess_exec(*command,
|
self._process = yield from asyncio.create_subprocess_exec(*command,
|
||||||
cwd=self.working_dir,
|
cwd=self.working_dir,
|
||||||
@ -246,7 +249,7 @@ class TraceNGVM(BaseNode):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
yield from self.stop()
|
yield from self.stop()
|
||||||
yield from self.start()
|
yield from self.start(self._destination)
|
||||||
|
|
||||||
def _terminate_process(self):
|
def _terminate_process(self):
|
||||||
"""
|
"""
|
||||||
@ -402,6 +405,7 @@ class TraceNGVM(BaseNode):
|
|||||||
if not self._ip_address:
|
if not self._ip_address:
|
||||||
raise TraceNGError("Please configure an IP address for this TraceNG node")
|
raise TraceNGError("Please configure an IP address for this TraceNG node")
|
||||||
|
|
||||||
|
self._destination = destination
|
||||||
command = [self._traceng_path()]
|
command = [self._traceng_path()]
|
||||||
# use the local UDP tunnel to uBridge instead
|
# use the local UDP tunnel to uBridge instead
|
||||||
if not self._local_udp_tunnel:
|
if not self._local_udp_tunnel:
|
||||||
|
@ -904,9 +904,11 @@ class Project:
|
|||||||
Start all nodes
|
Start all nodes
|
||||||
"""
|
"""
|
||||||
pool = Pool(concurrency=3)
|
pool = Pool(concurrency=3)
|
||||||
|
emit_warning = True
|
||||||
for node in self.nodes.values():
|
for node in self.nodes.values():
|
||||||
if node.node_type == "traceng":
|
if node.node_type == "traceng" and emit_warning:
|
||||||
#self.controller.notification.emit("log.warning", "TraceNG nodes must be started one by one")
|
self.controller.notification.emit("log.warning", {"message": "TraceNG nodes must be started one by one"})
|
||||||
|
emit_warning = False
|
||||||
continue
|
continue
|
||||||
pool.append(node.start)
|
pool.append(node.start)
|
||||||
yield from pool.join()
|
yield from pool.join()
|
||||||
|
@ -17,12 +17,10 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from tests.utils import asyncio_patch, AsyncioMagicMock
|
from tests.utils import asyncio_patch, AsyncioMagicMock
|
||||||
from gns3server.utils import parse_version
|
from unittest.mock import patch, MagicMock, ANY, PropertyMock
|
||||||
from unittest.mock import patch, MagicMock, ANY
|
|
||||||
|
|
||||||
from gns3server.compute.traceng.traceng_vm import TraceNGVM
|
from gns3server.compute.traceng.traceng_vm import TraceNGVM
|
||||||
from gns3server.compute.traceng.traceng_error import TraceNGError
|
from gns3server.compute.traceng.traceng_error import TraceNGError
|
||||||
@ -30,6 +28,7 @@ from gns3server.compute.traceng import TraceNG
|
|||||||
from gns3server.compute.notification_manager import NotificationManager
|
from gns3server.compute.notification_manager import NotificationManager
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def manager(port_manager):
|
def manager(port_manager):
|
||||||
m = TraceNG.instance()
|
m = TraceNG.instance()
|
||||||
@ -69,19 +68,26 @@ def test_start(loop, vm, async_run):
|
|||||||
with NotificationManager.instance().queue() as queue:
|
with NotificationManager.instance().queue() as queue:
|
||||||
async_run(queue.get(0)) # Ping
|
async_run(queue.get(0)) # Ping
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
vm.ip_address = "192.168.1.1"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
|
with patch("sys.platform", return_value="win"):
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
||||||
assert mock_exec.call_args[0] == (vm._traceng_path(),
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
|
||||||
'-c',
|
loop.run_until_complete(asyncio.async(vm.start("192.168.1.2")))
|
||||||
ANY,
|
assert mock_exec.call_args[0] == (vm._traceng_path(),
|
||||||
'-v',
|
'-u',
|
||||||
ANY,
|
'-c',
|
||||||
'-b',
|
ANY,
|
||||||
'127.0.0.1',
|
'-v',
|
||||||
'10.0.0.1')
|
ANY,
|
||||||
assert vm.is_running()
|
'-b',
|
||||||
assert vm.command_line == ' '.join(mock_exec.call_args[0])
|
'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) = async_run(queue.get(0))
|
(action, event, kwargs) = async_run(queue.get(0))
|
||||||
assert action == "node.updated"
|
assert action == "node.updated"
|
||||||
assert event == vm
|
assert event == vm
|
||||||
@ -96,30 +102,30 @@ def test_stop(loop, vm, async_run):
|
|||||||
process.wait.return_value = future
|
process.wait.return_value = future
|
||||||
process.returncode = None
|
process.returncode = None
|
||||||
|
|
||||||
|
vm.ip_address = "192.168.1.1"
|
||||||
with NotificationManager.instance().queue() as queue:
|
with NotificationManager.instance().queue() as queue:
|
||||||
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
with patch("sys.platform", return_value="win"):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
||||||
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||||
async_run(vm.port_add_nio_binding(0, nio))
|
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||||
|
async_run(vm.port_add_nio_binding(0, nio))
|
||||||
|
|
||||||
async_run(vm.start())
|
vm._ubridge_send = AsyncioMagicMock()
|
||||||
assert vm.is_running()
|
async_run(vm.start("192.168.1.2"))
|
||||||
|
assert vm.is_running()
|
||||||
|
|
||||||
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||||
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
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
|
||||||
process.send_signal.assert_called_with(1)
|
|
||||||
else:
|
|
||||||
process.terminate.assert_called_with()
|
process.terminate.assert_called_with()
|
||||||
|
|
||||||
async_run(queue.get(0)) # Ping
|
async_run(queue.get(0)) # Ping
|
||||||
async_run(queue.get(0)) # Started
|
async_run(queue.get(0)) # Started
|
||||||
|
|
||||||
(action, event, kwargs) = async_run(queue.get(0))
|
(action, event, kwargs) = async_run(queue.get(0))
|
||||||
assert action == "node.updated"
|
assert action == "node.updated"
|
||||||
assert event == vm
|
assert event == vm
|
||||||
|
|
||||||
|
|
||||||
def test_reload(loop, vm, async_run):
|
def test_reload(loop, vm, async_run):
|
||||||
@ -131,22 +137,25 @@ def test_reload(loop, vm, async_run):
|
|||||||
process.wait.return_value = future
|
process.wait.return_value = future
|
||||||
process.returncode = None
|
process.returncode = None
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
vm.ip_address = "192.168.1.1"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
with patch("sys.platform", return_value="win"):
|
||||||
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
|
||||||
async_run(vm.port_add_nio_binding(0, nio))
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||||
async_run(vm.start())
|
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||||
assert vm.is_running()
|
async_run(vm.port_add_nio_binding(0, nio))
|
||||||
|
|
||||||
vm._ubridge_send = AsyncioMagicMock()
|
vm._ubridge_send = AsyncioMagicMock()
|
||||||
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
async_run(vm.start("192.168.1.2"))
|
||||||
async_run(vm.reload())
|
assert vm.is_running()
|
||||||
assert vm.is_running() is True
|
|
||||||
|
|
||||||
#if sys.platform.startswith("win"):
|
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||||
# process.send_signal.assert_called_with(1)
|
async_run(vm.reload())
|
||||||
#else:
|
assert vm.is_running() is True
|
||||||
process.terminate.assert_called_with()
|
|
||||||
|
#if sys.platform.startswith("win"):
|
||||||
|
# process.send_signal.assert_called_with(1)
|
||||||
|
#else:
|
||||||
|
process.terminate.assert_called_with()
|
||||||
|
|
||||||
|
|
||||||
def test_add_nio_binding_udp(vm, async_run):
|
def test_add_nio_binding_udp(vm, async_run):
|
||||||
|
@ -31,11 +31,11 @@ from gns3server.version import __version__
|
|||||||
def test_get(http_compute, windows_platform):
|
def test_get(http_compute, windows_platform):
|
||||||
response = http_compute.get('/capabilities', example=True)
|
response = http_compute.get('/capabilities', example=True)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'nat', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'docker', 'iou', 'traceng'], 'version': __version__, 'platform': sys.platform}
|
assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'nat', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'traceng', 'docker', 'iou'], 'version': __version__, 'platform': sys.platform}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||||
def test_get_on_gns3vm(http_compute, on_gns3vm):
|
def test_get_on_gns3vm(http_compute, on_gns3vm):
|
||||||
response = http_compute.get('/capabilities', example=True)
|
response = http_compute.get('/capabilities', example=True)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'nat', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'docker', 'iou', 'traceng'], 'version': __version__, 'platform': sys.platform}
|
assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'nat', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'traceng', 'docker', 'iou'], 'version': __version__, 'platform': sys.platform}
|
||||||
|
@ -96,7 +96,7 @@ def test_traceng_delete_nio(http_compute, vm):
|
|||||||
def test_traceng_start(http_compute, vm):
|
def test_traceng_start(http_compute, vm):
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM.start", return_value=True) as mock:
|
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM.start", return_value=True) as mock:
|
||||||
response = http_compute.post("/projects/{project_id}/traceng/nodes/{node_id}/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True)
|
response = http_compute.post("/projects/{project_id}/traceng/nodes/{node_id}/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"destination": "192.168.1.2"}, example=True)
|
||||||
assert mock.called
|
assert mock.called
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert response.json["name"] == "TraceNG TEST 1"
|
assert response.json["name"] == "TraceNG TEST 1"
|
||||||
@ -139,9 +139,9 @@ def test_traceng_duplicate(http_compute, vm):
|
|||||||
|
|
||||||
def test_traceng_update(http_compute, vm, tmpdir, free_console_port):
|
def test_traceng_update(http_compute, vm, tmpdir, free_console_port):
|
||||||
response = http_compute.put("/projects/{project_id}/traceng/nodes/{node_id}".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"name": "test",
|
response = http_compute.put("/projects/{project_id}/traceng/nodes/{node_id}".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"name": "test",
|
||||||
"console": free_console_port,
|
"ip_address": "192.168.1.1",
|
||||||
},
|
},
|
||||||
example=True)
|
example=True)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert response.json["name"] == "test"
|
assert response.json["name"] == "test"
|
||||||
assert response.json["console"] == free_console_port
|
assert response.json["ip_address"] == "192.168.1.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user