mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add event logs for pause/unpuase
Fixes #6856 Docker-DCO-1.1-Signed-off-by: Brian Goff <cpuguy83@gmail.com> (github: cpuguy83)
This commit is contained in:
parent
cafb1bfd76
commit
e1ec91fc58
2 changed files with 31 additions and 1 deletions
|
@ -1,12 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCLIGetEvents(t *testing.T) {
|
||||
func TestCLIGetEventsUntag(t *testing.T) {
|
||||
out, _, _ := cmd(t, "images", "-q")
|
||||
image := strings.Split(out, "\n")[0]
|
||||
cmd(t, "tag", image, "utest:tag1")
|
||||
|
@ -27,3 +29,29 @@ func TestCLIGetEvents(t *testing.T) {
|
|||
}
|
||||
logDone("events - untags are logged")
|
||||
}
|
||||
|
||||
func TestCLIGetEventsPause(t *testing.T) {
|
||||
out, _, _ := cmd(t, "images", "-q")
|
||||
image := strings.Split(out, "\n")[0]
|
||||
cmd(t, "run", "-d", "--name", "testeventpause", image, "sleep", "2")
|
||||
cmd(t, "pause", "testeventpause")
|
||||
cmd(t, "unpause", "testeventpause")
|
||||
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", time.Now().Unix()))
|
||||
out, _, _ = runCommandWithOutput(eventsCmd)
|
||||
events := strings.Split(out, "\n")
|
||||
if len(events) <= 1 {
|
||||
t.Fatalf("Missing expected event")
|
||||
}
|
||||
|
||||
pauseEvent := strings.Fields(events[len(events)-3])
|
||||
unpauseEvent := strings.Fields(events[len(events)-2])
|
||||
|
||||
if pauseEvent[len(pauseEvent)-1] != "pause" {
|
||||
t.Fatalf("event should be pause, not %#v", pauseEvent)
|
||||
}
|
||||
if unpauseEvent[len(unpauseEvent)-1] != "unpause" {
|
||||
t.Fatalf("event should be pause, not %#v", unpauseEvent)
|
||||
}
|
||||
|
||||
logDone("events - pause/unpause is logged")
|
||||
}
|
||||
|
|
|
@ -183,6 +183,7 @@ func (srv *Server) ContainerPause(job *engine.Job) engine.Status {
|
|||
if err := container.Pause(); err != nil {
|
||||
return job.Errorf("Cannot pause container %s: %s", name, err)
|
||||
}
|
||||
srv.LogEvent("pause", container.ID, srv.daemon.Repositories().ImageName(container.Image))
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
|
@ -198,6 +199,7 @@ func (srv *Server) ContainerUnpause(job *engine.Job) engine.Status {
|
|||
if err := container.Unpause(); err != nil {
|
||||
return job.Errorf("Cannot unpause container %s: %s", name, err)
|
||||
}
|
||||
srv.LogEvent("unpause", container.ID, srv.daemon.Repositories().ImageName(container.Image))
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue