1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00

Fix VNC broke after container update

Fix https://github.com/GNS3/gns3-gui/issues/1163
This commit is contained in:
Julien Duponchelle 2016-04-06 14:57:52 +02:00
parent 5531a576d1
commit 9b9eddb30c
No known key found for this signature in database
GPG Key ID: F1E2485547D4595D
3 changed files with 37 additions and 7 deletions

View File

@ -338,13 +338,17 @@ class BaseVM:
return
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:
self._manager.port_manager.release_tcp_port(self._console, self._project)
self._console = None
if console is not None:
self._console = self._manager.port_manager.reserve_tcp_port(console, self._project)
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)
log.info("{module}: '{name}' [{id}]: console port set to {port}".format(module=self.manager.module_name,
name=self.name,
id=self.id,

View File

@ -68,6 +68,7 @@ class DockerVM(BaseVM):
self._ubridge_hypervisor = None
self._temporary_directory = None
self._telnet_servers = []
self._x11vnc_process = None
if adapters is None:
self.adapters = 1
@ -471,10 +472,11 @@ class DockerVM(BaseVM):
try:
if self.console_type == "vnc":
self._x11vnc_process.terminate()
self._xvfb_process.terminate()
yield from self._x11vnc_process.wait()
yield from self._xvfb_process.wait()
if self._x11vnc_process:
self._x11vnc_process.terminate()
self._xvfb_process.terminate()
yield from self._x11vnc_process.wait()
yield from self._xvfb_process.wait()
state = yield from self._get_container_state()
if state == "paused" or state == "running":

View File

@ -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.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._display = 42
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._cid == "e90e34656806"
assert vm._console_type == "vnc"
def test_create_start_cmd(loop, project, manager):
@ -485,6 +486,29 @@ def test_update(loop, vm):
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):
response = {