2015-01-30 19:23:47 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2015-10-14 12:09:33 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
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) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-01-30 19:23:47 -05:00
|
|
|
defer unpauseAllContainers()
|
|
|
|
|
|
|
|
name := "testeventpause"
|
2015-08-05 20:35:20 -04:00
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, "pause", name)
|
2015-01-30 19:23:47 -05:00
|
|
|
pausedContainers, err := getSliceOfPausedContainers()
|
2015-10-14 12:09:33 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(len(pausedContainers), checker.Equals, 1)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, "unpause", name)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2015-08-05 20:35:20 -04:00
|
|
|
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
2015-01-30 19:23:47 -05:00
|
|
|
events := strings.Split(out, "\n")
|
2015-10-14 12:09:33 -04:00
|
|
|
c.Assert(len(events) > 1, checker.Equals, true)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
|
|
|
pauseEvent := strings.Fields(events[len(events)-3])
|
|
|
|
unpauseEvent := strings.Fields(events[len(events)-2])
|
|
|
|
|
2015-10-14 12:09:33 -04:00
|
|
|
c.Assert(pauseEvent[len(pauseEvent)-1], checker.Equals, "pause")
|
|
|
|
c.Assert(unpauseEvent[len(unpauseEvent)-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) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-01-30 19:23:47 -05:00
|
|
|
defer unpauseAllContainers()
|
|
|
|
|
|
|
|
containers := []string{
|
|
|
|
"testpausewithmorecontainers1",
|
|
|
|
"testpausewithmorecontainers2",
|
|
|
|
}
|
|
|
|
for _, name := range containers {
|
2015-08-05 20:35:20 -04:00
|
|
|
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
|
2015-01-30 19:23:47 -05:00
|
|
|
}
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, append([]string{"pause"}, containers...)...)
|
2015-01-30 19:23:47 -05:00
|
|
|
pausedContainers, err := getSliceOfPausedContainers()
|
2015-10-14 12:09:33 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(len(pausedContainers), checker.Equals, len(containers))
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, append([]string{"unpause"}, containers...)...)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
2015-08-05 20:35:20 -04:00
|
|
|
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
2015-01-30 19:23:47 -05:00
|
|
|
events := strings.Split(out, "\n")
|
2015-10-14 12:09:33 -04:00
|
|
|
c.Assert(len(events) > len(containers)*3-2, checker.Equals, true)
|
2015-01-30 19:23:47 -05:00
|
|
|
|
|
|
|
pauseEvents := make([][]string, len(containers))
|
|
|
|
unpauseEvents := make([][]string, len(containers))
|
|
|
|
for i := range containers {
|
|
|
|
pauseEvents[i] = strings.Fields(events[len(events)-len(containers)*2-1+i])
|
|
|
|
unpauseEvents[i] = strings.Fields(events[len(events)-len(containers)-1+i])
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pauseEvent := range pauseEvents {
|
2015-10-14 12:09:33 -04:00
|
|
|
c.Assert(pauseEvent[len(pauseEvent)-1], checker.Equals, "pause")
|
2015-01-30 19:23:47 -05:00
|
|
|
}
|
|
|
|
for _, unpauseEvent := range unpauseEvents {
|
2015-10-14 12:09:33 -04:00
|
|
|
c.Assert(unpauseEvent[len(unpauseEvent)-1], checker.Equals, "unpause")
|
2015-01-30 19:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|