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

Fix _fix_permissions() garbles permissions in Docker VM. Ref #1428

This commit is contained in:
grossmj 2018-11-25 17:11:42 +07:00
parent df3baffd9b
commit a3044ede77

View File

@ -462,11 +462,10 @@ class DockerVM(BaseNode):
# We can not use the API because docker doesn't expose a websocket api for exec # We can not use the API because docker doesn't expose a websocket api for exec
# https://github.com/GNS3/gns3-gui/issues/1039 # https://github.com/GNS3/gns3-gui/issues/1039
try: try:
process = yield from asyncio.subprocess.create_subprocess_exec( process = yield from asyncio.subprocess.create_subprocess_exec("docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "script", "-qfc", "while true; do TERM=vt100 /gns3/bin/busybox sh; done", "/dev/null",
"docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "script", "-qfc", "while true; do TERM=vt100 /gns3/bin/busybox sh; done", "/dev/null", stdout=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT,
stderr=asyncio.subprocess.STDOUT, stdin=asyncio.subprocess.PIPE)
stdin=asyncio.subprocess.PIPE)
except OSError as e: except OSError as e:
raise DockerError("Could not start auxiliary console process: {}".format(e)) raise DockerError("Could not start auxiliary console process: {}".format(e))
server = AsyncioTelnetServer(reader=process.stdout, writer=process.stdin, binary=True, echo=True) server = AsyncioTelnetServer(reader=process.stdout, writer=process.stdin, binary=True, echo=True)
@ -474,7 +473,7 @@ class DockerVM(BaseNode):
self._telnet_servers.append((yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.aux))) self._telnet_servers.append((yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.aux)))
except OSError as e: except OSError as e:
raise DockerError("Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.aux, e)) raise DockerError("Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.aux, e))
log.debug("Docker container '%s' started listen for auxilary telnet on %d", self.name, self.aux) log.debug("Docker container '%s' started listen for auxiliary telnet on %d", self.name, self.aux)
@asyncio.coroutine @asyncio.coroutine
def _fix_permissions(self): def _fix_permissions(self):
@ -484,6 +483,7 @@ class DockerVM(BaseNode):
""" """
state = yield from self._get_container_state() state = yield from self._get_container_state()
log.info("Docker container '{name}' fix ownership, state = {state}".format(name=self._name, state=state))
if state == "stopped" or state == "exited": if state == "stopped" or state == "exited":
# We need to restart it to fix permissions # We need to restart it to fix permissions
yield from self.manager.query("POST", "containers/{}/start".format(self._cid)) yield from self.manager.query("POST", "containers/{}/start".format(self._cid))
@ -697,14 +697,15 @@ class DockerVM(BaseNode):
if state == "paused": if state == "paused":
yield from self.unpause() yield from self.unpause()
yield from self._fix_permissions() if state == "running":
yield from self._fix_permissions()
state = yield from self._get_container_state() state = yield from self._get_container_state()
if state != "stopped" or state != "exited": if state != "stopped" or state != "exited":
# t=5 number of seconds to wait before killing the container # t=5 number of seconds to wait before killing the container
try: try:
yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5}) yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5})
log.info("Docker container '{name}' [{image}] stopped".format( log.info("Docker container '{name}' [{image}] stopped".format(name=self._name, image=self._image))
name=self._name, image=self._image))
except DockerHttp304Error: except DockerHttp304Error:
# Container is already stopped # Container is already stopped
pass pass