1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Merge branch '1.5' into 2.0

This commit is contained in:
Julien Duponchelle 2016-06-14 09:50:07 +02:00
commit 52f852bc6d
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
3 changed files with 17 additions and 9 deletions

View File

@ -325,7 +325,7 @@ class DockerVM(BaseNode):
aux = self.aux aux = self.aux
state = yield from self._get_container_state() state = yield from self._get_container_state()
yield from self.close() yield from self.reset()
yield from self.create() yield from self.create()
self.console = console self.console = console
self.aux = aux self.aux = aux
@ -421,7 +421,8 @@ class DockerVM(BaseNode):
if shutil.which("Xvfb") is None or shutil.which("x11vnc") is None: if shutil.which("Xvfb") is None or shutil.which("x11vnc") is None:
raise DockerError("Please install Xvfb and x11vnc before using the VNC support") raise DockerError("Please install Xvfb and x11vnc before using the VNC support")
self._xvfb_process = yield from asyncio.create_subprocess_exec("Xvfb", "-nolisten", "tcp", ":{}".format(self._display), "-screen", "0", self._console_resolution + "x16") self._xvfb_process = yield from asyncio.create_subprocess_exec("Xvfb", "-nolisten", "tcp", ":{}".format(self._display), "-screen", "0", self._console_resolution + "x16")
self._x11vnc_process = yield from asyncio.create_subprocess_exec("x11vnc", "-forever", "-nopw", "-shared", "-geometry", self._console_resolution, "-display", "WAIT:{}".format(self._display), "-rfbport", str(self.console), "-noncache", "-listen", self._manager.port_manager.console_host) # We pass a port for TCPV6 due to a crash in X11VNC if not here: https://github.com/GNS3/gns3-server/issues/569
self._x11vnc_process = yield from asyncio.create_subprocess_exec("x11vnc", "-forever", "-nopw", "-shared", "-geometry", self._console_resolution, "-display", "WAIT:{}".format(self._display), "-rfbport", str(self.console), "-rfbportv6", str(self.console), "-noncache", "-listen", self._manager.port_manager.console_host)
x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display)) x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display))
yield from wait_for_file_creation(x11_socket) yield from wait_for_file_creation(x11_socket)
@ -570,7 +571,10 @@ class DockerVM(BaseNode):
if not (yield from super().close()): if not (yield from super().close()):
return False return False
yield from self.reset()
@asyncio.coroutine
def reset(self):
try: try:
if self.console_type == "vnc": if self.console_type == "vnc":
if self._x11vnc_process: if self._x11vnc_process:
@ -587,7 +591,9 @@ class DockerVM(BaseNode):
state = yield from self._get_container_state() state = yield from self._get_container_state()
if state == "paused" or state == "running": if state == "paused" or state == "running":
yield from self.stop() yield from self.stop()
yield from self.manager.query("DELETE", "containers/{}".format(self._cid), params={"force": 1}) # v 1/True/true or 0/False/false, Remove the volumes associated to the container. Default false.
# force - 1/True/true or 0/False/false, Kill then remove the container. Default false.
yield from self.manager.query("DELETE", "containers/{}".format(self._cid), params={"force": 1, "v": 1})
log.info("Docker container '{name}' [{image}] removed".format( log.info("Docker container '{name}' [{image}] removed".format(
name=self._name, image=self._image)) name=self._name, image=self._image))

View File

@ -550,6 +550,8 @@ def send_recv_loop(epoll, console, router, esc_char, stop_event):
esc_state = True esc_state = True
else: else:
router.write(buf) router.write(buf)
except ConnectionError as e:
pass
finally: finally:
router.unregister(epoll) router.unregister(epoll)
console.unregister(epoll) console.unregister(epoll)

View File

@ -520,7 +520,7 @@ def test_update(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.async(vm.update())) loop.run_until_complete(asyncio.async(vm.update()))
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1}) mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
mock_query.assert_any_call("POST", "containers/create", data={ mock_query.assert_any_call("POST", "containers/create", data={
"Tty": True, "Tty": True,
"OpenStdin": True, "OpenStdin": True,
@ -588,7 +588,7 @@ def test_update_running(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.async(vm.update())) loop.run_until_complete(asyncio.async(vm.update()))
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1}) mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
mock_query.assert_any_call("POST", "containers/create", data={ mock_query.assert_any_call("POST", "containers/create", data={
"Tty": True, "Tty": True,
"OpenStdin": True, "OpenStdin": True,
@ -624,7 +624,7 @@ def test_delete(loop, vm):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"): with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.delete())) loop.run_until_complete(asyncio.async(vm.delete()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1}) mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
def test_close(loop, vm, port_manager): def test_close(loop, vm, port_manager):
@ -638,7 +638,7 @@ def test_close(loop, vm, port_manager):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"): with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.close())) loop.run_until_complete(asyncio.async(vm.close()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1}) mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
assert vm._closed is True assert vm._closed is True
assert "4242" not in port_manager.udp_ports assert "4242" not in port_manager.udp_ports
@ -653,7 +653,7 @@ def test_close_vnc(loop, vm, port_manager):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"): with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.close())) loop.run_until_complete(asyncio.async(vm.close()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1}) mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
assert vm._closed is True assert vm._closed is True
assert vm._xvfb_process.terminate.called assert vm._xvfb_process.terminate.called
@ -891,7 +891,7 @@ def test_start_vnc(vm, loop):
loop.run_until_complete(asyncio.async(vm._start_vnc())) loop.run_until_complete(asyncio.async(vm._start_vnc()))
assert vm._display is not None assert vm._display is not None
mock_exec.assert_any_call("Xvfb", "-nolisten", "tcp", ":{}".format(vm._display), "-screen", "0", "1280x1024x16") mock_exec.assert_any_call("Xvfb", "-nolisten", "tcp", ":{}".format(vm._display), "-screen", "0", "1280x1024x16")
mock_exec.assert_any_call("x11vnc", "-forever", "-nopw", "-shared", "-geometry", "1280x1024", "-display", "WAIT:{}".format(vm._display), "-rfbport", str(vm.console), "-noncache", "-listen", "127.0.0.1") mock_exec.assert_any_call("x11vnc", "-forever", "-nopw", "-shared", "-geometry", "1280x1024", "-display", "WAIT:{}".format(vm._display), "-rfbport", str(vm.console), "-rfbportv6", str(vm.console), "-noncache", "-listen", "127.0.0.1")
mock_wait.assert_called_with("/tmp/.X11-unix/X{}".format(vm._display)) mock_wait.assert_called_with("/tmp/.X11-unix/X{}".format(vm._display))