From 63510447a39599351df404b5bf4c87d5f73a5257 Mon Sep 17 00:00:00 2001 From: Ma Shimiao Date: Tue, 5 Dec 2017 19:57:56 +0800 Subject: [PATCH] add cgroup network test for runtime Signed-off-by: Ma Shimiao --- validation/linux_cgroups_network.go | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 validation/linux_cgroups_network.go diff --git a/validation/linux_cgroups_network.go b/validation/linux_cgroups_network.go new file mode 100644 index 000000000..7ca3cd78d --- /dev/null +++ b/validation/linux_cgroups_network.go @@ -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) + } +}