From e8bd67181533222c192cca19a4279c85db48875e Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 21 Aug 2017 19:03:58 -0400 Subject: [PATCH] Remove testutil.ParseCgroupPaths Signed-off-by: Daniel Nephin --- integration-cli/docker_cli_build_test.go | 2 +- integration-cli/docker_cli_daemon_test.go | 3 +-- integration-cli/docker_cli_run_test.go | 4 ++-- integration-cli/utils_test.go | 16 +++++++++++++ pkg/testutil/utils.go | 14 ------------ pkg/testutil/utils_test.go | 28 ----------------------- 6 files changed, 20 insertions(+), 47 deletions(-) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index c7630ae1d1..b6fc4a0768 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -4071,7 +4071,7 @@ func (s *DockerSuite) TestBuildContainerWithCgroupParent(c *check.C) { if err != nil { c.Fatalf("failed to read '/proc/self/cgroup - %v", err) } - selfCgroupPaths := testutil.ParseCgroupPaths(string(data)) + selfCgroupPaths := ParseCgroupPaths(string(data)) _, found := selfCgroupPaths["memory"] if !found { c.Fatalf("unable to find self memory cgroup path. CgroupsPath: %v", selfCgroupPaths) diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 55b45a9724..3155a351c4 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -34,7 +34,6 @@ import ( "github.com/docker/docker/opts" "github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil" icmd "github.com/docker/docker/pkg/testutil/cmd" units "github.com/docker/go-units" "github.com/docker/libnetwork/iptables" @@ -1883,7 +1882,7 @@ func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *check.C) { out, err := s.d.Cmd("run", "--name", name, "busybox", "cat", "/proc/self/cgroup") c.Assert(err, checker.IsNil) - cgroupPaths := testutil.ParseCgroupPaths(string(out)) + cgroupPaths := ParseCgroupPaths(string(out)) c.Assert(len(cgroupPaths), checker.Not(checker.Equals), 0, check.Commentf("unexpected output - %q", string(out))) out, err = s.d.Cmd("inspect", "-f", "{{.Id}}", name) c.Assert(err, checker.IsNil) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 121f0220c3..fa2d7b31d9 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -3337,7 +3337,7 @@ func testRunContainerWithCgroupParent(c *check.C, cgroupParent, name string) { if err != nil { c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err) } - cgroupPaths := testutil.ParseCgroupPaths(string(out)) + cgroupPaths := ParseCgroupPaths(string(out)) if len(cgroupPaths) == 0 { c.Fatalf("unexpected output - %q", string(out)) } @@ -3377,7 +3377,7 @@ func testRunInvalidCgroupParent(c *check.C, cgroupParent, cleanCgroupParent, nam c.Fatalf("SECURITY: --cgroup-parent with ../../ relative paths cause files to be created in the host (this is bad) !!") } - cgroupPaths := testutil.ParseCgroupPaths(string(out)) + cgroupPaths := ParseCgroupPaths(string(out)) if len(cgroupPaths) == 0 { c.Fatalf("unexpected output - %q", string(out)) } diff --git a/integration-cli/utils_test.go b/integration-cli/utils_test.go index 2725ddf4f7..5eaf99e9d0 100644 --- a/integration-cli/utils_test.go +++ b/integration-cli/utils_test.go @@ -3,6 +3,8 @@ package main import ( "os/exec" + "strings" + "github.com/docker/docker/pkg/testutil/cmd" ) @@ -30,3 +32,17 @@ func transformCmd(execCmd *exec.Cmd) cmd.Cmd { Stdout: execCmd.Stdout, } } + +// ParseCgroupPaths parses 'procCgroupData', which is output of '/proc//cgroup', and returns +// a map which cgroup name as key and path as value. +func ParseCgroupPaths(procCgroupData string) map[string]string { + cgroupPaths := map[string]string{} + for _, line := range strings.Split(procCgroupData, "\n") { + parts := strings.Split(line, ":") + if len(parts) != 3 { + continue + } + cgroupPaths[parts[1]] = parts[2] + } + return cgroupPaths +} diff --git a/pkg/testutil/utils.go b/pkg/testutil/utils.go index c824442061..d694153265 100644 --- a/pkg/testutil/utils.go +++ b/pkg/testutil/utils.go @@ -77,17 +77,3 @@ func RandomTmpDirPath(s string, platform string) string { } return filepath.ToSlash(path) // Using / } - -// ParseCgroupPaths parses 'procCgroupData', which is output of '/proc//cgroup', and returns -// a map which cgroup name as key and path as value. -func ParseCgroupPaths(procCgroupData string) map[string]string { - cgroupPaths := map[string]string{} - for _, line := range strings.Split(procCgroupData, "\n") { - parts := strings.Split(line, ":") - if len(parts) != 3 { - continue - } - cgroupPaths[parts[1]] = parts[2] - } - return cgroupPaths -} diff --git a/pkg/testutil/utils_test.go b/pkg/testutil/utils_test.go index 929d53542e..b10ee31035 100644 --- a/pkg/testutil/utils_test.go +++ b/pkg/testutil/utils_test.go @@ -71,31 +71,3 @@ func TestRandomTmpDirPath(t *testing.T) { t.Fatalf("Expected generated path to be %d, got %d", expectedSize, len(path)) } } - -func TestParseCgroupPathsEmpty(t *testing.T) { - cgroupMap := ParseCgroupPaths("") - if len(cgroupMap) != 0 { - t.Fatalf("Expected an empty map, got %v", cgroupMap) - } - cgroupMap = ParseCgroupPaths("\n") - if len(cgroupMap) != 0 { - t.Fatalf("Expected an empty map, got %v", cgroupMap) - } - cgroupMap = ParseCgroupPaths("something:else\nagain:here") - if len(cgroupMap) != 0 { - t.Fatalf("Expected an empty map, got %v", cgroupMap) - } -} - -func TestParseCgroupPaths(t *testing.T) { - cgroupMap := ParseCgroupPaths("2:memory:/a\n1:cpuset:/b") - if len(cgroupMap) != 2 { - t.Fatalf("Expected a map with 2 entries, got %v", cgroupMap) - } - if value, ok := cgroupMap["memory"]; !ok || value != "/a" { - t.Fatalf("Expected cgroupMap to contains an entry for 'memory' with value '/a', got %v", cgroupMap) - } - if value, ok := cgroupMap["cpuset"]; !ok || value != "/b" { - t.Fatalf("Expected cgroupMap to contains an entry for 'cpuset' with value '/b', got %v", cgroupMap) - } -}