Skip to content

Commit

Permalink
add cgroup network test for runtime
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 Dec 5, 2017
1 parent 72e67e5 commit 6351044
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions validation/linux_cgroups_network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"

"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)

func main() {
var id, prio uint32 = 255, 10
ifName := "lo"
g := util.GetDefaultGenerator()
g.SetLinuxCgroupsPath("/test")
g.SetLinuxResourcesNetworkClassID(id)
err := util.RuntimeOutsideValidate(g, func(path string) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lnd, err := cg.GetNetworkData(path)
if err != nil {
return err
}
if *lnd.ClassID != id {
return fmt.Errorf("network ID is not set correctly, expect: %d, actual: %d", id, lnd.ClassID)
}
found := false
for _, lip := range lnd.Priorities {
if lip.Name == ifName {
found = true
if lip.Priority != prio {
return fmt.Errorf("network priority for %s is not set correctly, expect: %d, actual: %d", ifName, prio, lip.Priority)
}
}
}
if !found {
return fmt.Errorf("network priority for %s is not set correctly", ifName)
}

return nil
})

if err != nil {
util.Fatal(err)
}
}

0 comments on commit 6351044

Please sign in to comment.