Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin authored on 2017/08/22 08:03:58... | ... |
@@ -4071,7 +4071,7 @@ func (s *DockerSuite) TestBuildContainerWithCgroupParent(c *check.C) { |
4071 | 4071 |
if err != nil { |
4072 | 4072 |
c.Fatalf("failed to read '/proc/self/cgroup - %v", err) |
4073 | 4073 |
} |
4074 |
- selfCgroupPaths := testutil.ParseCgroupPaths(string(data)) |
|
4074 |
+ selfCgroupPaths := ParseCgroupPaths(string(data)) |
|
4075 | 4075 |
_, found := selfCgroupPaths["memory"] |
4076 | 4076 |
if !found { |
4077 | 4077 |
c.Fatalf("unable to find self memory cgroup path. CgroupsPath: %v", selfCgroupPaths) |
... | ... |
@@ -34,7 +34,6 @@ import ( |
34 | 34 |
"github.com/docker/docker/opts" |
35 | 35 |
"github.com/docker/docker/pkg/mount" |
36 | 36 |
"github.com/docker/docker/pkg/stringid" |
37 |
- "github.com/docker/docker/pkg/testutil" |
|
38 | 37 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
39 | 38 |
units "github.com/docker/go-units" |
40 | 39 |
"github.com/docker/libnetwork/iptables" |
... | ... |
@@ -1883,7 +1882,7 @@ func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *check.C) { |
1883 | 1883 |
|
1884 | 1884 |
out, err := s.d.Cmd("run", "--name", name, "busybox", "cat", "/proc/self/cgroup") |
1885 | 1885 |
c.Assert(err, checker.IsNil) |
1886 |
- cgroupPaths := testutil.ParseCgroupPaths(string(out)) |
|
1886 |
+ cgroupPaths := ParseCgroupPaths(string(out)) |
|
1887 | 1887 |
c.Assert(len(cgroupPaths), checker.Not(checker.Equals), 0, check.Commentf("unexpected output - %q", string(out))) |
1888 | 1888 |
out, err = s.d.Cmd("inspect", "-f", "{{.Id}}", name) |
1889 | 1889 |
c.Assert(err, checker.IsNil) |
... | ... |
@@ -3337,7 +3337,7 @@ func testRunContainerWithCgroupParent(c *check.C, cgroupParent, name string) { |
3337 | 3337 |
if err != nil { |
3338 | 3338 |
c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err) |
3339 | 3339 |
} |
3340 |
- cgroupPaths := testutil.ParseCgroupPaths(string(out)) |
|
3340 |
+ cgroupPaths := ParseCgroupPaths(string(out)) |
|
3341 | 3341 |
if len(cgroupPaths) == 0 { |
3342 | 3342 |
c.Fatalf("unexpected output - %q", string(out)) |
3343 | 3343 |
} |
... | ... |
@@ -3377,7 +3377,7 @@ func testRunInvalidCgroupParent(c *check.C, cgroupParent, cleanCgroupParent, nam |
3377 | 3377 |
c.Fatalf("SECURITY: --cgroup-parent with ../../ relative paths cause files to be created in the host (this is bad) !!") |
3378 | 3378 |
} |
3379 | 3379 |
|
3380 |
- cgroupPaths := testutil.ParseCgroupPaths(string(out)) |
|
3380 |
+ cgroupPaths := ParseCgroupPaths(string(out)) |
|
3381 | 3381 |
if len(cgroupPaths) == 0 { |
3382 | 3382 |
c.Fatalf("unexpected output - %q", string(out)) |
3383 | 3383 |
} |
... | ... |
@@ -3,6 +3,8 @@ package main |
3 | 3 |
import ( |
4 | 4 |
"os/exec" |
5 | 5 |
|
6 |
+ "strings" |
|
7 |
+ |
|
6 | 8 |
"github.com/docker/docker/pkg/testutil/cmd" |
7 | 9 |
) |
8 | 10 |
|
... | ... |
@@ -30,3 +32,17 @@ func transformCmd(execCmd *exec.Cmd) cmd.Cmd { |
30 | 30 |
Stdout: execCmd.Stdout, |
31 | 31 |
} |
32 | 32 |
} |
33 |
+ |
|
34 |
+// ParseCgroupPaths parses 'procCgroupData', which is output of '/proc/<pid>/cgroup', and returns |
|
35 |
+// a map which cgroup name as key and path as value. |
|
36 |
+func ParseCgroupPaths(procCgroupData string) map[string]string { |
|
37 |
+ cgroupPaths := map[string]string{} |
|
38 |
+ for _, line := range strings.Split(procCgroupData, "\n") { |
|
39 |
+ parts := strings.Split(line, ":") |
|
40 |
+ if len(parts) != 3 { |
|
41 |
+ continue |
|
42 |
+ } |
|
43 |
+ cgroupPaths[parts[1]] = parts[2] |
|
44 |
+ } |
|
45 |
+ return cgroupPaths |
|
46 |
+} |
... | ... |
@@ -77,17 +77,3 @@ func RandomTmpDirPath(s string, platform string) string { |
77 | 77 |
} |
78 | 78 |
return filepath.ToSlash(path) // Using / |
79 | 79 |
} |
80 |
- |
|
81 |
-// ParseCgroupPaths parses 'procCgroupData', which is output of '/proc/<pid>/cgroup', and returns |
|
82 |
-// a map which cgroup name as key and path as value. |
|
83 |
-func ParseCgroupPaths(procCgroupData string) map[string]string { |
|
84 |
- cgroupPaths := map[string]string{} |
|
85 |
- for _, line := range strings.Split(procCgroupData, "\n") { |
|
86 |
- parts := strings.Split(line, ":") |
|
87 |
- if len(parts) != 3 { |
|
88 |
- continue |
|
89 |
- } |
|
90 |
- cgroupPaths[parts[1]] = parts[2] |
|
91 |
- } |
|
92 |
- return cgroupPaths |
|
93 |
-} |
... | ... |
@@ -71,31 +71,3 @@ func TestRandomTmpDirPath(t *testing.T) { |
71 | 71 |
t.Fatalf("Expected generated path to be %d, got %d", expectedSize, len(path)) |
72 | 72 |
} |
73 | 73 |
} |
74 |
- |
|
75 |
-func TestParseCgroupPathsEmpty(t *testing.T) { |
|
76 |
- cgroupMap := ParseCgroupPaths("") |
|
77 |
- if len(cgroupMap) != 0 { |
|
78 |
- t.Fatalf("Expected an empty map, got %v", cgroupMap) |
|
79 |
- } |
|
80 |
- cgroupMap = ParseCgroupPaths("\n") |
|
81 |
- if len(cgroupMap) != 0 { |
|
82 |
- t.Fatalf("Expected an empty map, got %v", cgroupMap) |
|
83 |
- } |
|
84 |
- cgroupMap = ParseCgroupPaths("something:else\nagain:here") |
|
85 |
- if len(cgroupMap) != 0 { |
|
86 |
- t.Fatalf("Expected an empty map, got %v", cgroupMap) |
|
87 |
- } |
|
88 |
-} |
|
89 |
- |
|
90 |
-func TestParseCgroupPaths(t *testing.T) { |
|
91 |
- cgroupMap := ParseCgroupPaths("2:memory:/a\n1:cpuset:/b") |
|
92 |
- if len(cgroupMap) != 2 { |
|
93 |
- t.Fatalf("Expected a map with 2 entries, got %v", cgroupMap) |
|
94 |
- } |
|
95 |
- if value, ok := cgroupMap["memory"]; !ok || value != "/a" { |
|
96 |
- t.Fatalf("Expected cgroupMap to contains an entry for 'memory' with value '/a', got %v", cgroupMap) |
|
97 |
- } |
|
98 |
- if value, ok := cgroupMap["cpuset"]; !ok || value != "/b" { |
|
99 |
- t.Fatalf("Expected cgroupMap to contains an entry for 'cpuset' with value '/b', got %v", cgroupMap) |
|
100 |
- } |
|
101 |
-} |