From f5e01452d2c2a07bab48b4e05306ef9446770c4a Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 19 Dec 2017 17:28:13 -0800 Subject: [PATCH] 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//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 --- integration-cli/docker_cli_daemon_test.go | 36 ++++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index fb616261d4..5fbfac9a40 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -1441,13 +1441,19 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonAndContainerKill(c *chec out, err := d.Cmd("run", "-d", "busybox", "top") c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) id := strings.TrimSpace(out) - c.Assert(d.Signal(os.Kill), check.IsNil) + + // If there are no mounts with container id visible from the host + // (as those are in container's own mount ns), there is nothing + // to check here and the test should be skipped. mountOut, err := ioutil.ReadFile("/proc/self/mountinfo") c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) + if !strings.Contains(string(mountOut), id) { + d.Stop(c) + c.Skip("no container mounts visible in host ns") + } - // container mounts should exist even after daemon has crashed. - comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, d.Root, mountOut) - c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment) + // kill the daemon + c.Assert(d.Kill(), check.IsNil) // kill the container icmd.RunCommand(ctrBinary, "--address", "/var/run/docker/containerd/docker-containerd.sock", @@ -1459,7 +1465,7 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonAndContainerKill(c *chec // Now, container mounts should be gone. mountOut, err = ioutil.ReadFile("/proc/self/mountinfo") c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) - comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, d.Root, mountOut) + comment := check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, d.Root, mountOut) c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment) d.Stop(c) @@ -2047,13 +2053,18 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) { c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) id := strings.TrimSpace(out) - c.Assert(s.d.Signal(os.Kill), check.IsNil) + // kill the daemon + c.Assert(s.d.Kill(), check.IsNil) + + // Check if there are mounts with container id visible from the host. + // If not, those mounts exist in container's own mount ns, and so + // the following check for mounts being cleared is pointless. + skipMountCheck := false mountOut, err := ioutil.ReadFile("/proc/self/mountinfo") c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) - - // container mounts should exist even after daemon has crashed. - comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.Root, mountOut) - c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment) + if !strings.Contains(string(mountOut), id) { + skipMountCheck = true + } // restart daemon. s.d.Start(c, "--live-restore") @@ -2070,10 +2081,13 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) { out, err = s.d.Cmd("stop", id) c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) + if skipMountCheck { + return + } // Now, container mounts should be gone. mountOut, err = ioutil.ReadFile("/proc/self/mountinfo") c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) - comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.Root, mountOut) + comment := check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.Root, mountOut) c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment) }