123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package cm
- import (
- "io/ioutil"
- "os"
- "path"
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- "k8s.io/kubernetes/pkg/util/mount"
- )
- func fakeContainerMgrMountInt() mount.Interface {
- return &mount.FakeMounter{
- MountPoints: []mount.MountPoint{
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpuset"},
- },
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpu"},
- },
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpuacct"},
- },
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "memory"},
- },
- },
- }
- }
- func TestCgroupMountValidationSuccess(t *testing.T) {
- f, err := validateSystemRequirements(fakeContainerMgrMountInt())
- assert.Nil(t, err)
- assert.False(t, f.cpuHardcapping, "cpu hardcapping is expected to be disabled")
- }
- func TestCgroupMountValidationMemoryMissing(t *testing.T) {
- mountInt := &mount.FakeMounter{
- MountPoints: []mount.MountPoint{
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpuset"},
- },
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpu"},
- },
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpuacct"},
- },
- },
- }
- _, err := validateSystemRequirements(mountInt)
- assert.Error(t, err)
- }
- func TestCgroupMountValidationMultipleSubsystem(t *testing.T) {
- mountInt := &mount.FakeMounter{
- MountPoints: []mount.MountPoint{
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpuset", "memory"},
- },
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpu"},
- },
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpuacct"},
- },
- },
- }
- _, err := validateSystemRequirements(mountInt)
- assert.Nil(t, err)
- }
- func TestSoftRequirementsValidationSuccess(t *testing.T) {
- req := require.New(t)
- tempDir, err := ioutil.TempDir("", "")
- req.NoError(err)
- defer os.RemoveAll(tempDir)
- req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_period_us"), []byte("0"), os.ModePerm))
- req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_quota_us"), []byte("0"), os.ModePerm))
- mountInt := &mount.FakeMounter{
- MountPoints: []mount.MountPoint{
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpuset"},
- },
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpu"},
- Path: tempDir,
- },
- {
- Device: "cgroup",
- Type: "cgroup",
- Opts: []string{"rw", "relatime", "cpuacct", "memory"},
- },
- },
- }
- f, err := validateSystemRequirements(mountInt)
- assert.NoError(t, err)
- assert.True(t, f.cpuHardcapping, "cpu hardcapping is expected to be enabled")
- }
|