Skip to content

Commit 6351044

Browse files
author
Ma Shimiao
committed
add cgroup network test for runtime
Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
1 parent 72e67e5 commit 6351044

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/opencontainers/runtime-tools/cgroups"
7+
"github.com/opencontainers/runtime-tools/validation/util"
8+
)
9+
10+
func main() {
11+
var id, prio uint32 = 255, 10
12+
ifName := "lo"
13+
g := util.GetDefaultGenerator()
14+
g.SetLinuxCgroupsPath("/test")
15+
g.SetLinuxResourcesNetworkClassID(id)
16+
err := util.RuntimeOutsideValidate(g, func(path string) error {
17+
cg, err := cgroups.FindCgroup()
18+
if err != nil {
19+
return err
20+
}
21+
lnd, err := cg.GetNetworkData(path)
22+
if err != nil {
23+
return err
24+
}
25+
if *lnd.ClassID != id {
26+
return fmt.Errorf("network ID is not set correctly, expect: %d, actual: %d", id, lnd.ClassID)
27+
}
28+
found := false
29+
for _, lip := range lnd.Priorities {
30+
if lip.Name == ifName {
31+
found = true
32+
if lip.Priority != prio {
33+
return fmt.Errorf("network priority for %s is not set correctly, expect: %d, actual: %d", ifName, prio, lip.Priority)
34+
}
35+
}
36+
}
37+
if !found {
38+
return fmt.Errorf("network priority for %s is not set correctly", ifName)
39+
}
40+
41+
return nil
42+
})
43+
44+
if err != nil {
45+
util.Fatal(err)
46+
}
47+
}

0 commit comments

Comments
 (0)