From e3350155204f6d1200aaa82b1c4014ee0708f0fc Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 6 Jun 2016 12:39:29 +0200 Subject: [PATCH] Copy original ressources from VOLUMES Fix #561 --- gns3server/modules/docker/docker_vm.py | 4 ++-- gns3server/modules/docker/resources/init.sh | 11 ++++++++++- tests/modules/docker/test_docker_vm.py | 20 ++++++++++---------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/gns3server/modules/docker/docker_vm.py b/gns3server/modules/docker/docker_vm.py index 709c87e4..4c360d15 100644 --- a/gns3server/modules/docker/docker_vm.py +++ b/gns3server/modules/docker/docker_vm.py @@ -202,7 +202,7 @@ class DockerVM(BaseVM): # We mount our own etc/network network_config = self._create_network_config() - binds.append("{}:/etc/network:rw".format(network_config)) + binds.append("{}:/gns3volumes/etc/network:rw".format(network_config)) self._volumes = ["/etc/network"] @@ -212,7 +212,7 @@ class DockerVM(BaseVM): for volume in volumes.keys(): source = os.path.join(self.working_dir, os.path.relpath(volume, "/")) os.makedirs(source, exist_ok=True) - binds.append("{}:{}".format(source, volume)) + binds.append("{}:/gns3volumes{}".format(source, volume)) self._volumes.append(volume) return binds diff --git a/gns3server/modules/docker/resources/init.sh b/gns3server/modules/docker/resources/init.sh index d1b11d79..9ce22515 100755 --- a/gns3server/modules/docker/resources/init.sh +++ b/gns3server/modules/docker/resources/init.sh @@ -28,9 +28,18 @@ if [ ! -d /tmp/gns3/bin ]; then /gns3/bin/busybox --install -s /tmp/gns3/bin fi -# Restore file permission +# Restore file permission and mount volumes for i in $(echo "$GNS3_VOLUMES" | tr ":" "\n") do + # Copy original files if destination is empty (first start) + if ! [ "$(ls -A /gns3volumes$i)" ]; then + for file in $(ls -A "$i") + do + cp -a "$i/$file" "/gns3volumes$i/$file" + done + fi + + mount --bind "/gns3volumes$i" "$i" if [ -f "$i/.gns3_perms" ] then while IFS=: read PERMS OWNER GROUP FILE diff --git a/tests/modules/docker/test_docker_vm.py b/tests/modules/docker/test_docker_vm.py index feb82c71..5e6151f7 100644 --- a/tests/modules/docker/test_docker_vm.py +++ b/tests/modules/docker/test_docker_vm.py @@ -94,7 +94,7 @@ def test_create(loop, project, manager): "CapAdd": ["ALL"], "Binds": [ "{}:/gns3:ro".format(get_resource("modules/docker/resources")), - "{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) + "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) ], "Privileged": True }, @@ -132,7 +132,7 @@ def test_create_with_tag(loop, project, manager): "CapAdd": ["ALL"], "Binds": [ "{}:/gns3:ro".format(get_resource("modules/docker/resources")), - "{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) + "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) ], "Privileged": True }, @@ -173,7 +173,7 @@ def test_create_vnc(loop, project, manager): "CapAdd": ["ALL"], "Binds": [ "{}:/gns3:ro".format(get_resource("modules/docker/resources")), - "{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")), + "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")), '/tmp/.X11-unix/:/tmp/.X11-unix/' ], "Privileged": True @@ -216,7 +216,7 @@ def test_create_start_cmd(loop, project, manager): "CapAdd": ["ALL"], "Binds": [ "{}:/gns3:ro".format(get_resource("modules/docker/resources")), - "{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) + "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) ], "Privileged": True }, @@ -255,7 +255,7 @@ def test_create_environment(loop, project, manager): "CapAdd": ["ALL"], "Binds": [ "{}:/gns3:ro".format(get_resource("modules/docker/resources")), - "{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) + "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) ], "Privileged": True }, @@ -310,7 +310,7 @@ def test_create_image_not_available(loop, project, manager): "CapAdd": ["ALL"], "Binds": [ "{}:/gns3:ro".format(get_resource("modules/docker/resources")), - "{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) + "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) ], "Privileged": True }, @@ -530,7 +530,7 @@ def test_update(loop, vm): "CapAdd": ["ALL"], "Binds": [ "{}:/gns3:ro".format(get_resource("modules/docker/resources")), - "{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) + "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) ], "Privileged": True }, @@ -598,7 +598,7 @@ def test_update_running(loop, vm): "CapAdd": ["ALL"], "Binds": [ "{}:/gns3:ro".format(get_resource("modules/docker/resources")), - "{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) + "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) ], "Privileged": True }, @@ -875,8 +875,8 @@ def test_mount_binds(vm, tmpdir): dst = os.path.join(vm.working_dir, "test/experimental") assert vm._mount_binds(image_infos) == [ "{}:/gns3:ro".format(get_resource("modules/docker/resources")), - "{}:/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")), - "{}:{}".format(dst, "/test/experimental") + "{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")), + "{}:/gns3volumes{}".format(dst, "/test/experimental") ] assert vm._volumes == ["/etc/network", "/test/experimental"]