2015-12-28 11:19:26 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-09-01 19:14:59 +00:00
|
|
|
"context"
|
2015-12-30 01:33:16 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2016-12-17 01:57:05 +00:00
|
|
|
"os/exec"
|
2015-12-28 11:19:26 +00:00
|
|
|
"strings"
|
2019-09-09 21:06:12 +00:00
|
|
|
"testing"
|
2016-12-17 01:57:05 +00:00
|
|
|
"time"
|
2015-12-28 11:19:26 +00:00
|
|
|
|
2019-07-29 23:59:08 +00:00
|
|
|
"github.com/creack/pty"
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2017-09-01 19:14:59 +00:00
|
|
|
"github.com/docker/docker/client"
|
2017-09-14 17:17:49 +00:00
|
|
|
"github.com/docker/docker/pkg/parsers/kernel"
|
2019-08-29 20:52:40 +00:00
|
|
|
"github.com/docker/docker/testutil/request"
|
2019-04-04 13:23:19 +00:00
|
|
|
"gotest.tools/assert"
|
2015-12-28 11:19:26 +00:00
|
|
|
)
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateRunningContainer(c *testing.T) {
|
2015-12-28 11:19:26 +00:00
|
|
|
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)
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.Memory"), "524288000")
|
2015-12-28 11:19:26 +00:00
|
|
|
|
|
|
|
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes"
|
|
|
|
out, _ := dockerCmd(c, "exec", name, "cat", file)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "524288000")
|
2015-12-28 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *testing.T) {
|
2015-12-28 11:19:26 +00:00
|
|
|
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)
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.Memory"), "524288000")
|
2015-12-28 11:19:26 +00:00
|
|
|
|
|
|
|
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes"
|
|
|
|
out, _ := dockerCmd(c, "exec", name, "cat", file)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "524288000")
|
2015-12-28 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateStoppedContainer(c *testing.T) {
|
2015-12-28 11:19:26 +00:00
|
|
|
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)
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.Memory"), "524288000")
|
2015-12-28 11:19:26 +00:00
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "start", "-a", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "524288000")
|
2015-12-28 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdatePausedContainer(c *testing.T) {
|
2015-12-28 11:19:26 +00:00
|
|
|
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)
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.CPUShares"), "500")
|
2015-12-28 11:19:26 +00:00
|
|
|
|
|
|
|
dockerCmd(c, "unpause", name)
|
|
|
|
file := "/sys/fs/cgroup/cpu/cpu.shares"
|
2016-02-03 01:26:46 +00:00
|
|
|
out, _ := dockerCmd(c, "exec", name, "cat", file)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "500")
|
2015-12-28 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateWithUntouchedFields(c *testing.T) {
|
2015-12-28 11:19:26 +00:00
|
|
|
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
|
2016-01-28 14:19:25 +00:00
|
|
|
out := inspectField(c, name, "HostConfig.CPUShares")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, out, "800")
|
2015-12-28 11:19:26 +00:00
|
|
|
|
|
|
|
file := "/sys/fs/cgroup/cpu/cpu.shares"
|
|
|
|
out, _ = dockerCmd(c, "exec", name, "cat", file)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "800")
|
2015-12-28 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateContainerInvalidValue(c *testing.T) {
|
2015-12-28 11:19:26 +00:00
|
|
|
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)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2015-12-28 11:19:26 +00:00
|
|
|
expected := "Minimum memory limit allowed is 4MB"
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, expected))
|
2015-12-28 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateContainerWithoutFlags(c *testing.T) {
|
2015-12-28 11:19:26 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
testRequires(c, memoryLimitSupport)
|
|
|
|
|
|
|
|
name := "test-update-container"
|
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "true")
|
|
|
|
_, _, err := dockerCmdWithError("update", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2015-12-28 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateKernelMemory(c *testing.T) {
|
2016-04-01 02:32:46 +00:00
|
|
|
testRequires(c, DaemonIsLinux, kernelMemorySupport)
|
2015-12-28 11:19:26 +00:00
|
|
|
|
|
|
|
name := "test-update-container"
|
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "--kernel-memory", "50M", "busybox", "top")
|
2016-07-12 00:07:24 +00:00
|
|
|
dockerCmd(c, "update", "--kernel-memory", "100M", name)
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.KernelMemory"), "104857600")
|
2016-07-12 00:07:24 +00:00
|
|
|
|
|
|
|
file := "/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes"
|
|
|
|
out, _ := dockerCmd(c, "exec", name, "cat", file)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "104857600")
|
2016-07-12 00:07:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateKernelMemoryUninitialized(c *testing.T) {
|
2016-07-12 00:07:24 +00:00
|
|
|
testRequires(c, DaemonIsLinux, kernelMemorySupport)
|
|
|
|
|
2017-09-11 14:23:59 +00:00
|
|
|
isNewKernel := CheckKernelVersion(4, 6, 0)
|
2016-07-12 00:07:24 +00:00
|
|
|
name := "test-update-container"
|
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
|
2015-12-28 11:19:26 +00:00
|
|
|
_, _, err := dockerCmdWithError("update", "--kernel-memory", "100M", name)
|
2016-08-02 05:17:20 +00:00
|
|
|
// Update kernel memory to a running container without kernel memory initialized
|
|
|
|
// is not allowed before kernel version 4.6.
|
|
|
|
if !isNewKernel {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-08-02 05:17:20 +00:00
|
|
|
} else {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-08-02 05:17:20 +00:00
|
|
|
}
|
2015-12-28 11:19:26 +00:00
|
|
|
|
2016-04-01 02:32:46 +00:00
|
|
|
dockerCmd(c, "pause", name)
|
2016-08-02 05:17:20 +00:00
|
|
|
_, _, err = dockerCmdWithError("update", "--kernel-memory", "200M", name)
|
|
|
|
if !isNewKernel {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-08-02 05:17:20 +00:00
|
|
|
} else {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-08-02 05:17:20 +00:00
|
|
|
}
|
2016-04-01 02:32:46 +00:00
|
|
|
dockerCmd(c, "unpause", name)
|
|
|
|
|
2015-12-28 11:19:26 +00:00
|
|
|
dockerCmd(c, "stop", name)
|
2016-08-02 05:17:20 +00:00
|
|
|
dockerCmd(c, "update", "--kernel-memory", "300M", name)
|
2015-12-28 11:19:26 +00:00
|
|
|
dockerCmd(c, "start", name)
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.KernelMemory"), "314572800")
|
2015-12-28 11:19:26 +00:00
|
|
|
|
|
|
|
file := "/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes"
|
2016-02-03 01:26:46 +00:00
|
|
|
out, _ := dockerCmd(c, "exec", name, "cat", file)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "314572800")
|
2015-12-28 11:19:26 +00:00
|
|
|
}
|
2015-12-30 01:33:16 +00:00
|
|
|
|
2017-09-14 17:17:49 +00:00
|
|
|
// GetKernelVersion gets the current kernel version.
|
|
|
|
func GetKernelVersion() *kernel.VersionInfo {
|
|
|
|
v, _ := kernel.ParseRelease(testEnv.DaemonInfo.KernelVersion)
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// CheckKernelVersion checks if current kernel is newer than (or equal to)
|
|
|
|
// the given version.
|
|
|
|
func CheckKernelVersion(k, major, minor int) bool {
|
2017-10-03 16:09:16 +00:00
|
|
|
return kernel.CompareKernelVersion(*GetKernelVersion(), kernel.VersionInfo{Kernel: k, Major: major, Minor: minor}) >= 0
|
2017-09-14 17:17:49 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateSwapMemoryOnly(c *testing.T) {
|
2016-02-24 05:36:47 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
testRequires(c, memoryLimitSupport)
|
|
|
|
testRequires(c, swapMemorySupport)
|
|
|
|
|
|
|
|
name := "test-update-container"
|
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "--memory", "300M", "--memory-swap", "500M", "busybox", "top")
|
|
|
|
dockerCmd(c, "update", "--memory-swap", "600M", name)
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.MemorySwap"), "629145600")
|
2016-02-24 05:36:47 +00:00
|
|
|
|
|
|
|
file := "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes"
|
2016-02-24 06:23:48 +00:00
|
|
|
out, _ := dockerCmd(c, "exec", name, "cat", file)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "629145600")
|
2016-02-24 06:23:48 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateInvalidSwapMemory(c *testing.T) {
|
2016-02-24 06:23:48 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
testRequires(c, memoryLimitSupport)
|
|
|
|
testRequires(c, swapMemorySupport)
|
|
|
|
|
|
|
|
name := "test-update-container"
|
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "--memory", "300M", "--memory-swap", "500M", "busybox", "top")
|
|
|
|
_, _, err := dockerCmdWithError("update", "--memory-swap", "200M", name)
|
|
|
|
// Update invalid swap memory should fail.
|
|
|
|
// This will pass docker config validation, but failed at kernel validation
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-02-24 06:23:48 +00:00
|
|
|
|
|
|
|
// Update invalid swap memory with failure should not change HostConfig
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.Memory"), "314572800")
|
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.MemorySwap"), "524288000")
|
2016-02-24 06:23:48 +00:00
|
|
|
|
|
|
|
dockerCmd(c, "update", "--memory-swap", "600M", name)
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, inspectField(c, name, "HostConfig.MemorySwap"), "629145600")
|
2016-02-24 06:23:48 +00:00
|
|
|
|
|
|
|
file := "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes"
|
2016-02-24 05:36:47 +00:00
|
|
|
out, _ := dockerCmd(c, "exec", name, "cat", file)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "629145600")
|
2016-02-24 05:36:47 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateStats(c *testing.T) {
|
2015-12-30 01:33:16 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
testRequires(c, memoryLimitSupport)
|
|
|
|
testRequires(c, cpuCfsQuota)
|
|
|
|
name := "foo"
|
|
|
|
dockerCmd(c, "run", "-d", "-ti", "--name", name, "-m", "500m", "busybox")
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, waitRun(name))
|
2015-12-30 01:33:16 +00:00
|
|
|
|
|
|
|
getMemLimit := func(id string) uint64 {
|
2017-03-06 15:35:27 +00:00
|
|
|
resp, body, err := request.Get(fmt.Sprintf("/containers/%s/stats?stream=false", id))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, resp.Header.Get("Content-Type"), "application/json")
|
2015-12-30 01:33:16 +00:00
|
|
|
|
|
|
|
var v *types.Stats
|
|
|
|
err = json.NewDecoder(body).Decode(&v)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2015-12-30 01:33:16 +00:00
|
|
|
body.Close()
|
|
|
|
|
|
|
|
return v.MemoryStats.Limit
|
|
|
|
}
|
|
|
|
preMemLimit := getMemLimit(name)
|
|
|
|
|
|
|
|
dockerCmd(c, "update", "--cpu-quota", "2000", name)
|
|
|
|
|
|
|
|
curMemLimit := getMemLimit(name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, preMemLimit, curMemLimit)
|
2015-12-30 01:33:16 +00:00
|
|
|
}
|
2016-08-08 10:36:03 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *testing.T) {
|
2016-08-08 10:36:03 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
testRequires(c, memoryLimitSupport)
|
|
|
|
testRequires(c, swapMemorySupport)
|
|
|
|
|
|
|
|
name := "test-update-container"
|
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "--memory", "300M", "busybox", "top")
|
|
|
|
out, _, err := dockerCmdWithError("update", "--memory", "800M", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
|
|
|
assert.Assert(c, strings.Contains(out, "Memory limit should be smaller than already set memoryswap limit"))
|
2016-08-08 10:36:03 +00:00
|
|
|
|
|
|
|
dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name)
|
|
|
|
}
|
2016-12-17 01:57:05 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *testing.T) {
|
2016-12-17 01:57:05 +00:00
|
|
|
testRequires(c, DaemonIsLinux, cpuShare)
|
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "run", "-tid", "--restart=always", "busybox", "sh")
|
2019-08-05 15:54:15 +00:00
|
|
|
id := strings.TrimSpace(out)
|
2016-12-17 01:57:05 +00:00
|
|
|
dockerCmd(c, "update", "--cpu-shares", "512", id)
|
|
|
|
|
|
|
|
cpty, tty, err := pty.Open()
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-12-17 01:57:05 +00:00
|
|
|
defer cpty.Close()
|
|
|
|
|
|
|
|
cmd := exec.Command(dockerBinary, "attach", id)
|
|
|
|
cmd.Stdin = tty
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, cmd.Start())
|
2016-12-17 01:57:05 +00:00
|
|
|
defer cmd.Process.Kill()
|
|
|
|
|
|
|
|
_, err = cpty.Write([]byte("exit\n"))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-12-17 01:57:05 +00:00
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, cmd.Wait())
|
2016-12-17 01:57:05 +00:00
|
|
|
|
|
|
|
// container should restart again and keep running
|
|
|
|
err = waitInspect(id, "{{.RestartCount}}", "1", 30*time.Second)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.NilError(c, waitRun(id))
|
2016-12-17 01:57:05 +00:00
|
|
|
}
|
2017-02-18 06:04:37 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSuite) TestUpdateWithNanoCPUs(c *testing.T) {
|
2017-02-18 06:04:37 +00:00
|
|
|
testRequires(c, cpuCfsQuota, cpuCfsPeriod)
|
|
|
|
|
|
|
|
file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
|
|
|
|
file2 := "/sys/fs/cgroup/cpu/cpu.cfs_period_us"
|
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "run", "-d", "--cpus", "0.5", "--name", "top", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2017-02-18 06:04:37 +00:00
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "exec", "top", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "50000\n100000")
|
2017-02-18 06:04:37 +00:00
|
|
|
|
2019-01-03 21:49:00 +00:00
|
|
|
clt, err := client.NewClientWithOpts(client.FromEnv)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-09-01 19:14:59 +00:00
|
|
|
inspect, err := clt.ContainerInspect(context.Background(), "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, inspect.HostConfig.NanoCPUs, int64(500000000))
|
2017-09-01 19:14:59 +00:00
|
|
|
|
2017-02-18 06:04:37 +00:00
|
|
|
out = inspectField(c, "top", "HostConfig.CpuQuota")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, out, "0", "CPU CFS quota should be 0")
|
2017-02-18 06:04:37 +00:00
|
|
|
out = inspectField(c, "top", "HostConfig.CpuPeriod")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, out, "0", "CPU CFS period should be 0")
|
2017-02-18 06:04:37 +00:00
|
|
|
|
2017-09-01 19:14:59 +00:00
|
|
|
out, _, err = dockerCmdWithError("update", "--cpu-quota", "80000", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
|
|
|
assert.Assert(c, strings.Contains(out, "Conflicting options: CPU Quota cannot be updated as NanoCPUs has already been set"))
|
2017-02-18 06:04:37 +00:00
|
|
|
|
2018-07-09 17:40:34 +00:00
|
|
|
dockerCmd(c, "update", "--cpus", "0.8", "top")
|
2017-09-01 19:14:59 +00:00
|
|
|
inspect, err = clt.ContainerInspect(context.Background(), "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, inspect.HostConfig.NanoCPUs, int64(800000000))
|
2017-09-01 19:14:59 +00:00
|
|
|
|
2017-02-18 06:04:37 +00:00
|
|
|
out = inspectField(c, "top", "HostConfig.CpuQuota")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, out, "0", "CPU CFS quota should be 0")
|
2017-02-18 06:04:37 +00:00
|
|
|
out = inspectField(c, "top", "HostConfig.CpuPeriod")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, out, "0", "CPU CFS period should be 0")
|
2017-02-18 06:04:37 +00:00
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "exec", "top", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "80000\n100000")
|
2017-02-18 06:04:37 +00:00
|
|
|
}
|