Browse code

Use getResourcePath instead

Also cleans up tests to not shell out for file creation.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2015/03/31 03:35:37
Showing 2 changed files
... ...
@@ -189,13 +189,13 @@ func (container *Container) parseVolumeMountConfig() (map[string]*Mount, error)
189 189
 		if _, exists := container.Volumes[path]; exists {
190 190
 			continue
191 191
 		}
192
-		realpath, err := symlink.FollowSymlinkInScope(filepath.Join(container.basefs, path), container.basefs)
192
+		realPath, err := container.getResourcePath(path)
193 193
 		if err != nil {
194 194
 			return nil, fmt.Errorf("failed to evaluate the absolute path of symlink")
195 195
 		}
196
-		if stat, err := os.Stat(realpath); err == nil {
196
+		if stat, err := os.Stat(realPath); err == nil {
197 197
 			if !stat.IsDir() {
198
-				return nil, fmt.Errorf("file exists at %s, can't create volume there", realpath)
198
+				return nil, fmt.Errorf("file exists at %s, can't create volume there", realPath)
199 199
 			}
200 200
 		}
201 201
 
... ...
@@ -477,37 +477,34 @@ func TestRunWithVolumesFromExited(t *testing.T) {
477 477
 	logDone("run - regression test for #4979 - volumes-from on exited container")
478 478
 }
479 479
 
480
-// Test create volume in a dirctory which is a symbolic link
480
+// Volume path is a symlink which also exists on the host, and the host side is a file not a dir
481
+// But the volume call is just a normal volume, not a bind mount
481 482
 func TestRunCreateVolumesInSymlinkDir(t *testing.T) {
483
+	testRequires(t, SameHostDaemon)
484
+	testRequires(t, NativeExecDriver)
482 485
 	defer deleteAllContainers()
483
-	// This test has to create a file on host
484
-	hostFile := "/tmp/abcd"
485
-	cmd := exec.Command("touch", hostFile)
486
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
487
-		t.Fatalf("failed to create file %s on host: %v, output: %q", hostFile, err, out)
488
-	}
489
-	defer func() {
490
-		cmd := exec.Command("rm", "-f", hostFile)
491
-		if out, _, err := runCommandWithOutput(cmd); err != nil {
492
-			t.Fatalf("failed to remove file %s on host: %v, output: %q", hostFile, err, out)
493
-		}
494
-	}()
495
-	// create symlink directory /home/test link to /tmp
496
-	cmd = exec.Command(dockerBinary, "run", "--name=test", "busybox", "ln", "-s", "/tmp", "/home/test")
497
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
498
-		t.Fatalf("failed to run container: %v, output: %q", err, out)
486
+	name := "test-volume-symlink"
487
+
488
+	dir, err := ioutil.TempDir("", name)
489
+	if err != nil {
490
+		t.Fatal(err)
499 491
 	}
500
-	cmd = exec.Command(dockerBinary, "commit", "test", "busybox:test")
501
-	out, _, err := runCommandWithOutput(cmd)
492
+	defer os.RemoveAll(dir)
493
+
494
+	f, err := os.OpenFile(filepath.Join(dir, "test"), os.O_CREATE, 0700)
502 495
 	if err != nil {
503
-		t.Fatalf("failed to commit container: %v, output: %q", err, out)
496
+		t.Fatal(err)
504 497
 	}
505
-	cleanedImageID := stripTrailingCharacters(out)
506
-	defer deleteImages(cleanedImageID)
507
-	// directory /home/test is link to /tmp, /home/test/abcd==/tmp/abcd
508
-	cmd = exec.Command(dockerBinary, "run", "-v", "/home/test/abcd", "busybox", "touch", "/home/test/abcd/Hello")
509
-	if out, _, err = runCommandWithOutput(cmd); err != nil {
510
-		t.Fatalf("failed to create volume in symlink directory: %v, output %q", err, out)
498
+	f.Close()
499
+
500
+	dockerFile := fmt.Sprintf("FROM busybox\nRUN mkdir -p %s\nRUN ln -s %s /test", dir, dir)
501
+	if _, err := buildImage(name, dockerFile, false); err != nil {
502
+		t.Fatal(err)
503
+	}
504
+	defer deleteImages(name)
505
+
506
+	if out, _, err := dockerCmd(t, "run", "-v", "/test/test", name); err != nil {
507
+		t.Fatal(err, out)
511 508
 	}
512 509
 
513 510
 	logDone("run - create volume in symlink directory")