Browse code

integration-cli/TestCleanupMounts: fix/improve

`TestCleanupMountsAfterDaemonAndContainerKill` was supposedly written
when the container mounts were visible from the host. Currently they
all live in their own mount namespace and the only visible mount is
the tmpfs one for shareable /dev/shm inside the container (i.e.
/var/lib/docker/containers/<ID>/shm), which will no longer be there
in case of `--default-ipc-mode private` is used, and so the test will
fail. Add a check if any container mounts are visible from the host,
and skip the test if there are none, as there's nothing to check.

`TestCleanupMountsAfterDaemonCrash`: fix in a similar way, keeping
all the other checks it does, and skipping the "mounts gone" check
if there were no mounts visible from the host.

While at it, also fix the tests to use `d.Kill()` in order to not
leave behind a stale `docker.pid` files.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2017/12/20 10:28:13
Showing 1 changed files
... ...
@@ -1441,13 +1441,19 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonAndContainerKill(c *chec
1441 1441
 	out, err := d.Cmd("run", "-d", "busybox", "top")
1442 1442
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
1443 1443
 	id := strings.TrimSpace(out)
1444
-	c.Assert(d.Signal(os.Kill), check.IsNil)
1444
+
1445
+	// If there are no mounts with container id visible from the host
1446
+	// (as those are in container's own mount ns), there is nothing
1447
+	// to check here and the test should be skipped.
1445 1448
 	mountOut, err := ioutil.ReadFile("/proc/self/mountinfo")
1446 1449
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
1450
+	if !strings.Contains(string(mountOut), id) {
1451
+		d.Stop(c)
1452
+		c.Skip("no container mounts visible in host ns")
1453
+	}
1447 1454
 
1448
-	// container mounts should exist even after daemon has crashed.
1449
-	comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, d.Root, mountOut)
1450
-	c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment)
1455
+	// kill the daemon
1456
+	c.Assert(d.Kill(), check.IsNil)
1451 1457
 
1452 1458
 	// kill the container
1453 1459
 	icmd.RunCommand(ctrBinary, "--address", "/var/run/docker/containerd/docker-containerd.sock",
... ...
@@ -1459,7 +1465,7 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonAndContainerKill(c *chec
1459 1459
 	// Now, container mounts should be gone.
1460 1460
 	mountOut, err = ioutil.ReadFile("/proc/self/mountinfo")
1461 1461
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
1462
-	comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, d.Root, mountOut)
1462
+	comment := check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, d.Root, mountOut)
1463 1463
 	c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment)
1464 1464
 
1465 1465
 	d.Stop(c)
... ...
@@ -2047,13 +2053,18 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) {
2047 2047
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
2048 2048
 	id := strings.TrimSpace(out)
2049 2049
 
2050
-	c.Assert(s.d.Signal(os.Kill), check.IsNil)
2050
+	// kill the daemon
2051
+	c.Assert(s.d.Kill(), check.IsNil)
2052
+
2053
+	// Check if there are mounts with container id visible from the host.
2054
+	// If not, those mounts exist in container's own mount ns, and so
2055
+	// the following check for mounts being cleared is pointless.
2056
+	skipMountCheck := false
2051 2057
 	mountOut, err := ioutil.ReadFile("/proc/self/mountinfo")
2052 2058
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
2053
-
2054
-	// container mounts should exist even after daemon has crashed.
2055
-	comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.Root, mountOut)
2056
-	c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment)
2059
+	if !strings.Contains(string(mountOut), id) {
2060
+		skipMountCheck = true
2061
+	}
2057 2062
 
2058 2063
 	// restart daemon.
2059 2064
 	s.d.Start(c, "--live-restore")
... ...
@@ -2070,10 +2081,13 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) {
2070 2070
 	out, err = s.d.Cmd("stop", id)
2071 2071
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
2072 2072
 
2073
+	if skipMountCheck {
2074
+		return
2075
+	}
2073 2076
 	// Now, container mounts should be gone.
2074 2077
 	mountOut, err = ioutil.ReadFile("/proc/self/mountinfo")
2075 2078
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
2076
-	comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.Root, mountOut)
2079
+	comment := check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.Root, mountOut)
2077 2080
 	c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment)
2078 2081
 }
2079 2082