-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_cli_update_unix_test.go
196 lines (154 loc) · 6.28 KB
/
docker_cli_update_unix_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// +build !windows
package main
import (
"encoding/json"
"fmt"
"strings"
"github.com/docker/docker/pkg/integration/checker"
"github.com/docker/engine-api/types"
"github.com/go-check/check"
)
func (s *DockerSuite) TestUpdateRunningContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport)
name := "test-update-container"
dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "top")
dockerCmd(c, "update", "-m", "500M", name)
memory, err := inspectField(name, "HostConfig.Memory")
c.Assert(err, check.IsNil)
if memory != "524288000" {
c.Fatalf("Got the wrong memory value, we got %d, expected 524288000(500M).", memory)
}
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes"
out, _ := dockerCmd(c, "exec", name, "cat", file)
c.Assert(strings.TrimSpace(out), checker.Equals, "524288000")
}
func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport)
name := "test-update-container"
dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "top")
dockerCmd(c, "update", "-m", "500M", name)
dockerCmd(c, "restart", name)
memory, err := inspectField(name, "HostConfig.Memory")
c.Assert(err, check.IsNil)
if memory != "524288000" {
c.Fatalf("Got the wrong memory value, we got %d, expected 524288000(500M).", memory)
}
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes"
out, _ := dockerCmd(c, "exec", name, "cat", file)
c.Assert(strings.TrimSpace(out), checker.Equals, "524288000")
}
func (s *DockerSuite) TestUpdateStoppedContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport)
name := "test-update-container"
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes"
dockerCmd(c, "run", "--name", name, "-m", "300M", "busybox", "cat", file)
dockerCmd(c, "update", "-m", "500M", name)
memory, err := inspectField(name, "HostConfig.Memory")
c.Assert(err, check.IsNil)
if memory != "524288000" {
c.Fatalf("Got the wrong memory value, we got %d, expected 524288000(500M).", memory)
}
out, _ := dockerCmd(c, "start", "-a", name)
c.Assert(strings.TrimSpace(out), checker.Equals, "524288000")
}
func (s *DockerSuite) TestUpdatePausedContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, cpuShare)
name := "test-update-container"
dockerCmd(c, "run", "-d", "--name", name, "--cpu-shares", "1000", "busybox", "top")
dockerCmd(c, "pause", name)
dockerCmd(c, "update", "--cpu-shares", "500", name)
out, err := inspectField(name, "HostConfig.CPUShares")
c.Assert(err, check.IsNil)
if out != "500" {
c.Fatalf("Got the wrong cpu shares value, we got %d, expected 500.", out)
}
dockerCmd(c, "unpause", name)
file := "/sys/fs/cgroup/cpu/cpu.shares"
out, _ = dockerCmd(c, "exec", name, "cat", file)
c.Assert(strings.TrimSpace(out), checker.Equals, "500")
}
func (s *DockerSuite) TestUpdateWithUntouchedFields(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport)
testRequires(c, cpuShare)
name := "test-update-container"
dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "--cpu-shares", "800", "busybox", "top")
dockerCmd(c, "update", "-m", "500M", name)
// Update memory and not touch cpus, `cpuset.cpus` should still have the old value
out, err := inspectField(name, "HostConfig.CPUShares")
c.Assert(err, check.IsNil)
c.Assert(out, check.Equals, "800")
file := "/sys/fs/cgroup/cpu/cpu.shares"
out, _ = dockerCmd(c, "exec", name, "cat", file)
c.Assert(strings.TrimSpace(out), checker.Equals, "800")
}
func (s *DockerSuite) TestUpdateContainerInvalidValue(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport)
name := "test-update-container"
dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "true")
out, _, err := dockerCmdWithError("update", "-m", "2M", name)
c.Assert(err, check.NotNil)
expected := "Minimum memory limit allowed is 4MB"
c.Assert(out, checker.Contains, expected)
}
func (s *DockerSuite) TestUpdateContainerWithoutFlags(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport)
name := "test-update-container"
dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "true")
_, _, err := dockerCmdWithError("update", name)
c.Assert(err, check.NotNil)
}
func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, kernelMemorySupport)
name := "test-update-container"
dockerCmd(c, "run", "-d", "--name", name, "--kernel-memory", "50M", "busybox", "top")
_, _, err := dockerCmdWithError("update", "--kernel-memory", "100M", name)
// Update kernel memory to a running container is not allowed.
c.Assert(err, check.NotNil)
out, err := inspectField(name, "HostConfig.KernelMemory")
c.Assert(err, check.IsNil)
// Update kernel memory to a running container with failure should not change HostConfig
if out != "52428800" {
c.Fatalf("Got the wrong memory value, we got %d, expected 52428800(50M).", out)
}
dockerCmd(c, "stop", name)
dockerCmd(c, "update", "--kernel-memory", "100M", name)
dockerCmd(c, "start", name)
out, err = inspectField(name, "HostConfig.KernelMemory")
c.Assert(err, check.IsNil)
if out != "104857600" {
c.Fatalf("Got the wrong memory value, we got %d, expected 104857600(100M).", out)
}
file := "/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes"
out, _ = dockerCmd(c, "exec", name, "cat", file)
c.Assert(strings.TrimSpace(out), checker.Equals, "104857600")
}
func (s *DockerSuite) TestUpdateStats(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport)
testRequires(c, cpuCfsQuota)
name := "foo"
dockerCmd(c, "run", "-d", "-ti", "--name", name, "-m", "500m", "busybox")
c.Assert(waitRun(name), checker.IsNil)
getMemLimit := func(id string) uint64 {
resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
c.Assert(err, checker.IsNil)
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
var v *types.Stats
err = json.NewDecoder(body).Decode(&v)
c.Assert(err, checker.IsNil)
body.Close()
return v.MemoryStats.Limit
}
preMemLimit := getMemLimit(name)
dockerCmd(c, "update", "--cpu-quota", "2000", name)
curMemLimit := getMemLimit(name)
c.Assert(preMemLimit, checker.Equals, curMemLimit)
}