Merge pull request #32546 from vdemeester/integration-clean-utils-take1

[test-integration] more clean on `docker_utils_test.go`, wait* functions
This commit is contained in:
Vincent Demeester 2017-04-15 17:17:56 +02:00 committed by GitHub
commit 6e577ea1c0
22 changed files with 242 additions and 245 deletions

View file

@ -58,6 +58,58 @@ func InspectCmd(t testingT, name string, cmdOperators ...CmdOperator) *icmd.Resu
return Docker(Inspect(name), cmdOperators...).Assert(t, icmd.Success)
}
// WaitRun will wait for the specified container to be running, maximum 5 seconds.
func WaitRun(t testingT, name string, cmdOperators ...CmdOperator) {
WaitForInspectResult(t, name, "{{.State.Running}}", "true", 5*time.Second, cmdOperators...)
}
// WaitExited will wait for the specified container to state exit, subject
// to a maximum time limit in seconds supplied by the caller
func WaitExited(t testingT, name string, timeout time.Duration, cmdOperators ...CmdOperator) {
WaitForInspectResult(t, name, "{{.State.Status}}", "exited", timeout, cmdOperators...)
}
// WaitRestart will wait for the specified container to restart once
func WaitRestart(t testingT, name string, timeout time.Duration, cmdOperators ...CmdOperator) {
WaitForInspectResult(t, name, "{{.RestartCount}}", "1", timeout, cmdOperators...)
}
// WaitForInspectResult waits for the specified expression to be equals to the specified expected string in the given time.
func WaitForInspectResult(t testingT, name, expr, expected string, timeout time.Duration, cmdOperators ...CmdOperator) {
after := time.After(timeout)
args := []string{"inspect", "-f", expr, name}
for {
result := Docker(Args(args...), cmdOperators...)
if result.Error != nil {
if !strings.Contains(strings.ToLower(result.Stderr()), "no such") {
t.Fatalf("error executing docker inspect: %v\n%s",
result.Stderr(), result.Stdout())
}
select {
case <-after:
t.Fatal(result.Error)
default:
time.Sleep(10 * time.Millisecond)
continue
}
}
out := strings.TrimSpace(result.Stdout())
if out == expected {
break
}
select {
case <-after:
t.Fatalf("condition \"%q == %q\" not true in time (%v)", out, expected, timeout)
default:
}
time.Sleep(100 * time.Millisecond)
}
}
// Docker executes the specified docker command
func Docker(cmd icmd.Cmd, cmdOperators ...CmdOperator) *icmd.Result {
for _, op := range cmdOperators {

View file

@ -758,7 +758,7 @@ func (d *Daemon) ReloadConfig() error {
}
// WaitInspectWithArgs waits for the specified expression to be equals to the specified expected string in the given time.
// FIXME(vdemeester) Attach this to the Daemon struct
// Deprecated: use cli.WaitCmd instead
func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time.Duration, arg ...string) error {
after := time.After(timeout)

View file

@ -21,6 +21,7 @@ import (
mounttypes "github.com/docker/docker/api/types/mount"
networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/cli/build"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/ioutils"
@ -347,25 +348,29 @@ func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
// Problematic on Windows as Windows does not support pause
testRequires(c, DaemonIsLinux)
defer unpauseAllContainers(c)
out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "30")
getPaused := func(c *check.C) []string {
return strings.Fields(cli.DockerCmd(c, "ps", "-f", "status=paused", "-q", "-a").Combined())
}
out := cli.DockerCmd(c, "run", "-d", "busybox", "sleep", "30").Combined()
ContainerID := strings.TrimSpace(out)
status, _, err := request.SockRequest("POST", "/containers/"+ContainerID+"/pause", nil, daemonHost())
resp, _, err := request.Post("/containers/" + ContainerID + "/pause")
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusNoContent)
c.Assert(resp.StatusCode, checker.Equals, http.StatusNoContent)
pausedContainers := getPausedContainers(c)
pausedContainers := getPaused(c)
if len(pausedContainers) != 1 || stringid.TruncateID(ContainerID) != pausedContainers[0] {
c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
}
status, _, err = request.SockRequest("POST", "/containers/"+ContainerID+"/unpause", nil, daemonHost())
resp, _, err = request.Post("/containers/" + ContainerID + "/unpause")
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusNoContent)
c.Assert(resp.StatusCode, checker.Equals, http.StatusNoContent)
pausedContainers = getPausedContainers(c)
pausedContainers = getPaused(c)
c.Assert(pausedContainers, checker.HasLen, 0, check.Commentf("There should be no paused container."))
}
@ -1262,7 +1267,6 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(
readOnly: true,
volumes: defaultVolumes(testVol), // Our bind mount is at /vol2
})
defer deleteContainer(cID)
// Attempt to extract to a symlink in the volume which points to a
// directory outside the volume. This should cause an error because the

View file

@ -10,6 +10,7 @@ import (
"sync"
"time"
"github.com/docker/docker/integration-cli/cli"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/go-check/check"
)
@ -22,8 +23,8 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
endGroup.Add(3)
startGroup.Add(3)
err := waitForContainer("attacher", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 1; echo hello; done")
c.Assert(err, check.IsNil)
cli.DockerCmd(c, "run", "--name", "attacher", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 1; echo hello; done")
cli.WaitRun(c, "attacher")
startDone := make(chan struct{})
endDone := make(chan struct{})
@ -77,7 +78,7 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
c.Fatalf("Attaches did not initialize properly")
}
dockerCmd(c, "kill", "attacher")
cli.DockerCmd(c, "kill", "attacher")
select {
case <-endDone:
@ -155,7 +156,6 @@ func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
func (s *DockerSuite) TestAttachPausedContainer(c *check.C) {
testRequires(c, IsPausable)
defer unpauseAllContainers(c)
runSleepingContainer(c, "-d", "--name=test")
dockerCmd(c, "pause", "test")

View file

@ -12,6 +12,7 @@ import (
"github.com/docker/distribution/manifest/schema2"
"github.com/docker/docker/api/types"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/cli/build"
"github.com/docker/docker/pkg/stringutils"
"github.com/go-check/check"
@ -35,24 +36,20 @@ func setupImageWithTag(c *check.C, tag string) (digest.Digest, error) {
// new file is committed because this layer is used for detecting malicious
// changes. if this was committed as empty layer it would be skipped on pull
// and malicious changes would never be detected.
dockerCmd(c, "run", "-e", "digest=1", "--name", containerName, "busybox", "touch", "anewfile")
cli.DockerCmd(c, "run", "-e", "digest=1", "--name", containerName, "busybox", "touch", "anewfile")
// tag the image to upload it to the private registry
repoAndTag := repoName + ":" + tag
out, _, err := dockerCmdWithError("commit", containerName, repoAndTag)
c.Assert(err, checker.IsNil, check.Commentf("image tagging failed: %s", out))
cli.DockerCmd(c, "commit", containerName, repoAndTag)
// delete the container as we don't need it any more
err = deleteContainer(containerName)
c.Assert(err, checker.IsNil)
cli.DockerCmd(c, "rm", "-fv", containerName)
// push the image
out, _, err = dockerCmdWithError("push", repoAndTag)
c.Assert(err, checker.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out))
out := cli.DockerCmd(c, "push", repoAndTag).Combined()
// delete our local repo that we previously tagged
rmiout, _, err := dockerCmdWithError("rmi", repoAndTag)
c.Assert(err, checker.IsNil, check.Commentf("error deleting images prior to real test: %s", rmiout))
cli.DockerCmd(c, "rmi", repoAndTag)
matches := pushDigestRegex.FindStringSubmatch(out)
c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from push output: %s", out))

View file

@ -40,7 +40,6 @@ func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
//test commit a paused container should not unpause it after commit
func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
defer unpauseAllContainers(c)
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox")
cleanedContainerID := strings.TrimSpace(out)

View file

@ -5,13 +5,14 @@ import (
"time"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/go-check/check"
)
// ensure that an added file shows up in docker diff
func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) {
containerCmd := `mkdir /foo; echo xyzzy > /foo/bar`
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd).Combined()
// Wait for it to exit as cannot diff a running container on Windows, and
// it will take a few seconds to exit. Also there's no way in Windows to
@ -20,13 +21,12 @@ func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) {
containerID := strings.TrimSpace(out)
lookingFor := "A /foo/bar"
if testEnv.DaemonPlatform() == "windows" {
err := waitExited(containerID, 60*time.Second)
c.Assert(err, check.IsNil)
cli.WaitExited(c, containerID, 60*time.Second)
lookingFor = "C Files/foo/bar"
}
cleanCID := strings.TrimSpace(out)
out, _ = dockerCmd(c, "diff", cleanCID)
out = cli.DockerCmd(c, "diff", cleanCID).Combined()
found := false
for _, line := range strings.Split(out, "\n") {

View file

@ -15,6 +15,7 @@ import (
eventtypes "github.com/docker/docker/api/types/events"
eventstestutils "github.com/docker/docker/daemon/events/testutils"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/cli/build"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/testutil"
@ -453,14 +454,14 @@ func (s *DockerSuite) TestEventsCommit(c *check.C) {
out, _ := runSleepingContainer(c)
cID := strings.TrimSpace(out)
c.Assert(waitRun(cID), checker.IsNil)
cli.WaitRun(c, cID)
dockerCmd(c, "commit", "-m", "test", cID)
dockerCmd(c, "stop", cID)
c.Assert(waitExited(cID, 5*time.Second), checker.IsNil)
cli.DockerCmd(c, "commit", "-m", "test", cID)
cli.DockerCmd(c, "stop", cID)
cli.WaitExited(c, cID, 5*time.Second)
until := daemonUnixTime(c)
out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until)
out = cli.DockerCmd(c, "events", "-f", "container="+cID, "--until="+until).Combined()
c.Assert(out, checker.Contains, "commit", check.Commentf("Missing 'commit' log event"))
}
@ -514,9 +515,9 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) {
// TODO Windows CI: Figure out why this test fails intermittently (TP5).
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-di", "busybox", "cat")
out := cli.DockerCmd(c, "run", "-di", "busybox", "cat").Combined()
cID := strings.TrimSpace(out)
c.Assert(waitRun(cID), checker.IsNil)
cli.WaitRun(c, cID)
cmd := exec.Command(dockerBinary, "attach", cID)
stdin, err := cmd.StdinPipe()
@ -537,11 +538,11 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) {
c.Assert(stdin.Close(), checker.IsNil)
dockerCmd(c, "kill", cID)
c.Assert(waitExited(cID, 5*time.Second), checker.IsNil)
cli.DockerCmd(c, "kill", cID)
cli.WaitExited(c, cID, 5*time.Second)
until := daemonUnixTime(c)
out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until)
out = cli.DockerCmd(c, "events", "-f", "container="+cID, "--until="+until).Combined()
c.Assert(out, checker.Contains, "attach", check.Commentf("Missing 'attach' log event"))
}

View file

@ -16,6 +16,7 @@ import (
"time"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/cli/build"
"github.com/docker/docker/integration-cli/request"
icmd "github.com/docker/docker/pkg/testutil/cmd"
@ -137,7 +138,6 @@ func (s *DockerSuite) TestExecExitStatus(c *check.C) {
func (s *DockerSuite) TestExecPausedContainer(c *check.C) {
testRequires(c, IsPausable)
defer unpauseAllContainers(c)
out, _ := runSleepingContainer(c, "-d", "--name", "testing")
ContainerID := strings.TrimSpace(out)
@ -389,7 +389,10 @@ func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
// Not applicable on Windows to Windows CI.
testRequires(c, SameHostDaemon, DaemonIsLinux)
for _, fn := range []string{"resolv.conf", "hosts"} {
deleteAllContainers(c)
containers := cli.DockerCmd(c, "ps", "-q", "-a").Combined()
if containers != "" {
cli.DockerCmd(c, append([]string{"rm", "-fv"}, strings.Split(strings.TrimSpace(containers), "\n")...)...)
}
content := runCommandAndReadContainerFile(c, fn, dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn))

View file

@ -53,9 +53,6 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) {
}
func (s *DockerSuite) TestInspectStatus(c *check.C) {
if testEnv.DaemonPlatform() != "windows" {
defer unpauseAllContainers(c)
}
out, _ := runSleepingContainer(c, "-d")
out = strings.TrimSpace(out)

View file

@ -7,19 +7,21 @@ import (
"time"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/request"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/go-check/check"
)
func (s *DockerSuite) TestKillContainer(c *check.C) {
out, _ := runSleepingContainer(c, "-d")
cleanedContainerID := strings.TrimSpace(out)
c.Assert(waitRun(cleanedContainerID), check.IsNil)
cli.WaitRun(c, cleanedContainerID)
dockerCmd(c, "kill", cleanedContainerID)
c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil)
cli.DockerCmd(c, "kill", cleanedContainerID)
cli.WaitExited(c, cleanedContainerID, 10*time.Second)
out, _ = dockerCmd(c, "ps", "-q")
out = cli.DockerCmd(c, "ps", "-q").Combined()
c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running"))
}
@ -28,24 +30,25 @@ func (s *DockerSuite) TestKillOffStoppedContainer(c *check.C) {
out, _ := runSleepingContainer(c, "-d")
cleanedContainerID := strings.TrimSpace(out)
dockerCmd(c, "stop", cleanedContainerID)
c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil)
cli.DockerCmd(c, "stop", cleanedContainerID)
cli.WaitExited(c, cleanedContainerID, 10*time.Second)
_, _, err := dockerCmdWithError("kill", "-s", "30", cleanedContainerID)
c.Assert(err, check.Not(check.IsNil), check.Commentf("Container %s is not running", cleanedContainerID))
cli.Docker(cli.Args("kill", "-s", "30", cleanedContainerID)).Assert(c, icmd.Expected{
ExitCode: 1,
})
}
func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
// TODO Windows: Windows does not yet support -u (Feb 2016).
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-u", "daemon", "-d", "busybox", "top")
out := cli.DockerCmd(c, "run", "-u", "daemon", "-d", "busybox", "top").Combined()
cleanedContainerID := strings.TrimSpace(out)
c.Assert(waitRun(cleanedContainerID), check.IsNil)
cli.WaitRun(c, cleanedContainerID)
dockerCmd(c, "kill", cleanedContainerID)
c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil)
cli.DockerCmd(c, "kill", cleanedContainerID)
cli.WaitExited(c, cleanedContainerID, 10*time.Second)
out, _ = dockerCmd(c, "ps", "-q")
out = cli.DockerCmd(c, "ps", "-q").Combined()
c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running"))
}
@ -69,33 +72,33 @@ func (s *DockerSuite) TestKillWithSignal(c *check.C) {
func (s *DockerSuite) TestKillWithStopSignalWithSameSignalShouldDisableRestartPolicy(c *check.C) {
// Cannot port to Windows - does not support signals int the same way as Linux does
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "--stop-signal=TERM", "--restart=always", "busybox", "top")
out := cli.DockerCmd(c, "run", "-d", "--stop-signal=TERM", "--restart=always", "busybox", "top").Combined()
cid := strings.TrimSpace(out)
c.Assert(waitRun(cid), check.IsNil)
cli.WaitRun(c, cid)
// Let docker send a TERM signal to the container
// It will kill the process and disable the restart policy
dockerCmd(c, "kill", "-s", "TERM", cid)
c.Assert(waitExited(cid, 10*time.Second), check.IsNil)
cli.DockerCmd(c, "kill", "-s", "TERM", cid)
cli.WaitExited(c, cid, 10*time.Second)
out, _ = dockerCmd(c, "ps", "-q")
out = cli.DockerCmd(c, "ps", "-q").Combined()
c.Assert(out, checker.Not(checker.Contains), cid, check.Commentf("killed container is still running"))
}
func (s *DockerSuite) TestKillWithStopSignalWithDifferentSignalShouldKeepRestartPolicy(c *check.C) {
// Cannot port to Windows - does not support signals int the same way as Linux does
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "--stop-signal=CONT", "--restart=always", "busybox", "top")
out := cli.DockerCmd(c, "run", "-d", "--stop-signal=CONT", "--restart=always", "busybox", "top").Combined()
cid := strings.TrimSpace(out)
c.Assert(waitRun(cid), check.IsNil)
cli.WaitRun(c, cid)
// Let docker send a TERM signal to the container
// It will kill the process, but not disable the restart policy
dockerCmd(c, "kill", "-s", "TERM", cid)
c.Assert(waitRestart(cid, 10*time.Second), check.IsNil)
cli.DockerCmd(c, "kill", "-s", "TERM", cid)
cli.WaitRestart(c, cid, 10*time.Second)
// Restart policy should still be in place, so it should be still running
c.Assert(waitRun(cid), check.IsNil)
cli.WaitRun(c, cid)
}
// FIXME(vdemeester) should be a unit test

View file

@ -7,18 +7,23 @@ import (
"strings"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/go-check/check"
)
func startServerContainer(c *check.C, msg string, port int) string {
name := "server"
cmd := []string{
"run",
"--name",
name,
"-d",
"-p", fmt.Sprintf("%d:%d", port, port),
"busybox",
"sh", "-c", fmt.Sprintf("echo %q | nc -lp %d", msg, port),
}
c.Assert(waitForContainer(name, cmd...), check.IsNil)
cli.DockerCmd(c, cmd...)
cli.WaitRun(c, name)
return name
}

View file

@ -18,6 +18,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/versions/v1p20"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/daemon"
"github.com/docker/docker/pkg/stringid"
icmd "github.com/docker/docker/pkg/testutil/cmd"
@ -1797,18 +1798,16 @@ func (s *DockerNetworkSuite) TestConntrackFlowsLeak(c *check.C) {
testRequires(c, IsAmd64, DaemonIsLinux, Network)
// Create a new network
dockerCmd(c, "network", "create", "--subnet=192.168.10.0/24", "--gateway=192.168.10.1", "-o", "com.docker.network.bridge.host_binding_ipv4=192.168.10.1", "testbind")
cli.DockerCmd(c, "network", "create", "--subnet=192.168.10.0/24", "--gateway=192.168.10.1", "-o", "com.docker.network.bridge.host_binding_ipv4=192.168.10.1", "testbind")
assertNwIsAvailable(c, "testbind")
// Launch the server, this will remain listening on an exposed port and reply to any request in a ping/pong fashion
cmd := "while true; do echo hello | nc -w 1 -lu 8080; done"
_, _, err := dockerCmdWithError("run", "-d", "--name", "server", "--net", "testbind", "-p", "8080:8080/udp", "appropriate/nc", "sh", "-c", cmd)
c.Assert(err, check.IsNil)
cli.DockerCmd(c, "run", "-d", "--name", "server", "--net", "testbind", "-p", "8080:8080/udp", "appropriate/nc", "sh", "-c", cmd)
// Launch a container client, here the objective is to create a flow that is natted in order to expose the bug
cmd = "echo world | nc -q 1 -u 192.168.10.1 8080"
_, _, err = dockerCmdWithError("run", "-d", "--name", "client", "--net=host", "appropriate/nc", "sh", "-c", cmd)
c.Assert(err, check.IsNil)
cli.DockerCmd(c, "run", "-d", "--name", "client", "--net=host", "appropriate/nc", "sh", "-c", cmd)
// Get all the flows using netlink
flows, err := netlink.ConntrackTableList(netlink.ConntrackTable, syscall.AF_INET)
@ -1826,8 +1825,7 @@ func (s *DockerNetworkSuite) TestConntrackFlowsLeak(c *check.C) {
c.Assert(flowMatch, checker.Equals, 1)
// Now delete the server, this will trigger the conntrack cleanup
err = deleteContainer("server")
c.Assert(err, checker.IsNil)
cli.DockerCmd(c, "rm", "-fv", "server")
// Fetch again all the flows and validate that there is no server flow in the conntrack laying around
flows, err = netlink.ConntrackTableList(netlink.ConntrackTable, syscall.AF_INET)

View file

@ -4,23 +4,25 @@ import (
"strings"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/go-check/check"
)
func (s *DockerSuite) TestPause(c *check.C) {
testRequires(c, IsPausable)
defer unpauseAllContainers(c)
name := "testeventpause"
runSleepingContainer(c, "-d", "--name", name)
dockerCmd(c, "pause", name)
pausedContainers := getPausedContainers(c)
cli.DockerCmd(c, "pause", name)
pausedContainers := strings.Fields(
cli.DockerCmd(c, "ps", "-f", "status=paused", "-q", "-a").Combined(),
)
c.Assert(len(pausedContainers), checker.Equals, 1)
dockerCmd(c, "unpause", name)
cli.DockerCmd(c, "unpause", name)
out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c))
out := cli.DockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c)).Combined()
events := strings.Split(strings.TrimSpace(out), "\n")
actions := eventActionsByIDAndType(c, events, name, "container")
@ -30,7 +32,6 @@ func (s *DockerSuite) TestPause(c *check.C) {
func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
testRequires(c, IsPausable)
defer unpauseAllContainers(c)
containers := []string{
"testpausewithmorecontainers1",
@ -39,13 +40,15 @@ func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
for _, name := range containers {
runSleepingContainer(c, "-d", "--name", name)
}
dockerCmd(c, append([]string{"pause"}, containers...)...)
pausedContainers := getPausedContainers(c)
cli.DockerCmd(c, append([]string{"pause"}, containers...)...)
pausedContainers := strings.Fields(
cli.DockerCmd(c, "ps", "-f", "status=paused", "-q", "-a").Combined(),
)
c.Assert(len(pausedContainers), checker.Equals, len(containers))
dockerCmd(c, append([]string{"unpause"}, containers...)...)
cli.DockerCmd(c, append([]string{"unpause"}, containers...)...)
out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c))
out := cli.DockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c)).Combined()
events := strings.Split(strings.TrimSpace(out), "\n")
for _, name := range containers {

View file

@ -11,6 +11,7 @@ import (
"time"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/daemon"
"github.com/go-check/check"
)
@ -96,41 +97,41 @@ func (s *DockerDaemonSuite) TestPruneImageDangling(c *check.C) {
}
func (s *DockerSuite) TestPruneContainerUntil(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox")
out := cli.DockerCmd(c, "run", "-d", "busybox").Combined()
id1 := strings.TrimSpace(out)
c.Assert(waitExited(id1, 5*time.Second), checker.IsNil)
cli.WaitExited(c, id1, 5*time.Second)
until := daemonUnixTime(c)
out, _ = dockerCmd(c, "run", "-d", "busybox")
out = cli.DockerCmd(c, "run", "-d", "busybox").Combined()
id2 := strings.TrimSpace(out)
c.Assert(waitExited(id2, 5*time.Second), checker.IsNil)
cli.WaitExited(c, id2, 5*time.Second)
out, _ = dockerCmd(c, "container", "prune", "--force", "--filter", "until="+until)
out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "until="+until).Combined()
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc")
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
}
func (s *DockerSuite) TestPruneContainerLabel(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "--label", "foo", "busybox")
out := cli.DockerCmd(c, "run", "-d", "--label", "foo", "busybox").Combined()
id1 := strings.TrimSpace(out)
c.Assert(waitExited(id1, 5*time.Second), checker.IsNil)
cli.WaitExited(c, id1, 5*time.Second)
out, _ = dockerCmd(c, "run", "-d", "--label", "bar", "busybox")
out = cli.DockerCmd(c, "run", "-d", "--label", "bar", "busybox").Combined()
id2 := strings.TrimSpace(out)
c.Assert(waitExited(id2, 5*time.Second), checker.IsNil)
cli.WaitExited(c, id2, 5*time.Second)
out, _ = dockerCmd(c, "run", "-d", "busybox")
out = cli.DockerCmd(c, "run", "-d", "busybox").Combined()
id3 := strings.TrimSpace(out)
c.Assert(waitExited(id3, 5*time.Second), checker.IsNil)
cli.WaitExited(c, id3, 5*time.Second)
out, _ = dockerCmd(c, "run", "-d", "--label", "foobar", "busybox")
out = cli.DockerCmd(c, "run", "-d", "--label", "foobar", "busybox").Combined()
id4 := strings.TrimSpace(out)
c.Assert(waitExited(id4, 5*time.Second), checker.IsNil)
cli.WaitExited(c, id4, 5*time.Second)
// Add a config file of label=foobar, that will have no impact if cli is label!=foobar
config := `{"pruneFilters": ["label=foobar"]}`
@ -141,35 +142,35 @@ func (s *DockerSuite) TestPruneContainerLabel(c *check.C) {
c.Assert(err, checker.IsNil)
// With config.json only, prune based on label=foobar
out, _ = dockerCmd(c, "--config", d, "container", "prune", "--force")
out = cli.DockerCmd(c, "--config", d, "container", "prune", "--force").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
c.Assert(strings.TrimSpace(out), checker.Contains, id4)
out, _ = dockerCmd(c, "container", "prune", "--force", "--filter", "label=foo")
out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "label=foo").Combined()
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc")
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
out, _ = dockerCmd(c, "container", "prune", "--force", "--filter", "label!=bar")
out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "label!=bar").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc")
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
// With config.json label=foobar and CLI label!=foobar, CLI label!=foobar supersede
out, _ = dockerCmd(c, "--config", d, "container", "prune", "--force", "--filter", "label!=foobar")
out = cli.DockerCmd(c, "--config", d, "container", "prune", "--force", "--filter", "label!=foobar").Combined()
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc")
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
}

View file

@ -231,9 +231,9 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
out, _ := runSleepingContainer(c, "--name=none_legacy")
containerID := strings.TrimSpace(out)
waitForContainer(containerID)
cli.WaitRun(c, containerID)
out, _ = dockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none")
out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined()
containerOut := strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for legacy none filter, output: %q", containerID, containerOut, out))
@ -241,9 +241,9 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
out, _ = runSleepingContainer(c, "--name=none", "--no-healthcheck")
containerID = strings.TrimSpace(out)
waitForContainer(containerID)
cli.WaitRun(c, containerID)
out, _ = dockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none")
out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined()
containerOut = strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for none filter, output: %q", containerID, containerOut, out))
@ -253,7 +253,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
waitForHealthStatus(c, "failing_container", "starting", "unhealthy")
out, _ = dockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=unhealthy")
out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=unhealthy").Combined()
containerOut = strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for unhealthy filter, output: %q", containerID, containerOut, out))
@ -263,7 +263,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
waitForHealthStatus(c, "passing_container", "starting", "healthy")
out, _ = dockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy")
out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy").Combined()
containerOut = strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out))
}

View file

@ -6,6 +6,7 @@ import (
"time"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/cli/build"
"github.com/docker/docker/pkg/stringid"
icmd "github.com/docker/docker/pkg/testutil/cmd"
@ -62,24 +63,22 @@ func (s *DockerSuite) TestRmiTag(c *check.C) {
}
func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'")
out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'").Combined()
containerID := strings.TrimSpace(out)
// Wait for it to exit as cannot commit a running container on Windows, and
// it will take a few seconds to exit
if testEnv.DaemonPlatform() == "windows" {
err := waitExited(containerID, 60*time.Second)
c.Assert(err, check.IsNil)
cli.WaitExited(c, containerID, 60*time.Second)
}
dockerCmd(c, "commit", containerID, "busybox-one")
cli.DockerCmd(c, "commit", containerID, "busybox-one")
imagesBefore, _ := dockerCmd(c, "images", "-a")
dockerCmd(c, "tag", "busybox-one", "busybox-one:tag1")
dockerCmd(c, "tag", "busybox-one", "busybox-one:tag2")
imagesBefore := cli.DockerCmd(c, "images", "-a").Combined()
cli.DockerCmd(c, "tag", "busybox-one", "busybox-one:tag1")
cli.DockerCmd(c, "tag", "busybox-one", "busybox-one:tag2")
imagesAfter, _ := dockerCmd(c, "images", "-a")
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
// tag busybox to create 2 more images with same imageID
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("docker images shows: %q\n", imagesAfter))
@ -87,59 +86,55 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
// run a container with the image
out, _ = runSleepingContainerInImage(c, "busybox-one")
containerID = strings.TrimSpace(out)
// first checkout without force it fails
out, _, err := dockerCmdWithError("rmi", imgID)
expected := fmt.Sprintf("conflict: unable to delete %s (cannot be forced) - image is being used by running container %s", stringid.TruncateID(imgID), stringid.TruncateID(containerID))
// rmi tagged in multiple repos should have failed without force
c.Assert(err, checker.NotNil)
c.Assert(out, checker.Contains, expected)
cli.Docker(cli.Args("rmi", imgID)).Assert(c, icmd.Expected{
ExitCode: 1,
Err: fmt.Sprintf("conflict: unable to delete %s (cannot be forced) - image is being used by running container %s", stringid.TruncateID(imgID), stringid.TruncateID(containerID)),
})
dockerCmd(c, "stop", containerID)
dockerCmd(c, "rmi", "-f", imgID)
cli.DockerCmd(c, "stop", containerID)
cli.DockerCmd(c, "rmi", "-f", imgID)
imagesAfter, _ = dockerCmd(c, "images", "-a")
imagesAfter = cli.DockerCmd(c, "images", "-a").Combined()
// rmi -f failed, image still exists
c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12], check.Commentf("ImageID:%q; ImagesAfter: %q", imgID, imagesAfter))
}
func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'")
out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'").Combined()
containerID := strings.TrimSpace(out)
// Wait for it to exit as cannot commit a running container on Windows, and
// it will take a few seconds to exit
if testEnv.DaemonPlatform() == "windows" {
err := waitExited(containerID, 60*time.Second)
c.Assert(err, check.IsNil)
cli.WaitExited(c, containerID, 60*time.Second)
}
dockerCmd(c, "commit", containerID, "busybox-test")
cli.DockerCmd(c, "commit", containerID, "busybox-test")
imagesBefore, _ := dockerCmd(c, "images", "-a")
dockerCmd(c, "tag", "busybox-test", "utest:tag1")
dockerCmd(c, "tag", "busybox-test", "utest:tag2")
dockerCmd(c, "tag", "busybox-test", "utest/docker:tag3")
dockerCmd(c, "tag", "busybox-test", "utest:5000/docker:tag4")
imagesBefore := cli.DockerCmd(c, "images", "-a").Combined()
cli.DockerCmd(c, "tag", "busybox-test", "utest:tag1")
cli.DockerCmd(c, "tag", "busybox-test", "utest:tag2")
cli.DockerCmd(c, "tag", "busybox-test", "utest/docker:tag3")
cli.DockerCmd(c, "tag", "busybox-test", "utest:5000/docker:tag4")
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+4, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
imgID := inspectField(c, "busybox-test", "Id")
// first checkout without force it fails
out, _, err := dockerCmdWithError("rmi", imgID)
// rmi tagged in multiple repos should have failed without force
c.Assert(err, checker.NotNil)
// rmi tagged in multiple repos should have failed without force
c.Assert(out, checker.Contains, "(must be forced) - image is referenced in multiple repositories", check.Commentf("out: %s; err: %v;", out, err))
cli.Docker(cli.Args("rmi", imgID)).Assert(c, icmd.Expected{
ExitCode: 1,
Err: "(must be forced) - image is referenced in multiple repositories",
})
dockerCmd(c, "rmi", "-f", imgID)
cli.DockerCmd(c, "rmi", "-f", imgID)
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
// rmi failed, image still exists
c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12])
}

View file

@ -2025,18 +2025,16 @@ func (s *DockerSuite) TestRunDeallocatePortOnMissingIptablesRule(c *check.C) {
// TODO Windows. Network settings are not propagated back to inspect.
testRequires(c, SameHostDaemon, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "-p", "23:23", "busybox", "top")
out := cli.DockerCmd(c, "run", "-d", "-p", "23:23", "busybox", "top").Combined()
id := strings.TrimSpace(out)
ip := inspectField(c, id, "NetworkSettings.Networks.bridge.IPAddress")
icmd.RunCommand("iptables", "-D", "DOCKER", "-d", fmt.Sprintf("%s/32", ip),
"!", "-i", "docker0", "-o", "docker0", "-p", "tcp", "-m", "tcp", "--dport", "23", "-j", "ACCEPT").Assert(c, icmd.Success)
if err := deleteContainer(id); err != nil {
c.Fatal(err)
}
cli.DockerCmd(c, "rm", "-fv", id)
dockerCmd(c, "run", "-d", "-p", "23:23", "busybox", "top")
cli.DockerCmd(c, "run", "-d", "-p", "23:23", "busybox", "top")
}
func (s *DockerSuite) TestRunPortInUse(c *check.C) {
@ -2817,12 +2815,11 @@ func (s *DockerSuite) TestRunVolumesFromRestartAfterRemoved(c *check.C) {
// run container with --rm should remove container if exit code != 0
func (s *DockerSuite) TestRunContainerWithRmFlagExitCodeNotEqualToZero(c *check.C) {
name := "flowers"
out, _, err := dockerCmdWithError("run", "--name", name, "--rm", "busybox", "ls", "/notexists")
if err == nil {
c.Fatal("Expected docker run to fail", out, err)
}
cli.Docker(cli.Args("run", "--name", name, "--rm", "busybox", "ls", "/notexists")).Assert(c, icmd.Expected{
ExitCode: 1,
})
out = getAllContainers(c)
out := cli.DockerCmd(c, "ps", "-q", "-a").Combined()
if out != "" {
c.Fatal("Expected not to have containers", out)
}
@ -2830,12 +2827,10 @@ func (s *DockerSuite) TestRunContainerWithRmFlagExitCodeNotEqualToZero(c *check.
func (s *DockerSuite) TestRunContainerWithRmFlagCannotStartContainer(c *check.C) {
name := "sparkles"
out, _, err := dockerCmdWithError("run", "--name", name, "--rm", "busybox", "commandNotFound")
if err == nil {
c.Fatal("Expected docker run to fail", out, err)
}
out = getAllContainers(c)
cli.Docker(cli.Args("run", "--name", name, "--rm", "busybox", "commandNotFound")).Assert(c, icmd.Expected{
ExitCode: 127,
})
out := cli.DockerCmd(c, "ps", "-q", "-a").Combined()
if out != "" {
c.Fatal("Expected not to have containers", out)
}
@ -4265,10 +4260,9 @@ func (s *DockerSuite) TestRunCredentialSpecWellFormed(c *check.C) {
func (s *DockerSuite) TestRunServicingContainer(c *check.C) {
testRequires(c, DaemonIsWindows, SameHostDaemon)
out, _ := dockerCmd(c, "run", "-d", testEnv.MinimalBaseImage(), "cmd", "/c", "mkdir c:\\programdata\\Microsoft\\Windows\\ContainerUpdates\\000_000_d99f45d0-ffc8-4af7-bd9c-ea6a62e035c9_200 && sc control cexecsvc 255")
out := cli.DockerCmd(c, "run", "-d", testEnv.MinimalBaseImage(), "cmd", "/c", "mkdir c:\\programdata\\Microsoft\\Windows\\ContainerUpdates\\000_000_d99f45d0-ffc8-4af7-bd9c-ea6a62e035c9_200 && sc control cexecsvc 255").Combined()
containerID := strings.TrimSpace(out)
err := waitExited(containerID, 60*time.Second)
c.Assert(err, checker.IsNil)
cli.WaitExited(c, containerID, 60*time.Second)
result := icmd.RunCommand("powershell", "echo", `(Get-WinEvent -ProviderName "Microsoft-Windows-Hyper-V-Compute" -FilterXPath 'Event[System[EventID=2010]]' -MaxEvents 1).Message`)
result.Assert(c, icmd.Success)

View file

@ -94,7 +94,6 @@ func (s *DockerSuite) TestStartRecordError(c *check.C) {
func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
// Windows does not support pausing containers
testRequires(c, IsPausable)
defer unpauseAllContainers(c)
runSleepingContainer(c, "-d", "--name", "testing")
@ -174,17 +173,15 @@ func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) {
// Test case for #23716
func (s *DockerSuite) TestStartAttachWithRename(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "create", "-t", "--name", "before", "busybox")
cli.DockerCmd(c, "create", "-t", "--name", "before", "busybox")
go func() {
c.Assert(waitRun("before"), checker.IsNil)
dockerCmd(c, "rename", "before", "after")
dockerCmd(c, "stop", "--time=2", "after")
cli.WaitRun(c, "before")
cli.DockerCmd(c, "rename", "before", "after")
cli.DockerCmd(c, "stop", "--time=2", "after")
}()
// FIXME(vdemeester) the intent is not clear and potentially racey
result := icmd.RunCommand(dockerBinary, "start", "-a", "before")
result.Assert(c, icmd.Expected{
result := cli.Docker(cli.Args("start", "-a", "before")).Assert(c, icmd.Expected{
ExitCode: 137,
Error: "exit status 137",
})
c.Assert(result.Stderr(), checker.Not(checker.Contains), "No such container")
}

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/go-check/check"
)
@ -162,17 +163,17 @@ func (s *DockerSuite) TestStatsFormatAll(c *check.C) {
// Windows does not support stats
testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--name=RunningOne", "busybox", "top")
c.Assert(waitRun("RunningOne"), check.IsNil)
dockerCmd(c, "run", "-d", "--name=ExitedOne", "busybox", "top")
dockerCmd(c, "stop", "ExitedOne")
c.Assert(waitExited("ExitedOne", 5*time.Second), check.IsNil)
cli.DockerCmd(c, "run", "-d", "--name=RunningOne", "busybox", "top")
cli.WaitRun(c, "RunningOne")
cli.DockerCmd(c, "run", "-d", "--name=ExitedOne", "busybox", "top")
cli.DockerCmd(c, "stop", "ExitedOne")
cli.WaitExited(c, "ExitedOne", 5*time.Second)
out, _ := dockerCmd(c, "stats", "--no-stream", "--format", "{{.Name}}")
out := cli.DockerCmd(c, "stats", "--no-stream", "--format", "{{.Name}}").Combined()
c.Assert(out, checker.Contains, "RunningOne")
c.Assert(out, checker.Not(checker.Contains), "ExitedOne")
out, _ = dockerCmd(c, "stats", "--all", "--no-stream", "--format", "{{.Name}}")
out = cli.DockerCmd(c, "stats", "--all", "--no-stream", "--format", "{{.Name}}").Combined()
c.Assert(out, checker.Contains, "RunningOne")
c.Assert(out, checker.Contains, "ExitedOne")
}

View file

@ -5,11 +5,13 @@ import (
"time"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/go-check/check"
)
func (s *DockerSuite) TestUpdateRestartPolicy(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "sh", "-c", "sleep 1 && false")
out := cli.DockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "sh", "-c", "sleep 1 && false").Combined()
timeout := 60 * time.Second
if testEnv.DaemonPlatform() == "windows" {
timeout = 180 * time.Second
@ -18,10 +20,9 @@ func (s *DockerSuite) TestUpdateRestartPolicy(c *check.C) {
id := strings.TrimSpace(string(out))
// update restart policy to on-failure:5
dockerCmd(c, "update", "--restart=on-failure:5", id)
cli.DockerCmd(c, "update", "--restart=on-failure:5", id)
err := waitExited(id, timeout)
c.Assert(err, checker.IsNil)
cli.WaitExited(c, id, timeout)
count := inspectField(c, id, "RestartCount")
c.Assert(count, checker.Equals, "5")
@ -35,7 +36,8 @@ func (s *DockerSuite) TestUpdateRestartWithAutoRemoveFlag(c *check.C) {
id := strings.TrimSpace(out)
// update restart policy for an AutoRemove container
out, _, err := dockerCmdWithError("update", "--restart=always", id)
c.Assert(err, checker.NotNil)
c.Assert(out, checker.Contains, "Restart policy cannot be updated because AutoRemove is enabled for the container")
cli.Docker(cli.Args("update", "--restart=always", id)).Assert(c, icmd.Expected{
ExitCode: 1,
Err: "Restart policy cannot be updated because AutoRemove is enabled for the container",
})
}

View file

@ -33,44 +33,6 @@ func daemonHost() string {
return request.DaemonHost()
}
// FIXME(vdemeester) move this away are remove ignoreNoSuchContainer bool
func deleteContainer(container ...string) error {
return icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, container...)...).Compare(icmd.Success)
}
func getAllContainers(c *check.C) string {
result := icmd.RunCommand(dockerBinary, "ps", "-q", "-a")
result.Assert(c, icmd.Success)
return result.Combined()
}
// Deprecated
func deleteAllContainers(c *check.C) {
containers := getAllContainers(c)
if containers != "" {
err := deleteContainer(strings.Split(strings.TrimSpace(containers), "\n")...)
c.Assert(err, checker.IsNil)
}
}
func getPausedContainers(c *check.C) []string {
result := icmd.RunCommand(dockerBinary, "ps", "-f", "status=paused", "-q", "-a")
result.Assert(c, icmd.Success)
return strings.Fields(result.Combined())
}
func unpauseContainer(c *check.C, container string) {
dockerCmd(c, "unpause", container)
}
// Deprecated
func unpauseAllContainers(c *check.C) {
containers := getPausedContainers(c)
for _, value := range containers {
unpauseContainer(c, value)
}
}
func deleteImages(images ...string) error {
args := []string{dockerBinary, "rmi", "-f"}
return icmd.RunCmd(icmd.Cmd{Command: append(args, images...)}).Error
@ -496,38 +458,21 @@ func createTmpFile(c *check.C, content string) string {
return filename
}
func waitForContainer(contID string, args ...string) error {
args = append([]string{dockerBinary, "run", "--name", contID}, args...)
result := icmd.RunCmd(icmd.Cmd{Command: args})
if result.Error != nil {
return result.Error
}
return waitRun(contID)
}
// waitRestart will wait for the specified container to restart once
func waitRestart(contID string, duration time.Duration) error {
return waitInspect(contID, "{{.RestartCount}}", "1", duration)
}
// waitRun will wait for the specified container to be running, maximum 5 seconds.
// Deprecated: use cli.WaitFor
func waitRun(contID string) error {
return waitInspect(contID, "{{.State.Running}}", "true", 5*time.Second)
}
// waitExited will wait for the specified container to state exit, subject
// to a maximum time limit in seconds supplied by the caller
func waitExited(contID string, duration time.Duration) error {
return waitInspect(contID, "{{.State.Status}}", "exited", duration)
}
// waitInspect will wait for the specified container to have the specified string
// in the inspect output. It will wait until the specified timeout (in seconds)
// is reached.
// Deprecated: use cli.WaitFor
func waitInspect(name, expr, expected string, timeout time.Duration) error {
return waitInspectWithArgs(name, expr, expected, timeout)
}
// Deprecated: use cli.WaitFor
func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg ...string) error {
return daemon.WaitInspectWithArgs(dockerBinary, name, expr, expected, timeout, arg...)
}