mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-31 05:13:49 +02:00
Fix VNC broke after container update
Fix https://github.com/GNS3/gns3-gui/issues/1163
This commit is contained in:
parent
5531a576d1
commit
9b9eddb30c
@ -338,13 +338,17 @@ class BaseVM:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self._console_type == "vnc" and console is not None and console < 5900:
|
if self._console_type == "vnc" and console is not None and console < 5900:
|
||||||
raise VMError("VNC console require a port superior or equal to 5900")
|
raise VMError("VNC console require a port superior or equal to 5900 currently it's {}".format(console))
|
||||||
|
|
||||||
if self._console:
|
if self._console:
|
||||||
self._manager.port_manager.release_tcp_port(self._console, self._project)
|
self._manager.port_manager.release_tcp_port(self._console, self._project)
|
||||||
self._console = None
|
self._console = None
|
||||||
if console is not None:
|
if console is not None:
|
||||||
|
if self.console_type == "vnc":
|
||||||
|
self._console = self._manager.port_manager.reserve_tcp_port(console, self._project, port_range_start=5900, port_range_end=6000)
|
||||||
|
else:
|
||||||
self._console = self._manager.port_manager.reserve_tcp_port(console, self._project)
|
self._console = self._manager.port_manager.reserve_tcp_port(console, self._project)
|
||||||
|
|
||||||
log.info("{module}: '{name}' [{id}]: console port set to {port}".format(module=self.manager.module_name,
|
log.info("{module}: '{name}' [{id}]: console port set to {port}".format(module=self.manager.module_name,
|
||||||
name=self.name,
|
name=self.name,
|
||||||
id=self.id,
|
id=self.id,
|
||||||
|
@ -68,6 +68,7 @@ class DockerVM(BaseVM):
|
|||||||
self._ubridge_hypervisor = None
|
self._ubridge_hypervisor = None
|
||||||
self._temporary_directory = None
|
self._temporary_directory = None
|
||||||
self._telnet_servers = []
|
self._telnet_servers = []
|
||||||
|
self._x11vnc_process = None
|
||||||
|
|
||||||
if adapters is None:
|
if adapters is None:
|
||||||
self.adapters = 1
|
self.adapters = 1
|
||||||
@ -471,6 +472,7 @@ class DockerVM(BaseVM):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if self.console_type == "vnc":
|
if self.console_type == "vnc":
|
||||||
|
if self._x11vnc_process:
|
||||||
self._x11vnc_process.terminate()
|
self._x11vnc_process.terminate()
|
||||||
self._xvfb_process.terminate()
|
self._xvfb_process.terminate()
|
||||||
yield from self._x11vnc_process.wait()
|
yield from self._x11vnc_process.wait()
|
||||||
|
@ -116,7 +116,7 @@ def test_create_vnc(loop, project, manager):
|
|||||||
|
|
||||||
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||||
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
|
||||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", console_type="vnc")
|
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", console_type="vnc", console=5900)
|
||||||
vm._start_vnc = MagicMock()
|
vm._start_vnc = MagicMock()
|
||||||
vm._display = 42
|
vm._display = 42
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.async(vm.create()))
|
||||||
@ -145,6 +145,7 @@ def test_create_vnc(loop, project, manager):
|
|||||||
})
|
})
|
||||||
assert vm._start_vnc.called
|
assert vm._start_vnc.called
|
||||||
assert vm._cid == "e90e34656806"
|
assert vm._cid == "e90e34656806"
|
||||||
|
assert vm._console_type == "vnc"
|
||||||
|
|
||||||
|
|
||||||
def test_create_start_cmd(loop, project, manager):
|
def test_create_start_cmd(loop, project, manager):
|
||||||
@ -485,6 +486,29 @@ def test_update(loop, vm):
|
|||||||
assert vm.aux == original_aux
|
assert vm.aux == original_aux
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_vnc(loop, vm):
|
||||||
|
|
||||||
|
response = {
|
||||||
|
"Id": "e90e34656806",
|
||||||
|
"Warnings": []
|
||||||
|
}
|
||||||
|
|
||||||
|
vm.console_type = "vnc"
|
||||||
|
vm.console = 5900
|
||||||
|
vm._display = "display"
|
||||||
|
original_console = vm.console
|
||||||
|
original_aux = vm.aux
|
||||||
|
|
||||||
|
with asyncio_patch("gns3server.modules.docker.DockerVM._start_vnc"):
|
||||||
|
with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||||
|
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||||
|
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock_query:
|
||||||
|
loop.run_until_complete(asyncio.async(vm.update()))
|
||||||
|
|
||||||
|
assert vm.console == original_console
|
||||||
|
assert vm.aux == original_aux
|
||||||
|
|
||||||
|
|
||||||
def test_update_running(loop, vm):
|
def test_update_running(loop, vm):
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
|
Loading…
Reference in New Issue
Block a user