From 19e6de26541a01155019ef715359393412bedcde Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Fri, 3 Jul 2015 23:26:49 +0200 Subject: [PATCH] Fix combined image events filters Signed-off-by: Antonio Murdaca --- api/server/server.go | 7 +++++-- integration-cli/docker_cli_events_test.go | 25 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/api/server/server.go b/api/server/server.go index 1659f5834e..0537b5b164 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -410,6 +410,9 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht } isFiltered := func(field string, filter []string) bool { + if len(field) == 0 { + return false + } if len(filter) == 0 { return false } @@ -448,8 +451,8 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht ef["container"][i] = getContainerId(cn) } - if isFiltered(ev.Status, ef["event"]) || isFiltered(ev.From, ef["image"]) || - isFiltered(ev.ID, ef["container"]) { + if isFiltered(ev.Status, ef["event"]) || (isFiltered(ev.ID, ef["image"]) && + isFiltered(ev.From, ef["image"])) || isFiltered(ev.ID, ef["container"]) { return nil } diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index 36a8436b94..cef83fd42c 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -783,3 +783,28 @@ func (s *DockerSuite) TestEventsDefaultEmpty(c *check.C) { out, _ := dockerCmd(c, "events", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) c.Assert(strings.TrimSpace(out), check.Equals, "") } + +// #14316 +func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) { + testRequires(c, Network) + since := daemonTime(c).Unix() + repoName := fmt.Sprintf("%v/dockercli/testf", privateRegistryURL) + + runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") + out, _, err := runCommandWithOutput(runCmd) + c.Assert(err, check.IsNil) + cID := strings.TrimSpace(out) + c.Assert(waitRun(cID), check.IsNil) + + dockerCmd(c, "commit", cID, repoName) + dockerCmd(c, "stop", cID) + dockerCmd(c, "push", repoName) + + cmd := exec.Command(dockerBinary, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since))) + out, _, err = runCommandWithOutput(cmd) + c.Assert(err, check.IsNil) + + if !strings.Contains(out, repoName+": push\n") { + c.Fatalf("Missing 'push' log event for image %s\n%s", repoName, out) + } +}