1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #34707 from vieux/force_format

force inspect test format
This commit is contained in:
Victor Vieux 2017-09-05 13:35:07 -07:00 committed by GitHub
commit d7b4c7e0ea
2 changed files with 22 additions and 8 deletions

View file

@ -4,6 +4,7 @@ package main
import ( import (
"bufio" "bufio"
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -16,6 +17,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/cli/build" "github.com/docker/docker/integration-cli/cli/build"
@ -1563,14 +1565,18 @@ func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) {
out, _ := dockerCmd(c, "run", "--cpus", "0.5", "--name", "test", "busybox", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2)) out, _ := dockerCmd(c, "run", "--cpus", "0.5", "--name", "test", "busybox", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2))
c.Assert(strings.TrimSpace(out), checker.Equals, "50000\n100000") c.Assert(strings.TrimSpace(out), checker.Equals, "50000\n100000")
out = inspectField(c, "test", "HostConfig.NanoCpus") clt, err := client.NewEnvClient()
c.Assert(out, checker.Equals, "5e+08", check.Commentf("setting the Nano CPUs failed")) c.Assert(err, checker.IsNil)
inspect, err := clt.ContainerInspect(context.Background(), "test")
c.Assert(err, checker.IsNil)
c.Assert(inspect.HostConfig.NanoCPUs, checker.Equals, int64(500000000))
out = inspectField(c, "test", "HostConfig.CpuQuota") out = inspectField(c, "test", "HostConfig.CpuQuota")
c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0")) c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0"))
out = inspectField(c, "test", "HostConfig.CpuPeriod") out = inspectField(c, "test", "HostConfig.CpuPeriod")
c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS period should be 0")) c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS period should be 0"))
out, _, err := dockerCmdWithError("run", "--cpus", "0.5", "--cpu-quota", "50000", "--cpu-period", "100000", "busybox", "sh") out, _, err = dockerCmdWithError("run", "--cpus", "0.5", "--cpu-quota", "50000", "--cpu-period", "100000", "busybox", "sh")
c.Assert(err, check.NotNil) c.Assert(err, check.NotNil)
c.Assert(out, checker.Contains, "Conflicting options: Nano CPUs and CPU Period cannot both be set") c.Assert(out, checker.Contains, "Conflicting options: Nano CPUs and CPU Period cannot both be set")
} }

View file

@ -3,6 +3,7 @@
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os/exec" "os/exec"
@ -10,6 +11,7 @@ import (
"time" "time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/request" "github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/parsers/kernel"
@ -295,20 +297,26 @@ func (s *DockerSuite) TestUpdateWithNanoCPUs(c *check.C) {
out, _ = dockerCmd(c, "exec", "top", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2)) out, _ = dockerCmd(c, "exec", "top", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2))
c.Assert(strings.TrimSpace(out), checker.Equals, "50000\n100000") c.Assert(strings.TrimSpace(out), checker.Equals, "50000\n100000")
out = inspectField(c, "top", "HostConfig.NanoCpus") clt, err := client.NewEnvClient()
c.Assert(out, checker.Equals, "5e+08", check.Commentf("setting the Nano CPUs failed")) c.Assert(err, checker.IsNil)
inspect, err := clt.ContainerInspect(context.Background(), "top")
c.Assert(err, checker.IsNil)
c.Assert(inspect.HostConfig.NanoCPUs, checker.Equals, int64(500000000))
out = inspectField(c, "top", "HostConfig.CpuQuota") out = inspectField(c, "top", "HostConfig.CpuQuota")
c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0")) c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0"))
out = inspectField(c, "top", "HostConfig.CpuPeriod") out = inspectField(c, "top", "HostConfig.CpuPeriod")
c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS period should be 0")) c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS period should be 0"))
out, _, err := dockerCmdWithError("update", "--cpu-quota", "80000", "top") out, _, err = dockerCmdWithError("update", "--cpu-quota", "80000", "top")
c.Assert(err, checker.NotNil) c.Assert(err, checker.NotNil)
c.Assert(out, checker.Contains, "Conflicting options: CPU Quota cannot be updated as NanoCPUs has already been set") c.Assert(out, checker.Contains, "Conflicting options: CPU Quota cannot be updated as NanoCPUs has already been set")
out, _ = dockerCmd(c, "update", "--cpus", "0.8", "top") out, _ = dockerCmd(c, "update", "--cpus", "0.8", "top")
out = inspectField(c, "top", "HostConfig.NanoCpus") inspect, err = clt.ContainerInspect(context.Background(), "top")
c.Assert(out, checker.Equals, "8e+08", check.Commentf("updating the Nano CPUs failed")) c.Assert(err, checker.IsNil)
c.Assert(inspect.HostConfig.NanoCPUs, checker.Equals, int64(800000000))
out = inspectField(c, "top", "HostConfig.CpuQuota") out = inspectField(c, "top", "HostConfig.CpuQuota")
c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0")) c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0"))
out = inspectField(c, "top", "HostConfig.CpuPeriod") out = inspectField(c, "top", "HostConfig.CpuPeriod")