Skip to content

Commit

Permalink
Check integration test requirements using daemon
Browse files Browse the repository at this point in the history
When running against a remote daemon, we cannot use the local
filesystem to determine configuration.

Signed-off-by: Christopher Crone <[email protected]>
  • Loading branch information
chris-crone committed Sep 14, 2017
1 parent 0bdba0e commit b1fb419
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
6 changes: 3 additions & 3 deletions integration-cli/docker_cli_run_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ func (s *DockerSuite) TestRunWithSwappinessInvalid(c *check.C) {
}

func (s *DockerSuite) TestRunWithMemoryReservation(c *check.C) {
testRequires(c, memoryReservationSupport)
testRequires(c, SameHostDaemon, memoryReservationSupport)

file := "/sys/fs/cgroup/memory/memory.soft_limit_in_bytes"
out, _ := dockerCmd(c, "run", "--memory-reservation", "200M", "--name", "test", "busybox", "cat", file)
Expand All @@ -689,7 +689,7 @@ func (s *DockerSuite) TestRunWithMemoryReservation(c *check.C) {

func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *check.C) {
testRequires(c, memoryLimitSupport)
testRequires(c, memoryReservationSupport)
testRequires(c, SameHostDaemon, memoryReservationSupport)
out, _, err := dockerCmdWithError("run", "-m", "500M", "--memory-reservation", "800M", "busybox", "true")
c.Assert(err, check.NotNil)
expected := "Minimum memory limit can not be less than memory reservation limit"
Expand Down Expand Up @@ -1401,7 +1401,7 @@ func (s *DockerSuite) TestRunDeviceSymlink(c *check.C) {

// TestRunPIDsLimit makes sure the pids cgroup is set with --pids-limit
func (s *DockerSuite) TestRunPIDsLimit(c *check.C) {
testRequires(c, pidsLimit)
testRequires(c, SameHostDaemon, pidsLimit)

file := "/sys/fs/cgroup/pids/pids.max"
out, _ := dockerCmd(c, "run", "--name", "skittles", "--pids-limit", "4", "busybox", "cat", file)
Expand Down
3 changes: 1 addition & 2 deletions integration-cli/docker_cli_update_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/parsers/kernel"
"github.com/go-check/check"
"github.com/kr/pty"
)
Expand Down Expand Up @@ -139,7 +138,7 @@ func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) {
func (s *DockerSuite) TestUpdateKernelMemoryUninitialized(c *check.C) {
testRequires(c, DaemonIsLinux, kernelMemorySupport)

isNewKernel := kernel.CheckKernelVersion(4, 6, 0)
isNewKernel := CheckKernelVersion(4, 6, 0)
name := "test-update-container"
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
_, _, err := dockerCmdWithError("update", "--kernel-memory", "100M", name)
Expand Down
24 changes: 13 additions & 11 deletions integration-cli/requirements_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,51 @@ var (
)

func cpuCfsPeriod() bool {
return SysInfo.CPUCfsPeriod
return testEnv.DaemonInfo.CPUCfsPeriod
}

func cpuCfsQuota() bool {
return SysInfo.CPUCfsQuota
return testEnv.DaemonInfo.CPUCfsQuota
}

func cpuShare() bool {
return SysInfo.CPUShares
return testEnv.DaemonInfo.CPUShares
}

func oomControl() bool {
return SysInfo.OomKillDisable
return testEnv.DaemonInfo.OomKillDisable
}

func pidsLimit() bool {
return SysInfo.PidsLimit
}

func kernelMemorySupport() bool {
return SysInfo.KernelMemory
return testEnv.DaemonInfo.KernelMemory
}

func memoryLimitSupport() bool {
return SysInfo.MemoryLimit
return testEnv.DaemonInfo.MemoryLimit
}

func memoryReservationSupport() bool {
return SysInfo.MemoryReservation
}

func swapMemorySupport() bool {
return SysInfo.SwapLimit
return testEnv.DaemonInfo.SwapLimit
}

func memorySwappinessSupport() bool {
return SysInfo.MemorySwappiness
return SameHostDaemon() && SysInfo.MemorySwappiness
}

func blkioWeight() bool {
return SysInfo.BlkioWeight
return SameHostDaemon() && SysInfo.BlkioWeight
}

func cgroupCpuset() bool {
return SysInfo.Cpuset
return testEnv.DaemonInfo.CPUSet
}

func seccompEnabled() bool {
Expand Down Expand Up @@ -111,5 +111,7 @@ func overlay2Supported() bool {
}

func init() {
SysInfo = sysinfo.New(true)
if SameHostDaemon() {
SysInfo = sysinfo.New(true)
}
}
17 changes: 17 additions & 0 deletions integration-cli/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/parsers/kernel"
"github.com/docker/docker/pkg/stringutils"
"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
Expand Down Expand Up @@ -194,3 +195,19 @@ func NewEnvClientWithVersion(version string) (*client.Client, error) {
cli.NegotiateAPIVersionPing(types.Ping{APIVersion: version})
return cli, nil
}

// GetKernelVersion gets the current kernel version.
func GetKernelVersion() *kernel.VersionInfo {
v, _ := kernel.ParseRelease(testEnv.DaemonInfo.KernelVersion)
return v
}

// CheckKernelVersion checks if current kernel is newer than (or equal to)
// the given version.
func CheckKernelVersion(k, major, minor int) bool {
v := GetKernelVersion()
if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: k, Major: major, Minor: minor}) < 0 {
return false
}
return true
}

0 comments on commit b1fb419

Please sign in to comment.