2015-01-30 19:23:47 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2017-04-11 13:42:54 -04:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2015-01-30 19:23:47 -05:00
|
|
|
)
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestPause(c *check.C) {
|
2016-09-08 20:31:04 -04:00
|
|
|
testRequires(c, IsPausable)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
|
|
|
name := "testeventpause"
|
2016-09-08 20:31:04 -04:00
|
|
|
runSleepingContainer(c, "-d", "--name", name)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2017-04-11 13:42:54 -04:00
|
|
|
cli.DockerCmd(c, "pause", name)
|
|
|
|
pausedContainers := strings.Fields(
|
|
|
|
cli.DockerCmd(c, "ps", "-f", "status=paused", "-q", "-a").Combined(),
|
|
|
|
)
|
2015-10-14 12:09:33 -04:00
|
|
|
c.Assert(len(pausedContainers), checker.Equals, 1)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2017-04-11 13:42:54 -04:00
|
|
|
cli.DockerCmd(c, "unpause", name)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2017-04-11 13:42:54 -04:00
|
|
|
out := cli.DockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c)).Combined()
|
2015-12-21 17:55:23 -05:00
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
actions := eventActionsByIDAndType(c, events, name, "container")
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2015-12-21 17:55:23 -05:00
|
|
|
c.Assert(actions[len(actions)-2], checker.Equals, "pause")
|
|
|
|
c.Assert(actions[len(actions)-1], checker.Equals, "unpause")
|
2015-01-30 19:23:47 -05:00
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
|
2016-09-08 20:31:04 -04:00
|
|
|
testRequires(c, IsPausable)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
|
|
|
containers := []string{
|
|
|
|
"testpausewithmorecontainers1",
|
|
|
|
"testpausewithmorecontainers2",
|
|
|
|
}
|
|
|
|
for _, name := range containers {
|
2016-09-08 20:31:04 -04:00
|
|
|
runSleepingContainer(c, "-d", "--name", name)
|
2015-01-30 19:23:47 -05:00
|
|
|
}
|
2017-04-11 13:42:54 -04:00
|
|
|
cli.DockerCmd(c, append([]string{"pause"}, containers...)...)
|
|
|
|
pausedContainers := strings.Fields(
|
|
|
|
cli.DockerCmd(c, "ps", "-f", "status=paused", "-q", "-a").Combined(),
|
|
|
|
)
|
2015-10-14 12:09:33 -04:00
|
|
|
c.Assert(len(pausedContainers), checker.Equals, len(containers))
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2017-04-11 13:42:54 -04:00
|
|
|
cli.DockerCmd(c, append([]string{"unpause"}, containers...)...)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2017-04-11 13:42:54 -04:00
|
|
|
out := cli.DockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c)).Combined()
|
2015-12-21 17:55:23 -05:00
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2015-12-21 17:55:23 -05:00
|
|
|
for _, name := range containers {
|
|
|
|
actions := eventActionsByIDAndType(c, events, name, "container")
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2015-12-21 17:55:23 -05:00
|
|
|
c.Assert(actions[len(actions)-2], checker.Equals, "pause")
|
|
|
|
c.Assert(actions[len(actions)-1], checker.Equals, "unpause")
|
2015-01-30 19:23:47 -05:00
|
|
|
}
|
|
|
|
}
|
2016-01-08 16:49:43 -05:00
|
|
|
|
2016-09-08 20:31:04 -04:00
|
|
|
func (s *DockerSuite) TestPauseFailsOnWindowsServerContainers(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsWindows, NotPausable)
|
|
|
|
runSleepingContainer(c, "-d", "--name=test")
|
2016-01-08 16:49:43 -05:00
|
|
|
out, _, _ := dockerCmdWithError("pause", "test")
|
2016-09-08 20:31:04 -04:00
|
|
|
c.Assert(out, checker.Contains, "cannot pause Windows Server Containers")
|
2016-01-08 16:49:43 -05:00
|
|
|
}
|