mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Do not require cgroups capabilities on windows to run the integration tests.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
3bda841e3e
commit
a914101296
6 changed files with 149 additions and 127 deletions
|
@ -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"
|
||||
|
||||
|
|
75
integration-cli/docker_cli_build_unix_test.go
Normal file
75
integration-cli/docker_cli_build_unix_test.go
Normal file
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
39
integration-cli/requirements_unix.go
Normal file
39
integration-cli/requirements_unix.go
Normal file
|
@ -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.",
|
||||
}
|
||||
)
|
Loading…
Reference in a new issue