2015-01-31 00:23:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2015-10-14 16:09:33 +00:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2015-01-31 00:23:47 +00:00
|
|
|
)
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestPause(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-01-31 00:23:47 +00:00
|
|
|
defer unpauseAllContainers()
|
|
|
|
|
|
|
|
name := "testeventpause"
|
2015-08-06 00:35:20 +00:00
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
|
2015-01-31 00:23:47 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
dockerCmd(c, "pause", name)
|
2015-01-31 00:23:47 +00:00
|
|
|
pausedContainers, err := getSliceOfPausedContainers()
|
2015-10-14 16:09:33 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(len(pausedContainers), checker.Equals, 1)
|
2015-01-31 00:23:47 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
dockerCmd(c, "unpause", name)
|
2015-01-31 00:23:47 +00:00
|
|
|
|
2016-04-11 18:52:34 +00:00
|
|
|
out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c))
|
2015-12-21 22:55:23 +00:00
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
actions := eventActionsByIDAndType(c, events, name, "container")
|
2015-01-31 00:23:47 +00:00
|
|
|
|
2015-12-21 22:55:23 +00:00
|
|
|
c.Assert(actions[len(actions)-2], checker.Equals, "pause")
|
|
|
|
c.Assert(actions[len(actions)-1], checker.Equals, "unpause")
|
2015-01-31 00:23:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-01-31 00:23:47 +00:00
|
|
|
defer unpauseAllContainers()
|
|
|
|
|
|
|
|
containers := []string{
|
|
|
|
"testpausewithmorecontainers1",
|
|
|
|
"testpausewithmorecontainers2",
|
|
|
|
}
|
|
|
|
for _, name := range containers {
|
2015-08-06 00:35:20 +00:00
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
|
2015-01-31 00:23:47 +00:00
|
|
|
}
|
2015-04-18 16:46:47 +00:00
|
|
|
dockerCmd(c, append([]string{"pause"}, containers...)...)
|
2015-01-31 00:23:47 +00:00
|
|
|
pausedContainers, err := getSliceOfPausedContainers()
|
2015-10-14 16:09:33 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(len(pausedContainers), checker.Equals, len(containers))
|
2015-01-31 00:23:47 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
dockerCmd(c, append([]string{"unpause"}, containers...)...)
|
2015-01-31 00:23:47 +00:00
|
|
|
|
2016-04-11 18:52:34 +00:00
|
|
|
out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c))
|
2015-12-21 22:55:23 +00:00
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
2015-01-31 00:23:47 +00:00
|
|
|
|
2015-12-21 22:55:23 +00:00
|
|
|
for _, name := range containers {
|
|
|
|
actions := eventActionsByIDAndType(c, events, name, "container")
|
2015-01-31 00:23:47 +00:00
|
|
|
|
2015-12-21 22:55:23 +00:00
|
|
|
c.Assert(actions[len(actions)-2], checker.Equals, "pause")
|
|
|
|
c.Assert(actions[len(actions)-1], checker.Equals, "unpause")
|
2015-01-31 00:23:47 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-08 21:49:43 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestPauseFailsOnWindows(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsWindows)
|
|
|
|
dockerCmd(c, "run", "-d", "--name=test", "busybox", "sleep 3")
|
|
|
|
out, _, _ := dockerCmdWithError("pause", "test")
|
|
|
|
c.Assert(out, checker.Contains, "Windows: Containers cannot be paused")
|
|
|
|
}
|