Browse code

Merge pull request #14388 from runcom/14316-fix-events-filters

Fix combined image events filters

Jessie Frazelle authored on 2015/07/08 10:08:56
Showing 2 changed files
... ...
@@ -410,6 +410,9 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
410 410
 	}
411 411
 
412 412
 	isFiltered := func(field string, filter []string) bool {
413
+		if len(field) == 0 {
414
+			return false
415
+		}
413 416
 		if len(filter) == 0 {
414 417
 			return false
415 418
 		}
... ...
@@ -448,8 +451,8 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
448 448
 			ef["container"][i] = getContainerId(cn)
449 449
 		}
450 450
 
451
-		if isFiltered(ev.Status, ef["event"]) || isFiltered(ev.From, ef["image"]) ||
452
-			isFiltered(ev.ID, ef["container"]) {
451
+		if isFiltered(ev.Status, ef["event"]) || (isFiltered(ev.ID, ef["image"]) &&
452
+			isFiltered(ev.From, ef["image"])) || isFiltered(ev.ID, ef["container"]) {
453 453
 			return nil
454 454
 		}
455 455
 
... ...
@@ -783,3 +783,28 @@ func (s *DockerSuite) TestEventsDefaultEmpty(c *check.C) {
783 783
 	out, _ := dockerCmd(c, "events", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
784 784
 	c.Assert(strings.TrimSpace(out), check.Equals, "")
785 785
 }
786
+
787
+// #14316
788
+func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
789
+	testRequires(c, Network)
790
+	since := daemonTime(c).Unix()
791
+	repoName := fmt.Sprintf("%v/dockercli/testf", privateRegistryURL)
792
+
793
+	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
794
+	out, _, err := runCommandWithOutput(runCmd)
795
+	c.Assert(err, check.IsNil)
796
+	cID := strings.TrimSpace(out)
797
+	c.Assert(waitRun(cID), check.IsNil)
798
+
799
+	dockerCmd(c, "commit", cID, repoName)
800
+	dockerCmd(c, "stop", cID)
801
+	dockerCmd(c, "push", repoName)
802
+
803
+	cmd := exec.Command(dockerBinary, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since)))
804
+	out, _, err = runCommandWithOutput(cmd)
805
+	c.Assert(err, check.IsNil)
806
+
807
+	if !strings.Contains(out, repoName+": push\n") {
808
+		c.Fatalf("Missing 'push' log event for image %s\n%s", repoName, out)
809
+	}
810
+}