From 844fc5f77c9443b4605949219a8a3c8523249025 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Tue, 21 Jul 2015 08:59:12 -0700 Subject: [PATCH] Fix cgroup parent tests After merging mounting cgroups in container this tests doing wrong checks. Cgroup paths could be prepended by other cgroups from host. Signed-off-by: Alexander Morozov --- integration-cli/docker_cli_run_unix_test.go | 32 ++++++++++----------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/integration-cli/docker_cli_run_unix_test.go b/integration-cli/docker_cli_run_unix_test.go index 8da0fc769b..8b7cfd4055 100644 --- a/integration-cli/docker_cli_run_unix_test.go +++ b/integration-cli/docker_cli_run_unix_test.go @@ -100,17 +100,9 @@ func (s *DockerSuite) TestRunContainerWithCgroupParent(c *check.C) { testRequires(c, NativeExecDriver) cgroupParent := "test" - data, err := ioutil.ReadFile("/proc/self/cgroup") - if err != nil { - c.Fatalf("failed to read '/proc/self/cgroup - %v", err) - } - selfCgroupPaths := parseCgroupPaths(string(data)) - selfCpuCgroup, found := selfCgroupPaths["memory"] - if !found { - c.Fatalf("unable to find self cpu cgroup path. CgroupsPath: %v", selfCgroupPaths) - } + name := "cgroup-test" - out, _, err := dockerCmdWithError(c, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup") + out, _, err := dockerCmdWithError(c, "run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup") if err != nil { c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err) } @@ -118,16 +110,18 @@ func (s *DockerSuite) TestRunContainerWithCgroupParent(c *check.C) { if len(cgroupPaths) == 0 { c.Fatalf("unexpected output - %q", string(out)) } - found = false - expectedCgroupPrefix := path.Join(selfCpuCgroup, cgroupParent) + id, err := getIDByName(name) + c.Assert(err, check.IsNil) + expectedCgroup := path.Join(cgroupParent, id) + found := false for _, path := range cgroupPaths { - if strings.HasPrefix(path, expectedCgroupPrefix) { + if strings.HasSuffix(path, expectedCgroup) { found = true break } } if !found { - c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have prefix %q. Cgroup Paths: %v", expectedCgroupPrefix, cgroupPaths) + c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) } } @@ -135,7 +129,8 @@ func (s *DockerSuite) TestRunContainerWithCgroupParentAbsPath(c *check.C) { testRequires(c, NativeExecDriver) cgroupParent := "/cgroup-parent/test" - out, _, err := dockerCmdWithError(c, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup") + name := "cgroup-test" + out, _, err := dockerCmdWithError(c, "run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup") if err != nil { c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err) } @@ -143,15 +138,18 @@ func (s *DockerSuite) TestRunContainerWithCgroupParentAbsPath(c *check.C) { if len(cgroupPaths) == 0 { c.Fatalf("unexpected output - %q", string(out)) } + id, err := getIDByName(name) + c.Assert(err, check.IsNil) + expectedCgroup := path.Join(cgroupParent, id) found := false for _, path := range cgroupPaths { - if strings.HasPrefix(path, cgroupParent) { + if strings.HasSuffix(path, expectedCgroup) { found = true break } } if !found { - c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have prefix %q. Cgroup Paths: %v", cgroupParent, cgroupPaths) + c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) } }