2015-05-29 14:22:21 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"strings"
|
|
|
|
|
2015-10-26 09:00:16 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-07-22 22:26:06 -04:00
|
|
|
"github.com/docker/docker/pkg/ulimit"
|
2015-05-29 14:22:21 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
2015-07-22 08:59:24 -04:00
|
|
|
testRequires(c, cpuCfsQuota)
|
2015-05-29 14:22:21 -04:00
|
|
|
name := "testbuildresourceconstraints"
|
|
|
|
|
|
|
|
ctx, err := fakeContext(`
|
|
|
|
FROM hello-world:frozen
|
|
|
|
RUN ["/hello"]
|
|
|
|
`, map[string]string{})
|
2015-10-26 09:00:16 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-29 14:22:21 -04:00
|
|
|
|
2015-07-22 22:26:06 -04:00
|
|
|
dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, ".")
|
2015-05-29 14:22:21 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ := dockerCmd(c, "ps", "-lq")
|
2015-05-29 14:22:21 -04:00
|
|
|
cID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
type hostConfig struct {
|
|
|
|
Memory int64
|
|
|
|
MemorySwap int64
|
|
|
|
CpusetCpus string
|
|
|
|
CpusetMems string
|
2015-07-22 08:59:24 -04:00
|
|
|
CPUShares int64
|
|
|
|
CPUQuota int64
|
2015-07-22 22:26:06 -04:00
|
|
|
Ulimits []*ulimit.Ulimit
|
2015-05-29 14:22:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := inspectFieldJSON(cID, "HostConfig")
|
2015-10-26 09:00:16 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-29 14:22:21 -04:00
|
|
|
|
|
|
|
var c1 hostConfig
|
2015-10-26 09:00:16 -04:00
|
|
|
err = json.Unmarshal([]byte(cfg), &c1)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(cfg))
|
|
|
|
|
|
|
|
c.Assert(c1.Memory, checker.Equals, int64(64*1024*1024), check.Commentf("resource constraints not set properly for Memory"))
|
|
|
|
c.Assert(c1.MemorySwap, checker.Equals, int64(-1), check.Commentf("resource constraints not set properly for MemorySwap"))
|
|
|
|
c.Assert(c1.CpusetCpus, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetCpus"))
|
|
|
|
c.Assert(c1.CpusetMems, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetMems"))
|
|
|
|
c.Assert(c1.CPUShares, checker.Equals, int64(100), check.Commentf("resource constraints not set properly for CPUShares"))
|
|
|
|
c.Assert(c1.CPUQuota, checker.Equals, int64(8000), check.Commentf("resource constraints not set properly for CPUQuota"))
|
|
|
|
c.Assert(c1.Ulimits[0].Name, checker.Equals, "nofile", check.Commentf("resource constraints not set properly for Ulimits"))
|
|
|
|
c.Assert(c1.Ulimits[0].Hard, checker.Equals, int64(42), check.Commentf("resource constraints not set properly for Ulimits"))
|
2015-05-29 14:22:21 -04:00
|
|
|
|
|
|
|
// Make sure constraints aren't saved to image
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "run", "--name=test", name)
|
2015-05-29 14:22:21 -04:00
|
|
|
|
|
|
|
cfg, err = inspectFieldJSON("test", "HostConfig")
|
2015-10-26 09:00:16 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-22 22:26:06 -04:00
|
|
|
|
2015-10-26 09:00:16 -04:00
|
|
|
var c2 hostConfig
|
|
|
|
err = json.Unmarshal([]byte(cfg), &c2)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(cfg))
|
2015-05-29 14:22:21 -04:00
|
|
|
|
2015-10-26 09:00:16 -04:00
|
|
|
c.Assert(c2.Memory, check.Not(checker.Equals), int64(64*1024*1024), check.Commentf("resource leaked from build for Memory"))
|
|
|
|
c.Assert(c2.MemorySwap, check.Not(checker.Equals), int64(-1), check.Commentf("resource leaked from build for MemorySwap"))
|
|
|
|
c.Assert(c2.CpusetCpus, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetCpus"))
|
|
|
|
c.Assert(c2.CpusetMems, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetMems"))
|
|
|
|
c.Assert(c2.CPUShares, check.Not(checker.Equals), int64(100), check.Commentf("resource leaked from build for CPUShares"))
|
|
|
|
c.Assert(c2.CPUQuota, check.Not(checker.Equals), int64(8000), check.Commentf("resource leaked from build for CPUQuota"))
|
|
|
|
c.Assert(c2.Ulimits, checker.IsNil, check.Commentf("resource leaked from build for Ulimits"))
|
2015-05-29 14:22:21 -04:00
|
|
|
}
|