From 1dd437ecdcd9eaf7a7d18d8f623bd70b98690a01 Mon Sep 17 00:00:00 2001 From: Bernhard Ehlers Date: Thu, 3 Mar 2016 09:12:36 +0100 Subject: [PATCH 1/2] updated docker command line processing --- gns3server/modules/docker/docker_vm.py | 20 +++++++++++++------- gns3server/modules/docker/resources/init.sh | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) mode change 100644 => 100755 gns3server/modules/docker/resources/init.sh diff --git a/gns3server/modules/docker/docker_vm.py b/gns3server/modules/docker/docker_vm.py index 55fc04d5..3ae58910 100644 --- a/gns3server/modules/docker/docker_vm.py +++ b/gns3server/modules/docker/docker_vm.py @@ -195,16 +195,22 @@ class DockerVM(BaseVM): }, "Volumes": {}, "Env": [], - "Cmd": image_infos.get("ContainerConfig", {"Cmd": []})["Cmd"] + "Cmd": [], + "Entrypoint": image_infos.get("Config", {"Entrypoint": []})["Entrypoint"] } - params["Cmd"].insert(0, "/bin/sh") - params["Cmd"].insert(1, "/gns3/init.sh") + + if params["Entrypoint"] is None: + params["Entrypoint"] = [] if self._start_command: - params["Cmd"] += shlex.split(self._start_command) - else: - if len(params["Cmd"]) == 2: - params["Cmd"] += ["/bin/sh"] + params["Cmd"] = shlex.split(self._start_command) + if len(params["Cmd"]) == 0: + params["Cmd"] = image_infos.get("Config", {"Cmd": []})["Cmd"] + if params["Cmd"] is None: + params["Cmd"] = [] + if len(params["Cmd"]) == 0 and len(params["Entrypoint"]) == 0: + params["Cmd"] = ["/bin/sh"] + params["Entrypoint"].insert(0, "/gns3/init.sh") if self._environment: params["Env"] += [e.strip() for e in self._environment.split("\n")] diff --git a/gns3server/modules/docker/resources/init.sh b/gns3server/modules/docker/resources/init.sh old mode 100644 new mode 100755 index d120e395..abd3aa4f --- a/gns3server/modules/docker/resources/init.sh +++ b/gns3server/modules/docker/resources/init.sh @@ -43,4 +43,4 @@ sed -n 's/^ *\(eth[0-9]*\):.*/\1/p' < /proc/net/dev | while read dev; do done # continue normal docker startup -/bin/sh -c "$@" +exec "$@" From ee4b094160d6ef4c2d6c7aff740edb184d2e4d9d Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 4 Mar 2016 09:08:40 +0100 Subject: [PATCH 2/2] Fix tests on @ehlers Docker init patch --- tests/modules/docker/test_docker_vm.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/modules/docker/test_docker_vm.py b/tests/modules/docker/test_docker_vm.py index 0a21f255..2d6113f5 100644 --- a/tests/modules/docker/test_docker_vm.py +++ b/tests/modules/docker/test_docker_vm.py @@ -98,7 +98,8 @@ def test_create(loop, project, manager): "Hostname": "test", "Image": "ubuntu", "Env": [], - "Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"] + "Entrypoint": ["/gns3/init.sh"], + "Cmd": ["/bin/sh"] }) assert vm._cid == "e90e34656806" @@ -135,7 +136,8 @@ def test_create_vnc(loop, project, manager): "Hostname": "test", "Image": "ubuntu", "Env": ['DISPLAY=:42'], - "Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"] + "Entrypoint": ["/gns3/init.sh"], + "Cmd": ["/bin/sh"] }) assert vm._start_vnc.called assert vm._cid == "e90e34656806" @@ -163,7 +165,8 @@ def test_create_start_cmd(loop, project, manager): "Privileged": True }, "Volumes": {}, - "Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/ls"], + "Entrypoint": ["/gns3/init.sh"], + "Cmd": ["/bin/ls"], "NetworkDisabled": True, "Name": "test", "Hostname": "test", @@ -200,7 +203,8 @@ def test_create_environment(loop, project, manager): "Name": "test", "Hostname": "test", "Image": "ubuntu", - "Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"] + "Entrypoint": ["/gns3/init.sh"], + "Cmd": ["/bin/sh"] }) assert vm._cid == "e90e34656806" @@ -246,7 +250,8 @@ def test_create_image_not_available(loop, project, manager): "Hostname": "test", "Image": "ubuntu", "Env": [], - "Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"] + "Entrypoint": ["/gns3/init.sh"], + "Cmd": ["/bin/sh"] }) assert vm._cid == "e90e34656806" mock_pull.assert_called_with("ubuntu") @@ -456,7 +461,8 @@ def test_update(loop, vm): "Hostname": "test", "Image": "ubuntu", "Env": [], - "Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"] + "Entrypoint": ["/gns3/init.sh"], + "Cmd": ["/bin/sh"] }) assert vm.console == original_console @@ -493,7 +499,8 @@ def test_update_running(loop, vm): "Hostname": "test", "Image": "ubuntu", "Env": [], - "Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"] + "Entrypoint": ["/gns3/init.sh"], + "Cmd": ["/bin/sh"] }) assert vm.console == original_console