diff --git a/gns3server/modules/base_vm.py b/gns3server/modules/base_vm.py index 5845938d..e7ea4d4d 100644 --- a/gns3server/modules/base_vm.py +++ b/gns3server/modules/base_vm.py @@ -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, diff --git a/gns3server/modules/docker/docker_vm.py b/gns3server/modules/docker/docker_vm.py index 2513e7ff..29193240 100644 --- a/gns3server/modules/docker/docker_vm.py +++ b/gns3server/modules/docker/docker_vm.py @@ -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": diff --git a/tests/modules/docker/test_docker_vm.py b/tests/modules/docker/test_docker_vm.py index de1858ca..64c589fb 100644 --- a/tests/modules/docker/test_docker_vm.py +++ b/tests/modules/docker/test_docker_vm.py @@ -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 = {