diff --git a/components/engine/integration-cli/docker_cli_build_test.go b/components/engine/integration-cli/docker_cli_build_test.go index e60f4d5a6e..8ae5e05ed8 100644 --- a/components/engine/integration-cli/docker_cli_build_test.go +++ b/components/engine/integration-cli/docker_cli_build_test.go @@ -3532,7 +3532,17 @@ func (s *DockerSuite) TestBuildNotVerboseFailureRemote(c *check.C) { result.Assert(c, icmd.Expected{ ExitCode: 1, }) - if strings.TrimSpace(quietResult.Stderr()) != strings.TrimSpace(result.Combined()) { + + // An error message should contain name server IP and port, like this: + // "dial tcp: lookup something.invalid on 172.29.128.11:53: no such host" + // The IP:port need to be removed in order to not trigger a test failur + // when more than one nameserver is configured. + // While at it, also strip excessive newlines. + normalize := func(msg string) string { + return strings.TrimSpace(regexp.MustCompile("[1-9][0-9.]+:[0-9]+").ReplaceAllLiteralString(msg, "")) + } + + if normalize(quietResult.Stderr()) != normalize(result.Combined()) { c.Fatal(fmt.Errorf("Test[%s] expected that quiet stderr and verbose stdout are equal; quiet [%v], verbose [%v]", name, quietResult.Stderr(), result.Combined())) } } diff --git a/components/engine/integration-cli/docker_cli_daemon_test.go b/components/engine/integration-cli/docker_cli_daemon_test.go index fb616261d4..5fbfac9a40 100644 --- a/components/engine/integration-cli/docker_cli_daemon_test.go +++ b/components/engine/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) } diff --git a/components/engine/integration-cli/docker_cli_run_test.go b/components/engine/integration-cli/docker_cli_run_test.go index e6c1d91fce..1749df07c1 100644 --- a/components/engine/integration-cli/docker_cli_run_test.go +++ b/components/engine/integration-cli/docker_cli_run_test.go @@ -2312,48 +2312,6 @@ func (s *DockerSuite) TestRunModeIpcHost(c *check.C) { } } -func (s *DockerSuite) TestRunModeIpcContainer(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo -n test > /dev/shm/test && touch /dev/mqueue/toto && top") - - id := strings.TrimSpace(out) - state := inspectField(c, id, "State.Running") - if state != "true" { - c.Fatal("Container state is 'not running'") - } - pid1 := inspectField(c, id, "State.Pid") - - parentContainerIpc, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/ipc", pid1)) - if err != nil { - c.Fatal(err) - } - - out, _ = dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "readlink", "/proc/self/ns/ipc") - out = strings.Trim(out, "\n") - if parentContainerIpc != out { - c.Fatalf("IPC different with --ipc=container:%s %s != %s\n", id, parentContainerIpc, out) - } - - catOutput, _ := dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "cat", "/dev/shm/test") - if catOutput != "test" { - c.Fatalf("Output of /dev/shm/test expected test but found: %s", catOutput) - } - - // check that /dev/mqueue is actually of mqueue type - grepOutput, _ := dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "grep", "/dev/mqueue", "/proc/mounts") - if !strings.HasPrefix(grepOutput, "mqueue /dev/mqueue mqueue rw") { - c.Fatalf("Output of 'grep /proc/mounts' expected 'mqueue /dev/mqueue mqueue rw' but found: %s", grepOutput) - } - - lsOutput, _ := dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "ls", "/dev/mqueue") - lsOutput = strings.Trim(lsOutput, "\n") - if lsOutput != "toto" { - c.Fatalf("Output of 'ls /dev/mqueue' expected 'toto' but found: %s", lsOutput) - } -} - func (s *DockerSuite) TestRunModeIpcContainerNotExists(c *check.C) { // Not applicable on Windows as uses Unix-specific capabilities testRequires(c, DaemonIsLinux) diff --git a/components/engine/internal/testutil/helpers.go b/components/engine/internal/testutil/helpers.go index 287b3cb48a..bb36322a80 100644 --- a/components/engine/internal/testutil/helpers.go +++ b/components/engine/internal/testutil/helpers.go @@ -20,8 +20,8 @@ var DevZero io.Reader = devZero{} type devZero struct{} func (d devZero) Read(p []byte) (n int, err error) { - for i := 0; i < len(p); i++ { - p[i] = '\x00' + for i := range p { + p[i] = 0 } return len(p), nil }