Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: skip test cgroup parent when use cgroup ns #2693

Merged
merged 1 commit into from Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 13 additions & 19 deletions test/cli_run_cgroup_test.go
Expand Up @@ -2,8 +2,6 @@ package main

import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/alibaba/pouch/test/command"
Expand Down Expand Up @@ -53,28 +51,24 @@ func testRunWithCgroupParent(c *check.C, cgroupParent, name string) {
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)

res = command.PouchRun("exec", name, "cat", "/sys/fs/cgroup/memory/memory.limit_in_bytes")
res.Assert(c, icmd.Success)
c.Assert(util.PartialEqual(res.Stdout(), "314572800"), check.IsNil)

res = command.PouchRun("exec", name, "cat", "/proc/self/cgroup")
res.Assert(c, icmd.Success)
cgroupPaths := util.ParseCgroupFile(res.Stdout())

cgroupMount, err := util.FindCgroupMountpoint("memory")
c.Assert(err, check.IsNil)

file := filepath.Join(cgroupMount, cgroupPaths["memory"], "memory.limit_in_bytes")
if _, err := os.Stat(file); err != nil {
c.Fatalf("failed to Stat container %s cgroup mountpoint %s: %v", name, file, err)
}

out, err := exec.Command("cat", file).Output()
if err != nil {
c.Fatalf("execute cat command failed: %v", err)
}

if !strings.Contains(string(out), "314572800") {
c.Fatalf("unexpected output %s expected %s\n",
string(out), "314572800")
for _, v := range cgroupPaths {
// NOTE: if container in child cgroup namespace, cgroup mount is /,
// skip test since we can not get total cgroup path
if v == "/" {
break
}
if !strings.Contains(v, cgroupParent) {
c.Fatalf("unexpected cgroup path %v, expect to has %s in path", v, cgroupParent)
}
}

}

// TestRunInvalidCgroupParent checks that a specially-crafted cgroup parent
Expand Down
32 changes: 0 additions & 32 deletions test/util/util.go
@@ -1,9 +1,7 @@
package util

import (
"bufio"
"fmt"
"os"
"strings"
"time"

Expand Down Expand Up @@ -97,33 +95,3 @@ func ParseCgroupFile(text string) map[string]string {
}
return cgroups
}

// FindCgroupMountpoint find cgroup mountpoint for a specified subsystem
func FindCgroupMountpoint(subsystem string) (string, error) {
f, err := os.Open("/proc/self/mountinfo")
if err != nil {
return "", err
}
defer f.Close()

scanner := bufio.NewScanner(f)
for scanner.Scan() {
txt := scanner.Text()
fields := strings.Fields(txt)
if len(fields) < 5 {
continue
}
if strings.Contains(txt, "cgroup") {
for _, opt := range strings.Split(fields[len(fields)-1], ",") {
if opt == subsystem {
return fields[4], nil
}
}
}
}
if err := scanner.Err(); err != nil {
return "", err
}

return "", fmt.Errorf("failed to find %s cgroup mountpoint", subsystem)
}