Currently on kernels booted without the "cgroup_enable=memory" kernel
parameter the testcase TestApiStatsContainerGetMemoryLimit fails with:
FAIL: docker_api_stats_test.go:231: TestApiStatsContainerGetMemoryLimit.pN52_github_com_docker_docker_integration_cli.DockerSuite
docker_api_stats_test.go:256:
c.Assert(fmt.Sprintf("%d", v.MemoryStats.Limit), checker.Equals, fmt.Sprintf("%d", info.MemTotal))
... obtained string = "0"
... expected string = "33759145984"
Fix this and skip the testcase if the kernel does not support cgroup memory
limit. In that case the output would be:
SKIP: docker_api_stats_test.go:231:
TestApiStatsContainerGetMemoryLimit.pN52_github_com_docker_docker_integration_cli.DockerSuite
(Test requires an environment that supports cgroup memory limit.)
ChangeLog:
----------
v4: Move TestApiStatsContainerGetMemoryLimit to docker_api_stats_unix_test.go
v3: Use existing "memoryLimitSupport" from requirements_unix.go
v2: Move check to requirements.go
Fixes #22477
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
| ... | ... |
@@ -228,34 +228,6 @@ func (s *DockerSuite) TestApiStatsContainerNotFound(c *check.C) {
|
| 228 | 228 |
c.Assert(status, checker.Equals, http.StatusNotFound) |
| 229 | 229 |
} |
| 230 | 230 |
|
| 231 |
-func (s *DockerSuite) TestApiStatsContainerGetMemoryLimit(c *check.C) {
|
|
| 232 |
- testRequires(c, DaemonIsLinux) |
|
| 233 |
- |
|
| 234 |
- resp, body, err := sockRequestRaw("GET", "/info", nil, "application/json")
|
|
| 235 |
- c.Assert(err, checker.IsNil) |
|
| 236 |
- c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
|
| 237 |
- var info types.Info |
|
| 238 |
- err = json.NewDecoder(body).Decode(&info) |
|
| 239 |
- c.Assert(err, checker.IsNil) |
|
| 240 |
- body.Close() |
|
| 241 |
- |
|
| 242 |
- // don't set a memory limit, the memory limit should be system memory |
|
| 243 |
- conName := "foo" |
|
| 244 |
- dockerCmd(c, "run", "-d", "--name", conName, "busybox", "top") |
|
| 245 |
- c.Assert(waitRun(conName), checker.IsNil) |
|
| 246 |
- |
|
| 247 |
- resp, body, err = sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", conName), nil, "")
|
|
| 248 |
- c.Assert(err, checker.IsNil) |
|
| 249 |
- c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
|
| 250 |
- c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
|
| 251 |
- |
|
| 252 |
- var v *types.Stats |
|
| 253 |
- err = json.NewDecoder(body).Decode(&v) |
|
| 254 |
- c.Assert(err, checker.IsNil) |
|
| 255 |
- body.Close() |
|
| 256 |
- c.Assert(fmt.Sprintf("%d", v.MemoryStats.Limit), checker.Equals, fmt.Sprintf("%d", info.MemTotal))
|
|
| 257 |
-} |
|
| 258 |
- |
|
| 259 | 231 |
func (s *DockerSuite) TestApiStatsNoStreamConnectedContainers(c *check.C) {
|
| 260 | 232 |
testRequires(c, DaemonIsLinux) |
| 261 | 233 |
|
| 262 | 234 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,41 @@ |
| 0 |
+// +build !windows |
|
| 1 |
+ |
|
| 2 |
+package main |
|
| 3 |
+ |
|
| 4 |
+import ( |
|
| 5 |
+ "encoding/json" |
|
| 6 |
+ "fmt" |
|
| 7 |
+ "net/http" |
|
| 8 |
+ |
|
| 9 |
+ "github.com/docker/docker/pkg/integration/checker" |
|
| 10 |
+ "github.com/docker/engine-api/types" |
|
| 11 |
+ "github.com/go-check/check" |
|
| 12 |
+) |
|
| 13 |
+ |
|
| 14 |
+func (s *DockerSuite) TestApiStatsContainerGetMemoryLimit(c *check.C) {
|
|
| 15 |
+ testRequires(c, DaemonIsLinux, memoryLimitSupport) |
|
| 16 |
+ |
|
| 17 |
+ resp, body, err := sockRequestRaw("GET", "/info", nil, "application/json")
|
|
| 18 |
+ c.Assert(err, checker.IsNil) |
|
| 19 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
|
| 20 |
+ var info types.Info |
|
| 21 |
+ err = json.NewDecoder(body).Decode(&info) |
|
| 22 |
+ c.Assert(err, checker.IsNil) |
|
| 23 |
+ body.Close() |
|
| 24 |
+ |
|
| 25 |
+ // don't set a memory limit, the memory limit should be system memory |
|
| 26 |
+ conName := "foo" |
|
| 27 |
+ dockerCmd(c, "run", "-d", "--name", conName, "busybox", "top") |
|
| 28 |
+ c.Assert(waitRun(conName), checker.IsNil) |
|
| 29 |
+ |
|
| 30 |
+ resp, body, err = sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", conName), nil, "")
|
|
| 31 |
+ c.Assert(err, checker.IsNil) |
|
| 32 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
|
| 33 |
+ c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
|
| 34 |
+ |
|
| 35 |
+ var v *types.Stats |
|
| 36 |
+ err = json.NewDecoder(body).Decode(&v) |
|
| 37 |
+ c.Assert(err, checker.IsNil) |
|
| 38 |
+ body.Close() |
|
| 39 |
+ c.Assert(fmt.Sprintf("%d", v.MemoryStats.Limit), checker.Equals, fmt.Sprintf("%d", info.MemTotal))
|
|
| 40 |
+} |