mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +08:00
fix: podman event --filter volume=vol-name should compare the event name with volume name
Fixes: https://github.com/containers/podman/issues/18618 Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
This commit is contained in:
@ -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 {
|
||||
|
@ -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})
|
||||
}
|
||||
|
@ -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("")
|
||||
|
@ -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"
|
||||
}
|
||||
|
Reference in New Issue
Block a user