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

validation/linux_cgroups_*: Generate TAP output (and outside-validation cleanup) #542

Merged
merged 3 commits into from
Dec 29, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 1 addition & 89 deletions validation/linux_cgroups_blkio.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"fmt"

"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -22,93 +20,7 @@ func main() {
g.AddLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor, rate)
g.AddLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor, rate)
g.AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor, rate)
err := util.RuntimeOutsideValidate(g, cgroups.AbsCgroupPath, func(pid int, path string) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lbd, err := cg.GetBlockIOData(pid, path)
if err != nil {
return err
}
if *lbd.Weight != weight {
return fmt.Errorf("blkio weight is not set correctly, expect: %d, actual: %d", weight, lbd.Weight)
}
if *lbd.LeafWeight != leafWeight {
return fmt.Errorf("blkio leafWeight is not set correctly, expect: %d, actual: %d", weight, lbd.LeafWeight)
}

found := false
for _, wd := range lbd.WeightDevice {
if wd.Major == major && wd.Minor == minor {
found = true
if *wd.Weight != weight {
return fmt.Errorf("blkio weight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, weight, wd.Weight)
}
if *wd.LeafWeight != leafWeight {
return fmt.Errorf("blkio leafWeight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, leafWeight, wd.LeafWeight)
}
}
}
if !found {
return fmt.Errorf("blkio weightDevice for %d:%d is not set", major, minor)
}

found = false
for _, trbd := range lbd.ThrottleReadBpsDevice {
if trbd.Major == major && trbd.Minor == minor {
found = true
if trbd.Rate != rate {
return fmt.Errorf("blkio read bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trbd.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio read bps for %d:%d is not set", major, minor)
}

found = false
for _, twbd := range lbd.ThrottleWriteBpsDevice {
if twbd.Major == major && twbd.Minor == minor {
found = true
if twbd.Rate != rate {
return fmt.Errorf("blkio write bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twbd.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio write bps for %d:%d is not set", major, minor)
}

found = false
for _, trid := range lbd.ThrottleReadIOPSDevice {
if trid.Major == major && trid.Minor == minor {
found = true
if trid.Rate != rate {
return fmt.Errorf("blkio read iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trid.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio read iops for %d:%d is not set", major, minor)
}

found = false
for _, twid := range lbd.ThrottleWriteIOPSDevice {
if twid.Major == major && twid.Minor == minor {
found = true
if twid.Rate != rate {
return fmt.Errorf("blkio write iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twid.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio write iops for %d:%d is not set", major, minor)
}

return nil
})

err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesBlockIO)
if err != nil {
util.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions validation/linux_cgroups_cpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"

rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -19,12 +20,12 @@ func main() {
g.SetLinuxResourcesCPUPeriod(period)
g.SetLinuxResourcesCPUCpus(cpus)
g.SetLinuxResourcesCPUMems(mems)
err := util.RuntimeOutsideValidate(g, cgroups.AbsCgroupPath, func(pid int, path string) error {
err := util.RuntimeOutsideValidate(g, func(config *rspec.Spec, state *rspec.State) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lcd, err := cg.GetCPUData(pid, path)
lcd, err := cg.GetCPUData(state.Pid, config.Linux.CgroupsPath)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions validation/linux_cgroups_hugetlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"

rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -13,12 +14,12 @@ func main() {
g := util.GetDefaultGenerator()
g.SetLinuxCgroupsPath(cgroups.AbsCgroupPath)
g.AddLinuxResourcesHugepageLimit(page, limit)
err := util.RuntimeOutsideValidate(g, cgroups.AbsCgroupPath, func(pid int, path string) error {
err := util.RuntimeOutsideValidate(g, func(config *rspec.Spec, state *rspec.State) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lhd, err := cg.GetHugepageLimitData(pid, path)
lhd, err := cg.GetHugepageLimitData(state.Pid, config.Linux.CgroupsPath)
if err != nil {
return err
}
Expand Down
35 changes: 1 addition & 34 deletions validation/linux_cgroups_memory.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"fmt"

"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -19,38 +17,7 @@ func main() {
g.SetLinuxResourcesMemoryKernelTCP(limit)
g.SetLinuxResourcesMemorySwappiness(swappiness)
g.SetLinuxResourcesMemoryDisableOOMKiller(true)
err := util.RuntimeOutsideValidate(g, cgroups.AbsCgroupPath, func(pid int, path string) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lm, err := cg.GetMemoryData(pid, path)
if err != nil {
return err
}
if limit != *lm.Limit {
return fmt.Errorf("memory limit is not set correctly, expect: %d, actual: %d", limit, *lm.Limit)
}
if limit != *lm.Reservation {
return fmt.Errorf("memory reservation is not set correctly, expect: %d, actual: %d", limit, *lm.Reservation)
}
if limit != *lm.Swap {
return fmt.Errorf("memory swap is not set correctly, expect: %d, actual: %d", limit, *lm.Reservation)
}
if limit != *lm.Kernel {
return fmt.Errorf("memory kernel is not set correctly, expect: %d, actual: %d", limit, *lm.Kernel)
}
if limit != *lm.KernelTCP {
return fmt.Errorf("memory kernelTCP is not set correctly, expect: %d, actual: %d", limit, *lm.Kernel)
}
if swappiness != *lm.Swappiness {
return fmt.Errorf("memory swappiness is not set correctly, expect: %d, actual: %d", swappiness, *lm.Swappiness)
}
if true != *lm.DisableOOMKiller {
return fmt.Errorf("memory oom is not set correctly, expect: %t, actual: %t", true, *lm.DisableOOMKiller)
}
return nil
})
err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesMemory)
if err != nil {
util.Fatal(err)
}
Expand Down
32 changes: 2 additions & 30 deletions validation/linux_cgroups_network.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"fmt"

"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -13,34 +11,8 @@ func main() {
g := util.GetDefaultGenerator()
g.SetLinuxCgroupsPath(cgroups.AbsCgroupPath)
g.SetLinuxResourcesNetworkClassID(id)
err := util.RuntimeOutsideValidate(g, cgroups.AbsCgroupPath, func(pid int, path string) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lnd, err := cg.GetNetworkData(pid, 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
})

g.AddLinuxResourcesNetworkPriorities(ifName, prio)
err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesNetwork)
if err != nil {
util.Fatal(err)
}
Expand Down
18 changes: 1 addition & 17 deletions validation/linux_cgroups_pids.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"fmt"

"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -12,21 +10,7 @@ func main() {
g := util.GetDefaultGenerator()
g.SetLinuxCgroupsPath(cgroups.AbsCgroupPath)
g.SetLinuxResourcesPidsLimit(limit)
err := util.RuntimeOutsideValidate(g, cgroups.AbsCgroupPath, func(pid int, path string) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lpd, err := cg.GetPidsData(pid, path)
if err != nil {
return err
}
if lpd.Limit != limit {
return fmt.Errorf("pids limit is not set correctly, expect: %d, actual: %d", limit, lpd.Limit)
}
return nil
})

err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesPids)
if err != nil {
util.Fatal(err)
}
Expand Down
89 changes: 1 addition & 88 deletions validation/linux_cgroups_relative_blkio.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"fmt"

"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -22,92 +20,7 @@ func main() {
g.AddLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor, rate)
g.AddLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor, rate)
g.AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor, rate)
err := util.RuntimeOutsideValidate(g, cgroups.RelCgroupPath, func(pid int, path string) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lbd, err := cg.GetBlockIOData(pid, path)
if err != nil {
return err
}
if *lbd.Weight != weight {
return fmt.Errorf("blkio weight is not set correctly, expect: %d, actual: %d", weight, lbd.Weight)
}
if *lbd.LeafWeight != leafWeight {
return fmt.Errorf("blkio leafWeight is not set correctly, expect: %d, actual: %d", weight, lbd.LeafWeight)
}

found := false
for _, wd := range lbd.WeightDevice {
if wd.Major == major && wd.Minor == minor {
found = true
if *wd.Weight != weight {
return fmt.Errorf("blkio weight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, weight, wd.Weight)
}
if *wd.LeafWeight != leafWeight {
return fmt.Errorf("blkio leafWeight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, leafWeight, wd.LeafWeight)
}
}
}
if !found {
return fmt.Errorf("blkio weightDevice for %d:%d is not set", major, minor)
}

found = false
for _, trbd := range lbd.ThrottleReadBpsDevice {
if trbd.Major == major && trbd.Minor == minor {
found = true
if trbd.Rate != rate {
return fmt.Errorf("blkio read bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trbd.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio read bps for %d:%d is not set", major, minor)
}

found = false
for _, twbd := range lbd.ThrottleWriteBpsDevice {
if twbd.Major == major && twbd.Minor == minor {
found = true
if twbd.Rate != rate {
return fmt.Errorf("blkio write bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twbd.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio write bps for %d:%d is not set", major, minor)
}

found = false
for _, trid := range lbd.ThrottleReadIOPSDevice {
if trid.Major == major && trid.Minor == minor {
found = true
if trid.Rate != rate {
return fmt.Errorf("blkio read iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trid.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio read iops for %d:%d is not set", major, minor)
}

found = false
for _, twid := range lbd.ThrottleWriteIOPSDevice {
if twid.Major == major && twid.Minor == minor {
found = true
if twid.Rate != rate {
return fmt.Errorf("blkio write iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twid.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio write iops for %d:%d is not set", major, minor)
}

return nil
})
err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesBlockIO)

if err != nil {
util.Fatal(err)
Expand Down
Loading