Skip to content

Commit

Permalink
Merge pull request #18619 from vyasgun/pr/events-volume-name
Browse files Browse the repository at this point in the history
fix: event --filter volume=vol-name should compare the event name with volume name
  • Loading branch information
openshift-merge-robot authored May 23, 2023
2 parents b155106 + 5f29c7b commit ca7d012
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libpod/events/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func generateEventFilter(filter, filterValue string) (func(e *Event) bool, error
if e.Type != Volume {
return false
}
return strings.HasPrefix(e.ID, filterValue)
// Prefix match with name for consistency with docker
return strings.HasPrefix(e.Name, filterValue)
}, nil
case "TYPE":
return func(e *Event) bool {
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,19 @@ func (p *PodmanTestIntegration) CreatePod(options map[string][]string) (*PodmanS
return session, session.ExitCode(), session.OutputToString()
}

func (p *PodmanTestIntegration) CreateVolume(options map[string][]string) (*PodmanSessionIntegration, int, string) {
var args = []string{"volume", "create"}
for k, values := range options {
for _, v := range values {
args = append(args, k+"="+v)
}
}

session := p.Podman(args)
session.WaitWithDefaultTimeout()
return session, session.ExitCode(), session.OutputToString()
}

func (p *PodmanTestIntegration) RunTopContainerInPod(name, pod string) *PodmanSessionIntegration {
return p.RunTopContainerWithArgs(name, []string{"--pod", pod})
}
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ var _ = Describe("Podman events", func() {
date := time.Now().Format("2006-01-02")
Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(date)), "event log has correct timestamp")
})
It("podman events with a volume filter", func() {
_, ec, vname := podmanTest.CreateVolume(nil)
Expect(ec).To(Equal(0))

// Run two event commands - one with the full volume name and the second with the prefix
result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", fmt.Sprintf("volume=%s", vname)})
resultPrefix := podmanTest.Podman([]string{"events", "--stream=false", "--filter", fmt.Sprintf("volume=%s", vname[:5])})

result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
events := result.OutputToStringArray()
Expect(events).To(HaveLen(1), "number of events")
Expect(events[0]).To(ContainSubstring(vname), "event log includes volume name")

resultPrefix.WaitWithDefaultTimeout()
Expect(resultPrefix).Should(Exit(0))
events = resultPrefix.OutputToStringArray()
Expect(events).To(HaveLen(1), "number of events")
Expect(events[0]).To(ContainSubstring(vname), "event log includes volume name")
})

It("podman events with an event filter and container=cid", func() {
_, ec, cid := podmanTest.RunLsContainer("")
Expand Down
15 changes: 15 additions & 0 deletions test/system/090-events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,18 @@ EOF
--stream=false
is "${lines[0]}" ".* container died .* (image=$IMAGE, name=$cname, .*)"
}

@test "events - volume events" {
local vname=v$(random_string 10)
run_podman volume create $vname
run_podman volume rm $vname

run_podman events --since=1m --stream=false --filter volume=$vname
notrunc_results="$output"
assert "${lines[0]}" =~ ".* volume create $vname"
assert "${lines[1]}" =~ ".* volume remove $vname"

# Prefix test
run_podman events --since=1m --stream=false --filter volume=${vname:0:5}
assert "$output" = "$notrunc_results"
}

0 comments on commit ca7d012

Please sign in to comment.