2014-06-05 14:32:19 +04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-04-05 16:01:52 +03:00
|
|
|
"bufio"
|
2014-07-07 19:47:06 +04:00
|
|
|
"fmt"
|
2015-05-14 23:44:29 +03:00
|
|
|
"io/ioutil"
|
2015-05-24 21:19:39 +03:00
|
|
|
"net/http"
|
2015-05-14 23:44:29 +03:00
|
|
|
"os"
|
2014-06-05 14:32:19 +04:00
|
|
|
"os/exec"
|
2015-02-25 03:24:19 +03:00
|
|
|
"regexp"
|
2014-07-04 09:12:21 +04:00
|
|
|
"strconv"
|
2014-06-05 14:32:19 +04:00
|
|
|
"strings"
|
2015-04-27 22:12:23 +03:00
|
|
|
"sync"
|
2014-07-07 19:47:06 +04:00
|
|
|
"time"
|
2015-04-18 19:46:47 +03:00
|
|
|
|
2015-09-23 21:51:43 +03:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-18 19:46:47 +03:00
|
|
|
"github.com/go-check/check"
|
2014-06-05 14:32:19 +04:00
|
|
|
)
|
|
|
|
|
2015-05-13 19:27:00 +03:00
|
|
|
func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-13 19:27:00 +03:00
|
|
|
image := "busybox"
|
|
|
|
|
|
|
|
// Start stopwatch, generate an event
|
2015-08-11 10:41:11 +03:00
|
|
|
time.Sleep(1 * time.Second) // so that we don't grab events from previous test occured in the same second
|
2015-05-13 19:27:00 +03:00
|
|
|
start := daemonTime(c)
|
|
|
|
dockerCmd(c, "tag", image, "timestamptest:1")
|
|
|
|
dockerCmd(c, "rmi", "timestamptest:1")
|
2015-08-11 10:41:11 +03:00
|
|
|
time.Sleep(1 * time.Second) // so that until > since
|
2015-05-13 19:27:00 +03:00
|
|
|
end := daemonTime(c)
|
|
|
|
|
|
|
|
// List of available time formats to --since
|
|
|
|
unixTs := func(t time.Time) string { return fmt.Sprintf("%v", t.Unix()) }
|
|
|
|
rfc3339 := func(t time.Time) string { return t.Format(time.RFC3339) }
|
2015-05-12 22:59:34 +03:00
|
|
|
duration := func(t time.Time) string { return time.Now().Sub(t).String() }
|
2015-05-13 19:27:00 +03:00
|
|
|
|
|
|
|
// --since=$start must contain only the 'untag' event
|
2015-05-12 22:59:34 +03:00
|
|
|
for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} {
|
2015-05-13 19:27:00 +03:00
|
|
|
since, until := f(start), f(end)
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events", "--since="+since, "--until="+until)
|
2015-05-13 19:27:00 +03:00
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
2015-05-15 03:01:06 +03:00
|
|
|
if len(events) != 2 {
|
|
|
|
c.Fatalf("unexpected events, was expecting only 2 events tag/untag (since=%s, until=%s) out=%s", since, until, out)
|
2015-05-13 19:27:00 +03:00
|
|
|
}
|
|
|
|
if !strings.Contains(out, "untag") {
|
|
|
|
c.Fatalf("expected 'untag' event not found (since=%s, until=%s) out=%s", since, until, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsUntag(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-10-24 01:30:11 +04:00
|
|
|
image := "busybox"
|
2015-04-18 19:46:47 +03:00
|
|
|
dockerCmd(c, "tag", image, "utest:tag1")
|
|
|
|
dockerCmd(c, "tag", image, "utest:tag2")
|
|
|
|
dockerCmd(c, "rmi", "utest:tag1")
|
|
|
|
dockerCmd(c, "rmi", "utest:tag2")
|
2015-02-14 12:19:57 +03:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", "--since=1")
|
|
|
|
out, exitCode, _, err := runCommandWithOutputForDuration(eventsCmd, time.Duration(time.Millisecond*200))
|
|
|
|
if exitCode != 0 || err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Failed to get events - exit code %d: %s", exitCode, err)
|
2015-02-14 12:19:57 +03:00
|
|
|
}
|
2014-06-05 14:32:19 +04:00
|
|
|
events := strings.Split(out, "\n")
|
2014-10-06 18:26:55 +04:00
|
|
|
nEvents := len(events)
|
2014-06-05 14:32:19 +04:00
|
|
|
// The last element after the split above will be an empty string, so we
|
|
|
|
// get the two elements before the last, which are the untags we're
|
|
|
|
// looking for.
|
2014-10-06 18:26:55 +04:00
|
|
|
for _, v := range events[nEvents-3 : nEvents-1] {
|
2014-06-05 14:32:19 +04:00
|
|
|
if !strings.Contains(v, "untag") {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be untag, not %#v", v)
|
2014-06-05 14:32:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-07 19:47:06 +04:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsContainerFailStartDie(c *check.C) {
|
2014-11-17 19:05:49 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
out, _ := dockerCmd(c, "images", "-q")
|
2014-09-20 00:54:32 +04:00
|
|
|
image := strings.Split(out, "\n")[0]
|
2015-07-27 21:13:25 +03:00
|
|
|
if _, _, err := dockerCmdWithError("run", "--name", "testeventdie", image, "blerg"); err == nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Container run with command blerg should have failed, but it did not")
|
2014-09-20 00:54:32 +04:00
|
|
|
}
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
2014-09-20 00:54:32 +04:00
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
if len(events) <= 1 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Missing expected event")
|
2014-09-20 00:54:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
startEvent := strings.Fields(events[len(events)-3])
|
|
|
|
dieEvent := strings.Fields(events[len(events)-2])
|
|
|
|
|
|
|
|
if startEvent[len(startEvent)-1] != "start" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be start, not %#v", startEvent)
|
2014-09-20 00:54:32 +04:00
|
|
|
}
|
|
|
|
if dieEvent[len(dieEvent)-1] != "die" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be die, not %#v", dieEvent)
|
2014-09-20 00:54:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsLimit(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-27 22:12:23 +03:00
|
|
|
var waitGroup sync.WaitGroup
|
|
|
|
errChan := make(chan error, 17)
|
|
|
|
|
|
|
|
args := []string{"run", "--rm", "busybox", "true"}
|
|
|
|
for i := 0; i < 17; i++ {
|
|
|
|
waitGroup.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer waitGroup.Done()
|
2015-04-27 20:29:48 +03:00
|
|
|
errChan <- exec.Command(dockerBinary, args...).Run()
|
2015-04-27 22:12:23 +03:00
|
|
|
}()
|
2014-07-04 09:12:21 +04:00
|
|
|
}
|
2015-04-27 22:12:23 +03:00
|
|
|
|
|
|
|
waitGroup.Wait()
|
|
|
|
close(errChan)
|
|
|
|
|
|
|
|
for err := range errChan {
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("%q failed with error: %v", strings.Join(args, " "), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
2014-07-04 09:12:21 +04:00
|
|
|
events := strings.Split(out, "\n")
|
2014-10-06 18:26:55 +04:00
|
|
|
nEvents := len(events) - 1
|
|
|
|
if nEvents != 64 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("events should be limited to 64, but received %d", nEvents)
|
2014-07-04 09:12:21 +04:00
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:54:59 +04:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsContainerEvents(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-18 19:46:47 +03:00
|
|
|
dockerCmd(c, "run", "--rm", "busybox", "true")
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
2014-08-11 09:54:59 +04:00
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
events = events[:len(events)-1]
|
2015-05-24 21:19:39 +03:00
|
|
|
if len(events) < 5 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Missing expected event")
|
2014-08-11 09:54:59 +04:00
|
|
|
}
|
2015-05-24 21:19:39 +03:00
|
|
|
createEvent := strings.Fields(events[len(events)-5])
|
|
|
|
attachEvent := strings.Fields(events[len(events)-4])
|
2014-08-11 09:54:59 +04:00
|
|
|
startEvent := strings.Fields(events[len(events)-3])
|
|
|
|
dieEvent := strings.Fields(events[len(events)-2])
|
|
|
|
destroyEvent := strings.Fields(events[len(events)-1])
|
|
|
|
if createEvent[len(createEvent)-1] != "create" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be create, not %#v", createEvent)
|
2014-08-11 09:54:59 +04:00
|
|
|
}
|
2015-09-19 05:18:52 +03:00
|
|
|
if attachEvent[len(attachEvent)-1] != "attach" {
|
2015-05-24 21:19:39 +03:00
|
|
|
c.Fatalf("event should be attach, not %#v", attachEvent)
|
|
|
|
}
|
2014-08-11 09:54:59 +04:00
|
|
|
if startEvent[len(startEvent)-1] != "start" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be start, not %#v", startEvent)
|
2014-08-11 09:54:59 +04:00
|
|
|
}
|
|
|
|
if dieEvent[len(dieEvent)-1] != "die" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be die, not %#v", dieEvent)
|
2014-08-11 09:54:59 +04:00
|
|
|
}
|
|
|
|
if destroyEvent[len(destroyEvent)-1] != "destroy" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be destroy, not %#v", destroyEvent)
|
2014-08-11 09:54:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-08-11 11:39:47 +04:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-18 19:46:47 +03:00
|
|
|
dockerCmd(c, "run", "--rm", "busybox", "true")
|
2015-03-22 22:40:16 +03:00
|
|
|
timeBeginning := time.Unix(0, 0).Format(time.RFC3339Nano)
|
|
|
|
timeBeginning = strings.Replace(timeBeginning, "Z", ".000000000Z", -1)
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events", fmt.Sprintf("--since='%s'", timeBeginning),
|
2015-04-18 19:46:47 +03:00
|
|
|
fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
2015-03-22 22:40:16 +03:00
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
events = events[:len(events)-1]
|
2015-05-24 21:19:39 +03:00
|
|
|
if len(events) < 5 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Missing expected event")
|
2015-03-22 22:40:16 +03:00
|
|
|
}
|
2015-05-24 21:19:39 +03:00
|
|
|
createEvent := strings.Fields(events[len(events)-5])
|
|
|
|
attachEvent := strings.Fields(events[len(events)-4])
|
2015-03-22 22:40:16 +03:00
|
|
|
startEvent := strings.Fields(events[len(events)-3])
|
|
|
|
dieEvent := strings.Fields(events[len(events)-2])
|
|
|
|
destroyEvent := strings.Fields(events[len(events)-1])
|
|
|
|
if createEvent[len(createEvent)-1] != "create" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be create, not %#v", createEvent)
|
2015-03-22 22:40:16 +03:00
|
|
|
}
|
2015-05-24 21:19:39 +03:00
|
|
|
if attachEvent[len(attachEvent)-1] != "attach" {
|
|
|
|
c.Fatalf("event should be attach, not %#v", attachEvent)
|
|
|
|
}
|
2015-03-22 22:40:16 +03:00
|
|
|
if startEvent[len(startEvent)-1] != "start" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be start, not %#v", startEvent)
|
2015-03-22 22:40:16 +03:00
|
|
|
}
|
|
|
|
if dieEvent[len(dieEvent)-1] != "die" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be die, not %#v", dieEvent)
|
2015-03-22 22:40:16 +03:00
|
|
|
}
|
|
|
|
if destroyEvent[len(destroyEvent)-1] != "destroy" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should be destroy, not %#v", destroyEvent)
|
2015-03-22 22:40:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-08-11 11:39:47 +04:00
|
|
|
name := "testimageevents"
|
|
|
|
_, err := buildImage(name,
|
|
|
|
`FROM scratch
|
|
|
|
MAINTAINER "docker"`,
|
|
|
|
true)
|
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2014-08-11 11:39:47 +04:00
|
|
|
}
|
|
|
|
if err := deleteImages(name); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2014-08-11 11:39:47 +04:00
|
|
|
}
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
2014-08-11 11:39:47 +04:00
|
|
|
events := strings.Split(out, "\n")
|
2015-02-20 00:33:23 +03:00
|
|
|
|
2014-08-11 11:39:47 +04:00
|
|
|
events = events[:len(events)-1]
|
|
|
|
if len(events) < 2 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Missing expected event")
|
2014-08-11 11:39:47 +04:00
|
|
|
}
|
|
|
|
untagEvent := strings.Fields(events[len(events)-2])
|
|
|
|
deleteEvent := strings.Fields(events[len(events)-1])
|
|
|
|
if untagEvent[len(untagEvent)-1] != "untag" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("untag should be untag, not %#v", untagEvent)
|
2014-08-11 11:39:47 +04:00
|
|
|
}
|
|
|
|
if deleteEvent[len(deleteEvent)-1] != "delete" {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("delete should be delete, not %#v", deleteEvent)
|
2014-08-11 11:39:47 +04:00
|
|
|
}
|
|
|
|
}
|
2014-09-25 18:50:10 +04:00
|
|
|
|
2015-05-15 03:01:06 +03:00
|
|
|
func (s *DockerSuite) TestEventsImageTag(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-08-11 10:41:11 +03:00
|
|
|
time.Sleep(1 * time.Second) // because API has seconds granularity
|
2015-05-15 03:01:06 +03:00
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
image := "testimageevents:tag"
|
|
|
|
dockerCmd(c, "tag", "busybox", image)
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events",
|
2015-05-15 03:01:06 +03:00
|
|
|
fmt.Sprintf("--since=%d", since),
|
|
|
|
fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
|
|
|
|
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
if len(events) != 1 {
|
|
|
|
c.Fatalf("was expecting 1 event. out=%s", out)
|
|
|
|
}
|
|
|
|
event := strings.TrimSpace(events[0])
|
|
|
|
expectedStr := image + ": tag"
|
|
|
|
|
|
|
|
if !strings.HasSuffix(event, expectedStr) {
|
|
|
|
c.Fatalf("wrong event format. expected='%s' got=%s", expectedStr, event)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsImagePull(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-18 19:46:47 +03:00
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
testRequires(c, Network)
|
2015-02-06 04:46:55 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "pull", "hello-world")
|
2014-10-22 17:48:02 +04:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events",
|
2014-10-22 17:48:02 +04:00
|
|
|
fmt.Sprintf("--since=%d", since),
|
2015-04-18 19:46:47 +03:00
|
|
|
fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
2014-10-22 17:48:02 +04:00
|
|
|
|
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
event := strings.TrimSpace(events[len(events)-1])
|
|
|
|
|
2014-10-29 00:06:23 +03:00
|
|
|
if !strings.HasSuffix(event, "hello-world:latest: pull") {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Missing pull event - got:%q", event)
|
2014-10-22 17:48:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsImageImport(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-18 19:46:47 +03:00
|
|
|
since := daemonTime(c).Unix()
|
2014-10-22 17:48:02 +04:00
|
|
|
|
2015-04-18 15:58:57 +03:00
|
|
|
id := make(chan string)
|
|
|
|
eventImport := make(chan struct{})
|
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", "--since", strconv.FormatInt(since, 10))
|
|
|
|
stdout, err := eventsCmd.StdoutPipe()
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
2015-04-27 20:29:48 +03:00
|
|
|
if err := eventsCmd.Start(); err != nil {
|
2015-04-18 15:58:57 +03:00
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
defer eventsCmd.Process.Kill()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
containerID := <-id
|
|
|
|
|
|
|
|
matchImport := regexp.MustCompile(containerID + `: import$`)
|
|
|
|
scanner := bufio.NewScanner(stdout)
|
|
|
|
for scanner.Scan() {
|
|
|
|
if matchImport.MatchString(scanner.Text()) {
|
|
|
|
close(eventImport)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
2015-04-06 16:21:18 +03:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2015-02-14 13:27:06 +03:00
|
|
|
|
|
|
|
out, _, err = runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "export", cleanedContainerID),
|
|
|
|
exec.Command(dockerBinary, "import", "-"),
|
|
|
|
)
|
2014-10-22 17:48:02 +04:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Errorf("import failed with errors: %v, output: %q", err, out)
|
2014-10-22 17:48:02 +04:00
|
|
|
}
|
2015-04-18 15:58:57 +03:00
|
|
|
newContainerID := strings.TrimSpace(out)
|
|
|
|
id <- newContainerID
|
2014-10-22 17:48:02 +04:00
|
|
|
|
2015-04-18 15:58:57 +03:00
|
|
|
select {
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
c.Fatal("failed to observe image import in timely fashion")
|
|
|
|
case <-eventImport:
|
|
|
|
// ignore, done
|
2014-10-22 17:48:02 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-20 22:46:48 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsFilters(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-02-25 03:24:19 +03:00
|
|
|
parseEvents := func(out, match string) {
|
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
events = events[:len(events)-1]
|
|
|
|
for _, event := range events {
|
|
|
|
eventFields := strings.Fields(event)
|
|
|
|
eventName := eventFields[len(eventFields)-1]
|
|
|
|
if ok, err := regexp.MatchString(match, eventName); err != nil || !ok {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("event should match %s, got %#v, err: %v", match, eventFields, err)
|
2015-02-25 03:24:19 +03:00
|
|
|
}
|
|
|
|
}
|
2015-02-20 00:33:23 +03:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
since := daemonTime(c).Unix()
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "run", "--rm", "busybox", "true")
|
|
|
|
dockerCmd(c, "run", "--rm", "busybox", "true")
|
|
|
|
out, _ := dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", "event=die")
|
2015-02-25 03:24:19 +03:00
|
|
|
parseEvents(out, "die")
|
2014-11-20 22:46:48 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", "event=die", "--filter", "event=start")
|
2015-02-25 03:24:19 +03:00
|
|
|
parseEvents(out, "((die)|(start))")
|
|
|
|
|
|
|
|
// make sure we at least got 2 start events
|
|
|
|
count := strings.Count(out, "start")
|
2015-02-28 01:48:39 +03:00
|
|
|
if count < 2 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("should have had 2 start events but had %d, out: %s", count, out)
|
2014-11-20 22:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-02-10 00:02:53 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsFilterImageName(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-18 19:46:47 +03:00
|
|
|
since := daemonTime(c).Unix()
|
2015-02-10 00:02:53 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true")
|
2015-04-06 16:21:18 +03:00
|
|
|
container1 := strings.TrimSpace(out)
|
2015-02-09 09:03:42 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "run", "--name", "container_2", "-d", "busybox", "true")
|
2015-04-06 16:21:18 +03:00
|
|
|
container2 := strings.TrimSpace(out)
|
2015-02-10 00:02:53 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
name := "busybox"
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", fmt.Sprintf("image=%s", name))
|
2015-04-01 17:08:00 +03:00
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
events = events[:len(events)-1]
|
|
|
|
if len(events) == 0 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected events but found none for the image busybox:latest")
|
2015-04-01 17:08:00 +03:00
|
|
|
}
|
|
|
|
count1 := 0
|
|
|
|
count2 := 0
|
|
|
|
|
|
|
|
for _, e := range events {
|
|
|
|
if strings.Contains(e, container1) {
|
|
|
|
count1++
|
|
|
|
} else if strings.Contains(e, container2) {
|
|
|
|
count2++
|
2015-02-10 00:02:53 +03:00
|
|
|
}
|
|
|
|
}
|
2015-04-01 17:08:00 +03:00
|
|
|
if count1 == 0 || count2 == 0 {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatalf("Expected events from each container but got %d from %s and %d from %s", count1, container1, count2, container2)
|
2015-04-01 17:08:00 +03:00
|
|
|
}
|
2015-02-10 00:02:53 +03:00
|
|
|
|
2015-02-09 09:03:42 +03:00
|
|
|
}
|
|
|
|
|
2015-09-23 21:51:43 +03:00
|
|
|
func (s *DockerSuite) TestEventsFilterLabels(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
label := "io.docker.testing=foo"
|
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "run", "-d", "-l", label, "busybox:latest", "true")
|
|
|
|
container1 := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "run", "-d", "busybox", "true")
|
|
|
|
container2 := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(
|
|
|
|
c,
|
|
|
|
"events",
|
|
|
|
fmt.Sprintf("--since=%d", since),
|
|
|
|
fmt.Sprintf("--until=%d", daemonTime(c).Unix()),
|
|
|
|
"--filter", fmt.Sprintf("label=%s", label))
|
|
|
|
|
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(events), checker.Equals, 3)
|
|
|
|
|
|
|
|
for _, e := range events {
|
|
|
|
c.Assert(e, checker.Contains, container1)
|
|
|
|
c.Assert(e, check.Not(checker.Contains), container2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
since := daemonTime(c).Unix()
|
2015-10-16 18:54:05 +03:00
|
|
|
name := "labelfiltertest"
|
2015-09-23 21:51:43 +03:00
|
|
|
label := "io.docker.testing=image"
|
|
|
|
|
|
|
|
// Build a test image.
|
2015-10-16 18:54:05 +03:00
|
|
|
_, err := buildImage(name, fmt.Sprintf(`
|
2015-09-23 21:51:43 +03:00
|
|
|
FROM busybox:latest
|
2015-10-16 18:54:05 +03:00
|
|
|
LABEL %s`, label), true)
|
2015-09-23 21:51:43 +03:00
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Couldn't create image: %q", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
dockerCmd(c, "tag", name, "labelfiltertest:tag1")
|
|
|
|
dockerCmd(c, "tag", name, "labelfiltertest:tag2")
|
|
|
|
dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3")
|
|
|
|
|
|
|
|
out, _ := dockerCmd(
|
|
|
|
c,
|
|
|
|
"events",
|
|
|
|
fmt.Sprintf("--since=%d", since),
|
|
|
|
fmt.Sprintf("--until=%d", daemonTime(c).Unix()),
|
|
|
|
"--filter", fmt.Sprintf("label=%s", label))
|
|
|
|
|
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
2015-10-16 18:54:05 +03:00
|
|
|
|
|
|
|
// 2 events from the "docker tag" command, another one is from "docker build"
|
|
|
|
c.Assert(len(events), checker.Equals, 3, check.Commentf("Events == %s", events))
|
2015-09-23 21:51:43 +03:00
|
|
|
for _, e := range events {
|
|
|
|
c.Assert(e, checker.Contains, "labelfiltertest")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-18 19:46:47 +03:00
|
|
|
since := fmt.Sprintf("%d", daemonTime(c).Unix())
|
2015-04-06 20:18:38 +03:00
|
|
|
nameID := make(map[string]string)
|
2015-02-09 09:03:42 +03:00
|
|
|
|
2015-04-06 20:18:38 +03:00
|
|
|
for _, name := range []string{"container_1", "container_2"} {
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "run", "--name", name, "busybox", "true")
|
2015-04-23 21:43:08 +03:00
|
|
|
id, err := inspectField(name, "Id")
|
2015-02-09 09:03:42 +03:00
|
|
|
if err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2015-02-09 09:03:42 +03:00
|
|
|
}
|
2015-04-23 21:43:08 +03:00
|
|
|
nameID[name] = id
|
2015-02-09 09:03:42 +03:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
until := fmt.Sprintf("%d", daemonTime(c).Unix())
|
2015-02-09 09:03:42 +03:00
|
|
|
|
2015-04-06 20:18:38 +03:00
|
|
|
checkEvents := func(id string, events []string) error {
|
2015-05-24 21:19:39 +03:00
|
|
|
if len(events) != 4 { // create, attach, start, die
|
2015-09-23 21:51:43 +03:00
|
|
|
return fmt.Errorf("expected 4 events, got %v", events)
|
2015-04-06 20:18:38 +03:00
|
|
|
}
|
|
|
|
for _, event := range events {
|
|
|
|
e := strings.Fields(event)
|
|
|
|
if len(e) < 3 {
|
|
|
|
return fmt.Errorf("got malformed event: %s", event)
|
|
|
|
}
|
2015-02-09 09:03:42 +03:00
|
|
|
|
2015-04-06 20:18:38 +03:00
|
|
|
// Check the id
|
2015-09-29 20:51:40 +03:00
|
|
|
parsedID := strings.TrimSuffix(e[1], ":")
|
2015-04-06 20:18:38 +03:00
|
|
|
if parsedID != id {
|
|
|
|
return fmt.Errorf("expected event for container id %s: %s - parsed container id: %s", id, event, parsedID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2015-02-09 09:03:42 +03:00
|
|
|
}
|
|
|
|
|
2015-04-06 20:18:38 +03:00
|
|
|
for name, ID := range nameID {
|
|
|
|
// filter by names
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+name)
|
2015-04-06 20:18:38 +03:00
|
|
|
events := strings.Split(strings.TrimSuffix(out, "\n"), "\n")
|
|
|
|
if err := checkEvents(ID, events); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2015-03-31 06:26:27 +03:00
|
|
|
}
|
|
|
|
|
2015-04-06 20:18:38 +03:00
|
|
|
// filter by ID's
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+ID)
|
2015-04-06 20:18:38 +03:00
|
|
|
events = strings.Split(strings.TrimSuffix(out, "\n"), "\n")
|
|
|
|
if err := checkEvents(ID, events); err != nil {
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal(err)
|
2015-04-06 20:18:38 +03:00
|
|
|
}
|
2015-03-26 22:43:00 +03:00
|
|
|
}
|
|
|
|
}
|
2015-04-05 16:01:52 +03:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestEventsStreaming(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-18 19:46:47 +03:00
|
|
|
start := daemonTime(c).Unix()
|
2015-04-05 16:01:52 +03:00
|
|
|
|
|
|
|
id := make(chan string)
|
|
|
|
eventCreate := make(chan struct{})
|
|
|
|
eventStart := make(chan struct{})
|
|
|
|
eventDie := make(chan struct{})
|
|
|
|
eventDestroy := make(chan struct{})
|
|
|
|
|
2015-04-27 20:29:48 +03:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", "--since", strconv.FormatInt(start, 10))
|
|
|
|
stdout, err := eventsCmd.StdoutPipe()
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := eventsCmd.Start(); err != nil {
|
|
|
|
c.Fatalf("failed to start 'docker events': %s", err)
|
|
|
|
}
|
|
|
|
defer eventsCmd.Process.Kill()
|
2015-04-05 16:01:52 +03:00
|
|
|
|
2015-04-27 20:29:48 +03:00
|
|
|
go func() {
|
2015-04-05 16:01:52 +03:00
|
|
|
containerID := <-id
|
|
|
|
|
|
|
|
matchCreate := regexp.MustCompile(containerID + `: \(from busybox:latest\) create$`)
|
|
|
|
matchStart := regexp.MustCompile(containerID + `: \(from busybox:latest\) start$`)
|
|
|
|
matchDie := regexp.MustCompile(containerID + `: \(from busybox:latest\) die$`)
|
|
|
|
matchDestroy := regexp.MustCompile(containerID + `: \(from busybox:latest\) destroy$`)
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(stdout)
|
|
|
|
for scanner.Scan() {
|
|
|
|
switch {
|
|
|
|
case matchCreate.MatchString(scanner.Text()):
|
|
|
|
close(eventCreate)
|
|
|
|
case matchStart.MatchString(scanner.Text()):
|
|
|
|
close(eventStart)
|
|
|
|
case matchDie.MatchString(scanner.Text()):
|
|
|
|
close(eventDie)
|
|
|
|
case matchDestroy.MatchString(scanner.Text()):
|
|
|
|
close(eventDestroy)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox:latest", "true")
|
2015-04-05 16:01:52 +03:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
id <- cleanedContainerID
|
|
|
|
|
|
|
|
select {
|
2015-04-06 23:40:56 +03:00
|
|
|
case <-time.After(5 * time.Second):
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal("failed to observe container create in timely fashion")
|
2015-04-05 16:01:52 +03:00
|
|
|
case <-eventCreate:
|
|
|
|
// ignore, done
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
2015-04-06 23:40:56 +03:00
|
|
|
case <-time.After(5 * time.Second):
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal("failed to observe container start in timely fashion")
|
2015-04-05 16:01:52 +03:00
|
|
|
case <-eventStart:
|
|
|
|
// ignore, done
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
2015-04-06 23:40:56 +03:00
|
|
|
case <-time.After(5 * time.Second):
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal("failed to observe container die in timely fashion")
|
2015-04-05 16:01:52 +03:00
|
|
|
case <-eventDie:
|
|
|
|
// ignore, done
|
|
|
|
}
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "rm", cleanedContainerID)
|
2015-04-05 16:01:52 +03:00
|
|
|
|
|
|
|
select {
|
2015-04-06 23:40:56 +03:00
|
|
|
case <-time.After(5 * time.Second):
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal("failed to observe container destroy in timely fashion")
|
2015-04-05 16:01:52 +03:00
|
|
|
case <-eventDestroy:
|
|
|
|
// ignore, done
|
|
|
|
}
|
|
|
|
}
|
2015-05-24 21:19:39 +03:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestEventsCommit(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-24 21:19:39 +03:00
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
2015-05-24 21:19:39 +03:00
|
|
|
cID := strings.TrimSpace(out)
|
|
|
|
c.Assert(waitRun(cID), check.IsNil)
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "commit", "-m", "test", cID)
|
|
|
|
dockerCmd(c, "stop", cID)
|
2015-05-24 21:19:39 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
|
2015-05-24 21:19:39 +03:00
|
|
|
if !strings.Contains(out, " commit\n") {
|
|
|
|
c.Fatalf("Missing 'commit' log event\n%s", out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestEventsCopy(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-24 21:19:39 +03:00
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
|
2015-05-14 23:44:29 +03:00
|
|
|
// Build a test image.
|
2015-05-24 21:19:39 +03:00
|
|
|
id, err := buildImage("cpimg", `
|
|
|
|
FROM busybox
|
|
|
|
RUN echo HI > /tmp/file`, true)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Couldn't create image: %q", err)
|
|
|
|
}
|
|
|
|
|
2015-05-14 23:44:29 +03:00
|
|
|
// Create an empty test file.
|
|
|
|
tempFile, err := ioutil.TempFile("", "test-events-copy-")
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.Remove(tempFile.Name())
|
|
|
|
|
|
|
|
if err := tempFile.Close(); err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
dockerCmd(c, "create", "--name=cptest", id)
|
|
|
|
|
|
|
|
dockerCmd(c, "cp", "cptest:/tmp/file", tempFile.Name())
|
2015-05-24 21:19:39 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since)))
|
2015-05-14 23:44:29 +03:00
|
|
|
if !strings.Contains(out, " archive-path\n") {
|
|
|
|
c.Fatalf("Missing 'archive-path' log event\n%s", out)
|
|
|
|
}
|
|
|
|
|
|
|
|
dockerCmd(c, "cp", tempFile.Name(), "cptest:/tmp/filecopy")
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since)))
|
|
|
|
if !strings.Contains(out, " extract-to-dir\n") {
|
|
|
|
c.Fatalf("Missing 'extract-to-dir' log event\n%s", out)
|
2015-05-24 21:19:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestEventsResize(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-24 21:19:39 +03:00
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
2015-05-24 21:19:39 +03:00
|
|
|
cID := strings.TrimSpace(out)
|
|
|
|
c.Assert(waitRun(cID), check.IsNil)
|
|
|
|
|
|
|
|
endpoint := "/containers/" + cID + "/resize?h=80&w=24"
|
|
|
|
status, _, err := sockRequest("POST", endpoint, nil)
|
|
|
|
c.Assert(status, check.Equals, http.StatusOK)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "stop", cID)
|
2015-05-24 21:19:39 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
|
2015-05-24 21:19:39 +03:00
|
|
|
if !strings.Contains(out, " resize\n") {
|
|
|
|
c.Fatalf("Missing 'resize' log event\n%s", out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestEventsAttach(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-24 21:19:39 +03:00
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
|
|
|
|
out, _ := dockerCmd(c, "run", "-di", "busybox", "/bin/cat")
|
|
|
|
cID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
cmd := exec.Command(dockerBinary, "attach", cID)
|
|
|
|
stdin, err := cmd.StdinPipe()
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
defer stdin.Close()
|
|
|
|
stdout, err := cmd.StdoutPipe()
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
defer stdout.Close()
|
|
|
|
c.Assert(cmd.Start(), check.IsNil)
|
|
|
|
defer cmd.Process.Kill()
|
|
|
|
|
|
|
|
// Make sure we're done attaching by writing/reading some stuff
|
|
|
|
if _, err := stdin.Write([]byte("hello\n")); err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
out, err = bufio.NewReader(stdout).ReadString('\n')
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
if strings.TrimSpace(out) != "hello" {
|
|
|
|
c.Fatalf("expected 'hello', got %q", out)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Assert(stdin.Close(), check.IsNil)
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "stop", cID)
|
2015-05-24 21:19:39 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
|
2015-05-24 21:19:39 +03:00
|
|
|
if !strings.Contains(out, " attach\n") {
|
|
|
|
c.Fatalf("Missing 'attach' log event\n%s", out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestEventsRename(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-24 21:19:39 +03:00
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "run", "--name", "oldName", "busybox", "true")
|
|
|
|
dockerCmd(c, "rename", "oldName", "newName")
|
2015-05-24 21:19:39 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=newName", "--until="+strconv.Itoa(int(since)))
|
2015-05-24 21:19:39 +03:00
|
|
|
if !strings.Contains(out, " rename\n") {
|
|
|
|
c.Fatalf("Missing 'rename' log event\n%s", out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestEventsTop(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-24 21:19:39 +03:00
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
2015-05-24 21:19:39 +03:00
|
|
|
cID := strings.TrimSpace(out)
|
|
|
|
c.Assert(waitRun(cID), check.IsNil)
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
dockerCmd(c, "top", cID)
|
|
|
|
dockerCmd(c, "stop", cID)
|
2015-05-24 21:19:39 +03:00
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
|
2015-05-24 21:19:39 +03:00
|
|
|
if !strings.Contains(out, " top\n") {
|
|
|
|
c.Fatalf("Missing 'top' log event\n%s", out)
|
|
|
|
}
|
|
|
|
}
|
2015-06-05 05:47:46 +03:00
|
|
|
|
|
|
|
// #13753
|
|
|
|
func (s *DockerSuite) TestEventsDefaultEmpty(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-07 06:27:00 +03:00
|
|
|
dockerCmd(c, "run", "busybox")
|
2015-06-05 05:47:46 +03:00
|
|
|
out, _ := dockerCmd(c, "events", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, "")
|
|
|
|
}
|
2015-07-04 00:26:49 +03:00
|
|
|
|
|
|
|
// #14316
|
|
|
|
func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-04 00:26:49 +03:00
|
|
|
testRequires(c, Network)
|
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/testf", privateRegistryURL)
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
2015-07-04 00:26:49 +03:00
|
|
|
cID := strings.TrimSpace(out)
|
|
|
|
c.Assert(waitRun(cID), check.IsNil)
|
|
|
|
|
|
|
|
dockerCmd(c, "commit", cID, repoName)
|
|
|
|
dockerCmd(c, "stop", cID)
|
|
|
|
dockerCmd(c, "push", repoName)
|
|
|
|
|
2015-07-20 09:55:40 +03:00
|
|
|
out, _ = dockerCmd(c, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since)))
|
2015-07-04 00:26:49 +03:00
|
|
|
if !strings.Contains(out, repoName+": push\n") {
|
|
|
|
c.Fatalf("Missing 'push' log event for image %s\n%s", repoName, out)
|
|
|
|
}
|
|
|
|
}
|