Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: event --filter volume=vol-name should compare the event name with volume name #18619

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
vyasgun marked this conversation as resolved.
Show resolved Hide resolved
// 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"
}