Remove testutil.ParseCgroupPaths
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
1455086c4b
commit
e8bd671815
6 changed files with 20 additions and 47 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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/<pid>/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
|
||||
}
|
||||
|
|
|
@ -77,17 +77,3 @@ func RandomTmpDirPath(s string, platform string) string {
|
|||
}
|
||||
return filepath.ToSlash(path) // Using /
|
||||
}
|
||||
|
||||
// ParseCgroupPaths parses 'procCgroupData', which is output of '/proc/<pid>/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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue