Skip to content

Commit

Permalink
runtimetest: add validation of cgroups path
Browse files Browse the repository at this point in the history
Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
  • Loading branch information
Ma Shimiao committed Jun 3, 2016
1 parent b610069 commit 946b75e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"bufio"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -244,6 +245,45 @@ func validateROPaths(spec *rspec.Spec) error {
return nil
}

func getThisCgroupPath(subsystem string) (string, error) {
f, err := os.Open("/proc/self/cgroup")
if err != nil {
return "", err
}
defer f.Close()

s := bufio.NewScanner(f)
for s.Scan() {
if err := s.Err(); err != nil {
return "", err
}

text := s.Text()
parts := strings.Split(text, ":")

for _, subs := range strings.Split(parts[1], ",") {
if subs == subsystem {
return parts[2], nil
}
}
}
return "", fmt.Errorf("cgroup %v not found", subsystem)
}

func validateCgroupsPath(spec *rspec.Spec) error {
fmt.Println("validating cgroupsPath")
expectedPath := spec.Linux.CgroupsPath
actualPath, err := getThisCgroupPath("devices")
if err != nil {
return err
}

if expectedPath != nil && *expectedPath != actualPath {
return fmt.Errorf("Cgroup path expected: %v, actual: %v", *expectedPath, actualPath)
}
return nil
}

func main() {
spec, err := loadSpecConfig()
if err != nil {
Expand All @@ -254,6 +294,7 @@ func main() {
validateRootFS,
validateProcess,
validateCapabilities,
validateCgroupsPath,
validateHostname,
validateRlimits,
validateSysctls,
Expand Down

0 comments on commit 946b75e

Please sign in to comment.