From a9141012966db62b36b7d3d1df7af877bbd2d172 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Fri, 29 May 2015 11:22:21 -0700 Subject: [PATCH] Do not require cgroups capabilities on windows to run the integration tests. Signed-off-by: David Calavera --- integration-cli/docker_cli_build_test.go | 64 ---------------- integration-cli/docker_cli_build_unix_test.go | 75 +++++++++++++++++++ integration-cli/docker_cli_run_test.go | 35 --------- integration-cli/docker_cli_run_unix_test.go | 35 +++++++++ integration-cli/requirements.go | 28 ------- integration-cli/requirements_unix.go | 39 ++++++++++ 6 files changed, 149 insertions(+), 127 deletions(-) create mode 100644 integration-cli/docker_cli_build_unix_test.go create mode 100644 integration-cli/requirements_unix.go diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 7be8c862c3..c6a777fdd7 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -5271,70 +5271,6 @@ RUN [ "/hello" ]`, map[string]string{}) } -func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) { - testRequires(c, CpuCfsQuota) - name := "testbuildresourceconstraints" - - ctx, err := fakeContext(` - FROM hello-world:frozen - RUN ["/hello"] - `, map[string]string{}) - if err != nil { - c.Fatal(err) - } - - cmd := exec.Command(dockerBinary, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "-t", name, ".") - cmd.Dir = ctx.Dir - - out, _, err := runCommandWithOutput(cmd) - if err != nil { - c.Fatal(err, out) - } - out, _ = dockerCmd(c, "ps", "-lq") - - cID := strings.TrimSpace(out) - - type hostConfig struct { - Memory int64 - MemorySwap int64 - CpusetCpus string - CpusetMems string - CpuShares int64 - CpuQuota int64 - } - - cfg, err := inspectFieldJSON(cID, "HostConfig") - if err != nil { - c.Fatal(err) - } - - var c1 hostConfig - if err := json.Unmarshal([]byte(cfg), &c1); err != nil { - c.Fatal(err, cfg) - } - if c1.Memory != 67108864 || c1.MemorySwap != -1 || c1.CpusetCpus != "0" || c1.CpusetMems != "0" || c1.CpuShares != 100 || c1.CpuQuota != 8000 { - c.Fatalf("resource constraints not set properly:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d", - c1.Memory, c1.MemorySwap, c1.CpusetCpus, c1.CpusetMems, c1.CpuShares, c1.CpuQuota) - } - - // Make sure constraints aren't saved to image - _, _ = dockerCmd(c, "run", "--name=test", name) - - cfg, err = inspectFieldJSON("test", "HostConfig") - if err != nil { - c.Fatal(err) - } - var c2 hostConfig - if err := json.Unmarshal([]byte(cfg), &c2); err != nil { - c.Fatal(err, cfg) - } - if c2.Memory == 67108864 || c2.MemorySwap == -1 || c2.CpusetCpus == "0" || c2.CpusetMems == "0" || c2.CpuShares == 100 || c2.CpuQuota == 8000 { - c.Fatalf("resource constraints leaked from build:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d", - c2.Memory, c2.MemorySwap, c2.CpusetCpus, c2.CpusetMems, c2.CpuShares, c2.CpuQuota) - } - -} - func (s *DockerSuite) TestBuildEmptyStringVolume(c *check.C) { name := "testbuildemptystringvolume" diff --git a/integration-cli/docker_cli_build_unix_test.go b/integration-cli/docker_cli_build_unix_test.go new file mode 100644 index 0000000000..6e00c1c15f --- /dev/null +++ b/integration-cli/docker_cli_build_unix_test.go @@ -0,0 +1,75 @@ +// +build !windows + +package main + +import ( + "encoding/json" + "os/exec" + "strings" + + "github.com/go-check/check" +) + +func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) { + testRequires(c, CpuCfsQuota) + name := "testbuildresourceconstraints" + + ctx, err := fakeContext(` + FROM hello-world:frozen + RUN ["/hello"] + `, map[string]string{}) + if err != nil { + c.Fatal(err) + } + + cmd := exec.Command(dockerBinary, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "-t", name, ".") + cmd.Dir = ctx.Dir + + out, _, err := runCommandWithOutput(cmd) + if err != nil { + c.Fatal(err, out) + } + out, _ = dockerCmd(c, "ps", "-lq") + + cID := strings.TrimSpace(out) + + type hostConfig struct { + Memory int64 + MemorySwap int64 + CpusetCpus string + CpusetMems string + CpuShares int64 + CpuQuota int64 + } + + cfg, err := inspectFieldJSON(cID, "HostConfig") + if err != nil { + c.Fatal(err) + } + + var c1 hostConfig + if err := json.Unmarshal([]byte(cfg), &c1); err != nil { + c.Fatal(err, cfg) + } + if c1.Memory != 67108864 || c1.MemorySwap != -1 || c1.CpusetCpus != "0" || c1.CpusetMems != "0" || c1.CpuShares != 100 || c1.CpuQuota != 8000 { + c.Fatalf("resource constraints not set properly:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d", + c1.Memory, c1.MemorySwap, c1.CpusetCpus, c1.CpusetMems, c1.CpuShares, c1.CpuQuota) + } + + // Make sure constraints aren't saved to image + _, _ = dockerCmd(c, "run", "--name=test", name) + + cfg, err = inspectFieldJSON("test", "HostConfig") + if err != nil { + c.Fatal(err) + } + var c2 hostConfig + if err := json.Unmarshal([]byte(cfg), &c2); err != nil { + c.Fatal(err, cfg) + } + if c2.Memory == 67108864 || c2.MemorySwap == -1 || c2.CpusetCpus == "0" || c2.CpusetMems == "0" || c2.CpuShares == 100 || c2.CpuQuota == 8000 { + c.Fatalf("resource constraints leaked from build:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d", + c2.Memory, c2.MemorySwap, c2.CpusetCpus, c2.CpusetMems, c2.CpuShares, c2.CpuQuota) + } + +} diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 308ae5bf94..866a579bb4 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -86,27 +86,6 @@ 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 out != "test" { - c.Errorf("container should've printed 'test'") - } - - out, err = inspectField("test", "HostConfig.CpuQuota") - c.Assert(err, check.IsNil) - - if out != "8000" { - c.Fatalf("setting the CPU CFS quota failed") - } -} - // "test" should be printed func (s *DockerSuite) TestRunEchoNamedContainer(c *check.C) { runCmd := exec.Command(dockerBinary, "run", "--name", "testfoonamedcontainer", "busybox", "echo", "test") @@ -1113,20 +1092,6 @@ 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") - if _, err := runCommand(runCmd); err != nil { - c.Fatalf("failed to run container: %v", err) - } - - out, err := inspectField("test", "HostConfig.CpuPeriod") - c.Assert(err, check.IsNil) - if out != "50000" { - c.Fatalf("setting the CPU CFS period failed") - } -} - func (s *DockerSuite) TestRunWithCpuset(c *check.C) { cmd := exec.Command(dockerBinary, "run", "--cpuset", "0", "busybox", "true") if code, err := runCommand(cmd); err != nil || code != 0 { diff --git a/integration-cli/docker_cli_run_unix_test.go b/integration-cli/docker_cli_run_unix_test.go index 59b623162d..5a22ae6c90 100644 --- a/integration-cli/docker_cli_run_unix_test.go +++ b/integration-cli/docker_cli_run_unix_test.go @@ -250,3 +250,38 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) { c.Fatal("timed out waiting for container to exit") } } + +// "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 out != "test" { + c.Errorf("container should've printed 'test'") + } + + out, err = inspectField("test", "HostConfig.CpuQuota") + c.Assert(err, check.IsNil) + + if out != "8000" { + c.Fatalf("setting the CPU CFS quota failed") + } +} + +func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) { + testRequires(c, CpuCfsPeriod) + runCmd := exec.Command(dockerBinary, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true") + if _, err := runCommand(runCmd); err != nil { + c.Fatalf("failed to run container: %v", err) + } + + out, err := inspectField("test", "HostConfig.CpuPeriod") + c.Assert(err, check.IsNil) + if out != "50000" { + c.Fatalf("setting the CPU CFS period failed") + } +} diff --git a/integration-cli/requirements.go b/integration-cli/requirements.go index 62a0acc0f1..fc4f5ee955 100644 --- a/integration-cli/requirements.go +++ b/integration-cli/requirements.go @@ -7,10 +7,8 @@ import ( "log" "net/http" "os/exec" - "path" "strings" - "github.com/docker/libcontainer/cgroups" "github.com/go-check/check" ) @@ -98,32 +96,6 @@ 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 diff --git a/integration-cli/requirements_unix.go b/integration-cli/requirements_unix.go new file mode 100644 index 0000000000..98e2c9fc54 --- /dev/null +++ b/integration-cli/requirements_unix.go @@ -0,0 +1,39 @@ +// +build !windows + +package main + +import ( + "io/ioutil" + "path" + + "github.com/docker/libcontainer/cgroups" +) + +var ( + 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.", + } +)