Add volume events.
Signed-off-by: David Calavera <david.calavera@gmail.com> Upstream-commit: 9d12d093009d3c4bf3bd4ebad3f8327c36d2d584 Component: engine
This commit is contained in:
@@ -402,11 +402,6 @@ func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
|
||||
func (s *DockerSuite) TestEventsStreaming(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
eventCreate := make(chan struct{})
|
||||
eventStart := make(chan struct{})
|
||||
eventDie := make(chan struct{})
|
||||
eventDestroy := make(chan struct{})
|
||||
|
||||
observer, err := newEventObserver(c)
|
||||
c.Assert(err, checker.IsNil)
|
||||
err = observer.Start()
|
||||
@@ -415,42 +410,21 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
|
||||
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox:latest", "true")
|
||||
containerID := strings.TrimSpace(out)
|
||||
matchCreate := regexp.MustCompile(containerID + `: \(from busybox:latest\) create\z`)
|
||||
matchStart := regexp.MustCompile(containerID + `: \(from busybox:latest\) start\z`)
|
||||
matchDie := regexp.MustCompile(containerID + `: \(from busybox:latest\) die\z`)
|
||||
matchDestroy := regexp.MustCompile(containerID + `: \(from busybox:latest\) destroy\z`)
|
||||
|
||||
matcher := func(text string) {
|
||||
switch {
|
||||
case matchCreate.MatchString(text):
|
||||
close(eventCreate)
|
||||
case matchStart.MatchString(text):
|
||||
close(eventStart)
|
||||
case matchDie.MatchString(text):
|
||||
close(eventDie)
|
||||
case matchDestroy.MatchString(text):
|
||||
close(eventDestroy)
|
||||
}
|
||||
testActions := map[string]chan bool{
|
||||
"create": make(chan bool),
|
||||
"start": make(chan bool),
|
||||
"die": make(chan bool),
|
||||
"destroy": make(chan bool),
|
||||
}
|
||||
go observer.Match(matcher)
|
||||
|
||||
go observer.Match(matchEventLine(containerID, "container", testActions))
|
||||
|
||||
select {
|
||||
case <-time.After(5 * time.Second):
|
||||
c.Fatal(observer.TimeoutError(containerID, "create"))
|
||||
c.Fatal(observer.TimeoutError(containerID, "create/start/die"))
|
||||
case <-testActions["create"]:
|
||||
// ignore, done
|
||||
}
|
||||
|
||||
select {
|
||||
case <-time.After(5 * time.Second):
|
||||
c.Fatal(observer.TimeoutError(containerID, "start"))
|
||||
case <-testActions["start"]:
|
||||
// ignore, done
|
||||
}
|
||||
|
||||
select {
|
||||
case <-time.After(5 * time.Second):
|
||||
c.Fatal(observer.TimeoutError(containerID, "die"))
|
||||
case <-testActions["die"]:
|
||||
// ignore, done
|
||||
}
|
||||
@@ -460,7 +434,7 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
|
||||
select {
|
||||
case <-time.After(5 * time.Second):
|
||||
c.Fatal(observer.TimeoutError(containerID, "destroy"))
|
||||
case <-eventDestroy:
|
||||
case <-testActions["destroy"]:
|
||||
// ignore, done
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,3 +151,29 @@ func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *check.C) {
|
||||
<-ch
|
||||
c.Assert(out, checker.Contains, cID, check.Commentf("Missing event of container (foo)"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeEvents(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
since := daemonTime(c).Unix()
|
||||
|
||||
// Observe create/mount volume actions
|
||||
dockerCmd(c, "volume", "create", "--name", "test-event-volume-local")
|
||||
dockerCmd(c, "run", "--name", "test-volume-container", "--volume", "test-event-volume-local:/foo", "-d", "busybox", "true")
|
||||
waitRun("test-volume-container")
|
||||
|
||||
// Observe unmount/destroy volume actions
|
||||
dockerCmd(c, "rm", "-f", "test-volume-container")
|
||||
dockerCmd(c, "volume", "rm", "test-event-volume-local")
|
||||
|
||||
out, _ := dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(events), checker.GreaterThan, 4)
|
||||
|
||||
volumeEvents := eventActionsByIDAndType(c, events, "test-event-volume-local", "volume")
|
||||
c.Assert(volumeEvents, checker.HasLen, 4)
|
||||
c.Assert(volumeEvents[0], checker.Equals, "create")
|
||||
c.Assert(volumeEvents[1], checker.Equals, "mount")
|
||||
c.Assert(volumeEvents[2], checker.Equals, "unmount")
|
||||
c.Assert(volumeEvents[3], checker.Equals, "destroy")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user