Browse code

Clean loopbacks in TestDaemonNoSpaceLeftOnDeviceError

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2016/05/07 06:19:27
Showing 1 changed files
... ...
@@ -1922,16 +1922,24 @@ func (s *DockerDaemonSuite) TestDaemonNoSpaceLeftOnDeviceError(c *check.C) {
1922 1922
 	defer os.RemoveAll(testDir)
1923 1923
 	c.Assert(mount.MakeRShared(testDir), checker.IsNil)
1924 1924
 	defer mount.Unmount(testDir)
1925
-	defer mount.Unmount(filepath.Join(testDir, "test-mount"))
1926 1925
 
1927 1926
 	// create a 2MiB image and mount it as graph root
1928 1927
 	// Why in a container? Because `mount` sometimes behaves weirdly and often fails outright on this test in debian:jessie (which is what the test suite runs under if run from the Makefile)
1929 1928
 	dockerCmd(c, "run", "--rm", "-v", testDir+":/test", "busybox", "sh", "-c", "dd of=/test/testfs.img bs=1M seek=2 count=0")
1930 1929
 	out, _, err := runCommandWithOutput(exec.Command("mkfs.ext4", "-F", filepath.Join(testDir, "testfs.img"))) // `mkfs.ext4` is not in busybox
1931 1930
 	c.Assert(err, checker.IsNil, check.Commentf(out))
1932
-	dockerCmd(c, "run", "--privileged", "--rm", "-v", testDir+":/test:shared", "busybox", "sh", "-c", "mkdir -p /test/test-mount && mount -t ext4 -no loop,rw /test/testfs.img /test/test-mount")
1931
+
1932
+	cmd := exec.Command("losetup", "-f", "--show", filepath.Join(testDir, "testfs.img"))
1933
+	loout, err := cmd.CombinedOutput()
1934
+	c.Assert(err, checker.IsNil)
1935
+	loopname := strings.TrimSpace(string(loout))
1936
+	defer exec.Command("losetup", "-d", loopname).Run()
1937
+
1938
+	dockerCmd(c, "run", "--privileged", "--rm", "-v", testDir+":/test:shared", "busybox", "sh", "-c", fmt.Sprintf("mkdir -p /test/test-mount && mount -t ext4 -no loop,rw %v /test/test-mount", loopname))
1939
+	defer mount.Unmount(filepath.Join(testDir, "test-mount"))
1933 1940
 
1934 1941
 	err = s.d.Start("--graph", filepath.Join(testDir, "test-mount"))
1942
+	defer s.d.Stop()
1935 1943
 	c.Assert(err, check.IsNil)
1936 1944
 
1937 1945
 	// pull a repository large enough to fill the mount point