1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #13529 from hqhq/hq_skip_cgroup_test

Skip test if not have Cpu quota or Cpu period
This commit is contained in:
Jessie Frazelle 2015-05-28 10:57:32 -07:00
commit 5bb6262d88
3 changed files with 36 additions and 13 deletions

View file

@ -5272,6 +5272,7 @@ RUN [ "/hello" ]`, map[string]string{})
}
func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
testRequires(c, CpuCfsQuota)
name := "testbuildresourceconstraints"
ctx, err := fakeContext(`

View file

@ -88,15 +88,13 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUAndMemoryLimit(c *check.C) {
// "test" should be printed
func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
testRequires(c, CpuCfsQuota)
runCmd := exec.Command(dockerBinary, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "echo", "test")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatalf("failed to run container: %v, output: %q", err, out)
}
out = strings.TrimSpace(out)
if strings.Contains(out, "Your kernel does not support CPU cfs quota") {
c.Skip("Your kernel does not support CPU cfs quota, skip this test")
}
if out != "test" {
c.Errorf("container should've printed 'test'")
}
@ -105,7 +103,7 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
c.Assert(err, check.IsNil)
if out != "8000" {
c.Errorf("setting the CPU CFS quota failed")
c.Fatalf("setting the CPU CFS quota failed")
}
}
@ -1116,20 +1114,16 @@ func (s *DockerSuite) TestRunProcWritableInPrivilegedContainers(c *check.C) {
}
func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
testRequires(c, CpuCfsPeriod)
runCmd := exec.Command(dockerBinary, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatalf("failed to run container: %v, output: %q", err, out)
}
out = strings.TrimSpace(out)
if strings.Contains(out, "Your kernel does not support CPU cfs period") {
c.Skip("Your kernel does not support CPU cfs period, skip this test")
if _, err := runCommand(runCmd); err != nil {
c.Fatalf("failed to run container: %v", err)
}
out, err = inspectField("test", "HostConfig.CpuPeriod")
out, err := inspectField("test", "HostConfig.CpuPeriod")
c.Assert(err, check.IsNil)
if out != "50000" {
c.Errorf("setting the CPU CFS period failed")
c.Fatalf("setting the CPU CFS period failed")
}
}

View file

@ -7,8 +7,10 @@ import (
"log"
"net/http"
"os/exec"
"path"
"strings"
"github.com/docker/libcontainer/cgroups"
"github.com/go-check/check"
)
@ -96,6 +98,32 @@ var (
},
"Test requires underlying root filesystem not be backed by overlay.",
}
CpuCfsPeriod = TestRequirement{
func() bool {
cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
if err != nil {
return false
}
if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_period_us")); err != nil {
return false
}
return true
},
"Test requires an environment that supports cgroup cfs period.",
}
CpuCfsQuota = TestRequirement{
func() bool {
cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
if err != nil {
return false
}
if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_quota_us")); err != nil {
return false
}
return true
},
"Test requires an environment that supports cgroup cfs quota.",
}
)
// testRequires checks if the environment satisfies the requirements