diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-09-09 11:43:20 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-09-12 18:05:17 +0200 |
commit | 138b09c7e28de336717191ec79c0b0bdf61b448a (patch) | |
tree | dc845fe7b3870b6f2be04227912e91548ba46145 | |
parent | c5bdb6afe741d34c32f779b6ef9508b6f1d05794 (diff) | |
download | podman-138b09c7e28de336717191ec79c0b0bdf61b448a.tar.gz podman-138b09c7e28de336717191ec79c0b0bdf61b448a.tar.bz2 podman-138b09c7e28de336717191ec79c0b0bdf61b448a.zip |
event backend none: return an error when reading events
podman --events-backend none events should return with an error since it
will never be able to actually list events.
Fixes part three of #15688
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
-rw-r--r-- | cmd/podman/system/events.go | 39 | ||||
-rw-r--r-- | libpod/events/events_linux.go | 2 | ||||
-rw-r--r-- | libpod/events/nullout.go | 13 | ||||
-rw-r--r-- | test/system/090-events.bats | 9 |
4 files changed, 38 insertions, 25 deletions
diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go index 3c6a35e83..57279bb02 100644 --- a/cmd/podman/system/events.go +++ b/cmd/podman/system/events.go @@ -99,25 +99,28 @@ func eventsCmd(cmd *cobra.Command, _ []string) error { errChannel <- err }() - for event := range eventChannel { - switch { - case event == nil: - // no-op - case doJSON: - jsonStr, err := event.ToJSONString() - if err != nil { - return err + for { + select { + case err := <-errChannel: + return err + case event := <-eventChannel: + switch { + case event == nil: + // no-op + case doJSON: + jsonStr, err := event.ToJSONString() + if err != nil { + return err + } + fmt.Println(jsonStr) + case cmd.Flags().Changed("format"): + if err := rpt.Execute(event); err != nil { + return err + } + os.Stdout.WriteString("\n") + default: + fmt.Println(event.ToHumanReadable(!noTrunc)) } - fmt.Println(jsonStr) - case cmd.Flags().Changed("format"): - if err := rpt.Execute(event); err != nil { - return err - } - os.Stdout.WriteString("\n") - default: - fmt.Println(event.ToHumanReadable(!noTrunc)) } } - - return <-errChannel } diff --git a/libpod/events/events_linux.go b/libpod/events/events_linux.go index b11467aca..66b125dd5 100644 --- a/libpod/events/events_linux.go +++ b/libpod/events/events_linux.go @@ -20,7 +20,7 @@ func NewEventer(options EventerOptions) (Eventer, error) { case strings.ToUpper(LogFile.String()): return newLogFileEventer(options) case strings.ToUpper(Null.String()): - return NewNullEventer(), nil + return newNullEventer(), nil case strings.ToUpper(Memory.String()): return NewMemoryEventer(), nil default: diff --git a/libpod/events/nullout.go b/libpod/events/nullout.go index 587a1b98b..da3820c23 100644 --- a/libpod/events/nullout.go +++ b/libpod/events/nullout.go @@ -2,10 +2,11 @@ package events import ( "context" + "errors" ) -// EventToNull is an eventer type that only performs write operations -// and only writes to /dev/null. It is meant for unittests only +// EventToNull is an eventer type that does nothing. +// It is meant for unittests only type EventToNull struct{} // Write eats the event and always returns nil @@ -13,14 +14,14 @@ func (e EventToNull) Write(ee Event) error { return nil } -// Read does nothing. Do not use it. +// Read does nothing and returns an error. func (e EventToNull) Read(ctx context.Context, options ReadOptions) error { - return nil + return errors.New("cannot read events with the \"none\" backend") } -// NewNullEventer returns a new null eventer. You should only do this for +// newNullEventer returns a new null eventer. You should only do this for // the purposes of internal libpod testing. -func NewNullEventer() Eventer { +func newNullEventer() Eventer { return EventToNull{} } diff --git a/test/system/090-events.bats b/test/system/090-events.bats index 51a327865..509e7a306 100644 --- a/test/system/090-events.bats +++ b/test/system/090-events.bats @@ -217,3 +217,12 @@ EOF --format="{{.Attributes.$lname}}" assert "$output" = "$lvalue" "podman-events output includes container label" } + +@test "events - backend none should error" { + skip_if_remote "remote does not support --events-backend" + + run_podman 125 --events-backend none events + is "$output" "Error: cannot read events with the \"none\" backend" "correct error message" + run_podman 125 --events-backend none events --stream=false + is "$output" "Error: cannot read events with the \"none\" backend" "correct error message" +} |