mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Refactor aux port allocation
This move the allocation of aux port to the base vm. Also now the free of console port during the close is in the base VM. An aux port is allocated to the docker container but not used for the moment. Ref https://github.com/GNS3/gns3-gui/issues/1039
This commit is contained in:
12 files changed
+190
-132
No files matched your search
@@ -54,6 +54,7 @@ def test_json(vm, project):
|
||||
'vm_id': vm.id,
|
||||
'adapters': 1,
|
||||
'console': vm.console,
|
||||
'aux': vm.aux,
|
||||
'start_command': vm.start_command,
|
||||
'environment': vm.environment,
|
||||
'vm_directory': vm.working_dir
|
||||
|
||||
@@ -24,6 +24,7 @@ from tests.utils import asyncio_patch
|
||||
|
||||
from unittest.mock import patch, MagicMock
|
||||
from gns3server.modules.vpcs.vpcs_vm import VPCSVM
|
||||
from gns3server.modules.docker.docker_vm import DockerVM
|
||||
from gns3server.modules.vpcs.vpcs_error import VPCSError
|
||||
from gns3server.modules.vm_error import VMError
|
||||
from gns3server.modules.vpcs import VPCS
|
||||
@@ -50,6 +51,19 @@ def test_console(project, manager):
|
||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
vm.console = 2111
|
||||
assert vm.console == 2111
|
||||
vm.console = None
|
||||
assert vm.console is None
|
||||
|
||||
|
||||
def test_change_console_port(vm, port_manager):
|
||||
port1 = port_manager.get_free_tcp_port(vm.project)
|
||||
port2 = port_manager.get_free_tcp_port(vm.project)
|
||||
port_manager.release_tcp_port(port1, vm.project)
|
||||
port_manager.release_tcp_port(port2, vm.project)
|
||||
vm.console = port1
|
||||
vm.console = port2
|
||||
assert vm.console == port2
|
||||
port_manager.reserve_tcp_port(port1, vm.project)
|
||||
|
||||
|
||||
def test_console_vnc_invalid(project, manager):
|
||||
@@ -57,3 +71,53 @@ def test_console_vnc_invalid(project, manager):
|
||||
vm.console_type = "vnc"
|
||||
with pytest.raises(VMError):
|
||||
vm.console = 2012
|
||||
|
||||
|
||||
def test_close(vm, loop, port_manager):
|
||||
assert vm.console is not None
|
||||
|
||||
aux = port_manager.get_free_tcp_port(vm.project)
|
||||
port_manager.release_tcp_port(aux, vm.project)
|
||||
|
||||
vm.aux = aux
|
||||
port = vm.console
|
||||
assert loop.run_until_complete(asyncio.async(vm.close()))
|
||||
# Raise an exception if the port is not free
|
||||
port_manager.reserve_tcp_port(port, vm.project)
|
||||
# Raise an exception if the port is not free
|
||||
port_manager.reserve_tcp_port(aux, vm.project)
|
||||
assert vm.console is None
|
||||
assert vm.aux is None
|
||||
|
||||
# Called twice closed should return False
|
||||
assert loop.run_until_complete(asyncio.async(vm.close())) is False
|
||||
|
||||
|
||||
def test_aux(project, manager, port_manager):
|
||||
aux = port_manager.get_free_tcp_port(project)
|
||||
port_manager.release_tcp_port(aux, project)
|
||||
|
||||
vm = DockerVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "ubuntu", aux=aux)
|
||||
assert vm.aux == aux
|
||||
vm.aux = None
|
||||
assert vm.aux is None
|
||||
|
||||
|
||||
def test_allocate_aux(project, manager):
|
||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
assert vm.aux is None
|
||||
|
||||
# Docker has an aux port by default
|
||||
vm = DockerVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "ubuntu")
|
||||
assert vm.aux is not None
|
||||
|
||||
|
||||
def test_change_aux_port(vm, port_manager):
|
||||
port1 = port_manager.get_free_tcp_port(vm.project)
|
||||
port2 = port_manager.get_free_tcp_port(vm.project)
|
||||
port_manager.release_tcp_port(port1, vm.project)
|
||||
port_manager.release_tcp_port(port2, vm.project)
|
||||
vm.aux = port1
|
||||
vm.aux = port2
|
||||
assert vm.aux == port2
|
||||
port_manager.reserve_tcp_port(port1, vm.project)
|
||||
@@ -273,17 +273,6 @@ def test_get_startup_script_using_default_script(vm):
|
||||
assert vm.script_file == filepath
|
||||
|
||||
|
||||
def test_change_console_port(vm, port_manager):
|
||||
port1 = port_manager.get_free_tcp_port(vm.project)
|
||||
port2 = port_manager.get_free_tcp_port(vm.project)
|
||||
port_manager.release_tcp_port(port1, vm.project)
|
||||
port_manager.release_tcp_port(port2, vm.project)
|
||||
vm.console = port1
|
||||
vm.console = port2
|
||||
assert vm.console == port2
|
||||
port_manager.reserve_tcp_port(port1, vm.project)
|
||||
|
||||
|
||||
def test_change_name(vm, tmpdir):
|
||||
path = os.path.join(vm.working_dir, 'startup.vpc')
|
||||
vm.name = "world"
|
||||
@@ -299,8 +288,5 @@ def test_close(vm, port_manager, loop):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
vm.start()
|
||||
port = vm.console
|
||||
loop.run_until_complete(asyncio.async(vm.close()))
|
||||
# Raise an exception if the port is not free
|
||||
port_manager.reserve_tcp_port(port, vm.project)
|
||||
assert vm.is_running() is False
|
||||
Reference in new issue
Block a user