Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -5271,70 +5271,6 @@ RUN [ "/hello" ]`, map[string]string{})
|
| 5271 | 5271 |
|
| 5272 | 5272 |
} |
| 5273 | 5273 |
|
| 5274 |
-func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
|
| 5275 |
- testRequires(c, CpuCfsQuota) |
|
| 5276 |
- name := "testbuildresourceconstraints" |
|
| 5277 |
- |
|
| 5278 |
- ctx, err := fakeContext(` |
|
| 5279 |
- FROM hello-world:frozen |
|
| 5280 |
- RUN ["/hello"] |
|
| 5281 |
- `, map[string]string{})
|
|
| 5282 |
- if err != nil {
|
|
| 5283 |
- c.Fatal(err) |
|
| 5284 |
- } |
|
| 5285 |
- |
|
| 5286 |
- 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, ".") |
|
| 5287 |
- cmd.Dir = ctx.Dir |
|
| 5288 |
- |
|
| 5289 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 5290 |
- if err != nil {
|
|
| 5291 |
- c.Fatal(err, out) |
|
| 5292 |
- } |
|
| 5293 |
- out, _ = dockerCmd(c, "ps", "-lq") |
|
| 5294 |
- |
|
| 5295 |
- cID := strings.TrimSpace(out) |
|
| 5296 |
- |
|
| 5297 |
- type hostConfig struct {
|
|
| 5298 |
- Memory int64 |
|
| 5299 |
- MemorySwap int64 |
|
| 5300 |
- CpusetCpus string |
|
| 5301 |
- CpusetMems string |
|
| 5302 |
- CpuShares int64 |
|
| 5303 |
- CpuQuota int64 |
|
| 5304 |
- } |
|
| 5305 |
- |
|
| 5306 |
- cfg, err := inspectFieldJSON(cID, "HostConfig") |
|
| 5307 |
- if err != nil {
|
|
| 5308 |
- c.Fatal(err) |
|
| 5309 |
- } |
|
| 5310 |
- |
|
| 5311 |
- var c1 hostConfig |
|
| 5312 |
- if err := json.Unmarshal([]byte(cfg), &c1); err != nil {
|
|
| 5313 |
- c.Fatal(err, cfg) |
|
| 5314 |
- } |
|
| 5315 |
- if c1.Memory != 67108864 || c1.MemorySwap != -1 || c1.CpusetCpus != "0" || c1.CpusetMems != "0" || c1.CpuShares != 100 || c1.CpuQuota != 8000 {
|
|
| 5316 |
- c.Fatalf("resource constraints not set properly:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d",
|
|
| 5317 |
- c1.Memory, c1.MemorySwap, c1.CpusetCpus, c1.CpusetMems, c1.CpuShares, c1.CpuQuota) |
|
| 5318 |
- } |
|
| 5319 |
- |
|
| 5320 |
- // Make sure constraints aren't saved to image |
|
| 5321 |
- _, _ = dockerCmd(c, "run", "--name=test", name) |
|
| 5322 |
- |
|
| 5323 |
- cfg, err = inspectFieldJSON("test", "HostConfig")
|
|
| 5324 |
- if err != nil {
|
|
| 5325 |
- c.Fatal(err) |
|
| 5326 |
- } |
|
| 5327 |
- var c2 hostConfig |
|
| 5328 |
- if err := json.Unmarshal([]byte(cfg), &c2); err != nil {
|
|
| 5329 |
- c.Fatal(err, cfg) |
|
| 5330 |
- } |
|
| 5331 |
- if c2.Memory == 67108864 || c2.MemorySwap == -1 || c2.CpusetCpus == "0" || c2.CpusetMems == "0" || c2.CpuShares == 100 || c2.CpuQuota == 8000 {
|
|
| 5332 |
- c.Fatalf("resource constraints leaked from build:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d",
|
|
| 5333 |
- c2.Memory, c2.MemorySwap, c2.CpusetCpus, c2.CpusetMems, c2.CpuShares, c2.CpuQuota) |
|
| 5334 |
- } |
|
| 5335 |
- |
|
| 5336 |
-} |
|
| 5337 |
- |
|
| 5338 | 5274 |
func (s *DockerSuite) TestBuildEmptyStringVolume(c *check.C) {
|
| 5339 | 5275 |
name := "testbuildemptystringvolume" |
| 5340 | 5276 |
|
| 5341 | 5277 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,75 @@ |
| 0 |
+// +build !windows |
|
| 1 |
+ |
|
| 2 |
+package main |
|
| 3 |
+ |
|
| 4 |
+import ( |
|
| 5 |
+ "encoding/json" |
|
| 6 |
+ "os/exec" |
|
| 7 |
+ "strings" |
|
| 8 |
+ |
|
| 9 |
+ "github.com/go-check/check" |
|
| 10 |
+) |
|
| 11 |
+ |
|
| 12 |
+func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
|
| 13 |
+ testRequires(c, CpuCfsQuota) |
|
| 14 |
+ name := "testbuildresourceconstraints" |
|
| 15 |
+ |
|
| 16 |
+ ctx, err := fakeContext(` |
|
| 17 |
+ FROM hello-world:frozen |
|
| 18 |
+ RUN ["/hello"] |
|
| 19 |
+ `, map[string]string{})
|
|
| 20 |
+ if err != nil {
|
|
| 21 |
+ c.Fatal(err) |
|
| 22 |
+ } |
|
| 23 |
+ |
|
| 24 |
+ 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, ".") |
|
| 25 |
+ cmd.Dir = ctx.Dir |
|
| 26 |
+ |
|
| 27 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 28 |
+ if err != nil {
|
|
| 29 |
+ c.Fatal(err, out) |
|
| 30 |
+ } |
|
| 31 |
+ out, _ = dockerCmd(c, "ps", "-lq") |
|
| 32 |
+ |
|
| 33 |
+ cID := strings.TrimSpace(out) |
|
| 34 |
+ |
|
| 35 |
+ type hostConfig struct {
|
|
| 36 |
+ Memory int64 |
|
| 37 |
+ MemorySwap int64 |
|
| 38 |
+ CpusetCpus string |
|
| 39 |
+ CpusetMems string |
|
| 40 |
+ CpuShares int64 |
|
| 41 |
+ CpuQuota int64 |
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ cfg, err := inspectFieldJSON(cID, "HostConfig") |
|
| 45 |
+ if err != nil {
|
|
| 46 |
+ c.Fatal(err) |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ var c1 hostConfig |
|
| 50 |
+ if err := json.Unmarshal([]byte(cfg), &c1); err != nil {
|
|
| 51 |
+ c.Fatal(err, cfg) |
|
| 52 |
+ } |
|
| 53 |
+ if c1.Memory != 67108864 || c1.MemorySwap != -1 || c1.CpusetCpus != "0" || c1.CpusetMems != "0" || c1.CpuShares != 100 || c1.CpuQuota != 8000 {
|
|
| 54 |
+ c.Fatalf("resource constraints not set properly:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d",
|
|
| 55 |
+ c1.Memory, c1.MemorySwap, c1.CpusetCpus, c1.CpusetMems, c1.CpuShares, c1.CpuQuota) |
|
| 56 |
+ } |
|
| 57 |
+ |
|
| 58 |
+ // Make sure constraints aren't saved to image |
|
| 59 |
+ _, _ = dockerCmd(c, "run", "--name=test", name) |
|
| 60 |
+ |
|
| 61 |
+ cfg, err = inspectFieldJSON("test", "HostConfig")
|
|
| 62 |
+ if err != nil {
|
|
| 63 |
+ c.Fatal(err) |
|
| 64 |
+ } |
|
| 65 |
+ var c2 hostConfig |
|
| 66 |
+ if err := json.Unmarshal([]byte(cfg), &c2); err != nil {
|
|
| 67 |
+ c.Fatal(err, cfg) |
|
| 68 |
+ } |
|
| 69 |
+ if c2.Memory == 67108864 || c2.MemorySwap == -1 || c2.CpusetCpus == "0" || c2.CpusetMems == "0" || c2.CpuShares == 100 || c2.CpuQuota == 8000 {
|
|
| 70 |
+ c.Fatalf("resource constraints leaked from build:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d",
|
|
| 71 |
+ c2.Memory, c2.MemorySwap, c2.CpusetCpus, c2.CpusetMems, c2.CpuShares, c2.CpuQuota) |
|
| 72 |
+ } |
|
| 73 |
+ |
|
| 74 |
+} |
| ... | ... |
@@ -87,27 +87,6 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUAndMemoryLimit(c *check.C) {
|
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 | 89 |
// "test" should be printed |
| 90 |
-func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
|
|
| 91 |
- testRequires(c, CpuCfsQuota) |
|
| 92 |
- runCmd := exec.Command(dockerBinary, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "echo", "test") |
|
| 93 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 94 |
- if err != nil {
|
|
| 95 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 96 |
- } |
|
| 97 |
- out = strings.TrimSpace(out) |
|
| 98 |
- if out != "test" {
|
|
| 99 |
- c.Errorf("container should've printed 'test'")
|
|
| 100 |
- } |
|
| 101 |
- |
|
| 102 |
- out, err = inspectField("test", "HostConfig.CpuQuota")
|
|
| 103 |
- c.Assert(err, check.IsNil) |
|
| 104 |
- |
|
| 105 |
- if out != "8000" {
|
|
| 106 |
- c.Fatalf("setting the CPU CFS quota failed")
|
|
| 107 |
- } |
|
| 108 |
-} |
|
| 109 |
- |
|
| 110 |
-// "test" should be printed |
|
| 111 | 90 |
func (s *DockerSuite) TestRunEchoNamedContainer(c *check.C) {
|
| 112 | 91 |
runCmd := exec.Command(dockerBinary, "run", "--name", "testfoonamedcontainer", "busybox", "echo", "test") |
| 113 | 92 |
out, _, _, err := runCommandWithStdoutStderr(runCmd) |
| ... | ... |
@@ -1113,20 +1092,6 @@ func (s *DockerSuite) TestRunProcWritableInPrivilegedContainers(c *check.C) {
|
| 1113 | 1113 |
} |
| 1114 | 1114 |
} |
| 1115 | 1115 |
|
| 1116 |
-func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
|
|
| 1117 |
- testRequires(c, CpuCfsPeriod) |
|
| 1118 |
- runCmd := exec.Command(dockerBinary, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true") |
|
| 1119 |
- if _, err := runCommand(runCmd); err != nil {
|
|
| 1120 |
- c.Fatalf("failed to run container: %v", err)
|
|
| 1121 |
- } |
|
| 1122 |
- |
|
| 1123 |
- out, err := inspectField("test", "HostConfig.CpuPeriod")
|
|
| 1124 |
- c.Assert(err, check.IsNil) |
|
| 1125 |
- if out != "50000" {
|
|
| 1126 |
- c.Fatalf("setting the CPU CFS period failed")
|
|
| 1127 |
- } |
|
| 1128 |
-} |
|
| 1129 |
- |
|
| 1130 | 1116 |
func (s *DockerSuite) TestRunWithCpuset(c *check.C) {
|
| 1131 | 1117 |
cmd := exec.Command(dockerBinary, "run", "--cpuset", "0", "busybox", "true") |
| 1132 | 1118 |
if code, err := runCommand(cmd); err != nil || code != 0 {
|
| ... | ... |
@@ -250,3 +250,38 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) {
|
| 250 | 250 |
c.Fatal("timed out waiting for container to exit")
|
| 251 | 251 |
} |
| 252 | 252 |
} |
| 253 |
+ |
|
| 254 |
+// "test" should be printed |
|
| 255 |
+func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
|
|
| 256 |
+ testRequires(c, CpuCfsQuota) |
|
| 257 |
+ runCmd := exec.Command(dockerBinary, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "echo", "test") |
|
| 258 |
+ out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 259 |
+ if err != nil {
|
|
| 260 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 261 |
+ } |
|
| 262 |
+ out = strings.TrimSpace(out) |
|
| 263 |
+ if out != "test" {
|
|
| 264 |
+ c.Errorf("container should've printed 'test'")
|
|
| 265 |
+ } |
|
| 266 |
+ |
|
| 267 |
+ out, err = inspectField("test", "HostConfig.CpuQuota")
|
|
| 268 |
+ c.Assert(err, check.IsNil) |
|
| 269 |
+ |
|
| 270 |
+ if out != "8000" {
|
|
| 271 |
+ c.Fatalf("setting the CPU CFS quota failed")
|
|
| 272 |
+ } |
|
| 273 |
+} |
|
| 274 |
+ |
|
| 275 |
+func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
|
|
| 276 |
+ testRequires(c, CpuCfsPeriod) |
|
| 277 |
+ runCmd := exec.Command(dockerBinary, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true") |
|
| 278 |
+ if _, err := runCommand(runCmd); err != nil {
|
|
| 279 |
+ c.Fatalf("failed to run container: %v", err)
|
|
| 280 |
+ } |
|
| 281 |
+ |
|
| 282 |
+ out, err := inspectField("test", "HostConfig.CpuPeriod")
|
|
| 283 |
+ c.Assert(err, check.IsNil) |
|
| 284 |
+ if out != "50000" {
|
|
| 285 |
+ c.Fatalf("setting the CPU CFS period failed")
|
|
| 286 |
+ } |
|
| 287 |
+} |
| ... | ... |
@@ -7,10 +7,8 @@ import ( |
| 7 | 7 |
"log" |
| 8 | 8 |
"net/http" |
| 9 | 9 |
"os/exec" |
| 10 |
- "path" |
|
| 11 | 10 |
"strings" |
| 12 | 11 |
|
| 13 |
- "github.com/docker/libcontainer/cgroups" |
|
| 14 | 12 |
"github.com/go-check/check" |
| 15 | 13 |
) |
| 16 | 14 |
|
| ... | ... |
@@ -98,32 +96,6 @@ var ( |
| 98 | 98 |
}, |
| 99 | 99 |
"Test requires underlying root filesystem not be backed by overlay.", |
| 100 | 100 |
} |
| 101 |
- CpuCfsPeriod = TestRequirement{
|
|
| 102 |
- func() bool {
|
|
| 103 |
- cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
|
|
| 104 |
- if err != nil {
|
|
| 105 |
- return false |
|
| 106 |
- } |
|
| 107 |
- if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_period_us")); err != nil {
|
|
| 108 |
- return false |
|
| 109 |
- } |
|
| 110 |
- return true |
|
| 111 |
- }, |
|
| 112 |
- "Test requires an environment that supports cgroup cfs period.", |
|
| 113 |
- } |
|
| 114 |
- CpuCfsQuota = TestRequirement{
|
|
| 115 |
- func() bool {
|
|
| 116 |
- cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
|
|
| 117 |
- if err != nil {
|
|
| 118 |
- return false |
|
| 119 |
- } |
|
| 120 |
- if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_quota_us")); err != nil {
|
|
| 121 |
- return false |
|
| 122 |
- } |
|
| 123 |
- return true |
|
| 124 |
- }, |
|
| 125 |
- "Test requires an environment that supports cgroup cfs quota.", |
|
| 126 |
- } |
|
| 127 | 101 |
) |
| 128 | 102 |
|
| 129 | 103 |
// testRequires checks if the environment satisfies the requirements |
| 130 | 104 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,39 @@ |
| 0 |
+// +build !windows |
|
| 1 |
+ |
|
| 2 |
+package main |
|
| 3 |
+ |
|
| 4 |
+import ( |
|
| 5 |
+ "io/ioutil" |
|
| 6 |
+ "path" |
|
| 7 |
+ |
|
| 8 |
+ "github.com/docker/libcontainer/cgroups" |
|
| 9 |
+) |
|
| 10 |
+ |
|
| 11 |
+var ( |
|
| 12 |
+ CpuCfsPeriod = TestRequirement{
|
|
| 13 |
+ func() bool {
|
|
| 14 |
+ cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
|
|
| 15 |
+ if err != nil {
|
|
| 16 |
+ return false |
|
| 17 |
+ } |
|
| 18 |
+ if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_period_us")); err != nil {
|
|
| 19 |
+ return false |
|
| 20 |
+ } |
|
| 21 |
+ return true |
|
| 22 |
+ }, |
|
| 23 |
+ "Test requires an environment that supports cgroup cfs period.", |
|
| 24 |
+ } |
|
| 25 |
+ CpuCfsQuota = TestRequirement{
|
|
| 26 |
+ func() bool {
|
|
| 27 |
+ cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
|
|
| 28 |
+ if err != nil {
|
|
| 29 |
+ return false |
|
| 30 |
+ } |
|
| 31 |
+ if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_quota_us")); err != nil {
|
|
| 32 |
+ return false |
|
| 33 |
+ } |
|
| 34 |
+ return true |
|
| 35 |
+ }, |
|
| 36 |
+ "Test requires an environment that supports cgroup cfs quota.", |
|
| 37 |
+ } |
|
| 38 |
+) |