diff options
-rw-r--r-- | cmd/podman/stats.go | 7 | ||||
-rw-r--r-- | test/e2e/stats_test.go | 19 |
2 files changed, 7 insertions, 19 deletions
diff --git a/cmd/podman/stats.go b/cmd/podman/stats.go index dea351e88..f6beac1a8 100644 --- a/cmd/podman/stats.go +++ b/cmd/podman/stats.go @@ -84,8 +84,7 @@ func statsCmd(c *cli.Context) error { if ctr > 1 { return errors.Errorf("--all, --latest and containers cannot be used together") } else if ctr == 0 { - // If user didn't specify, imply --all - all = true + return errors.Errorf("you must specify --all, --latest, or at least one container") } runtime, err := libpodruntime.GetRuntime(c) @@ -126,6 +125,10 @@ func statsCmd(c *cli.Context) error { for _, ctr := range ctrs { initialStats, err := ctr.GetContainerStats(&libpod.ContainerStats{}) if err != nil { + // when doing "all", dont worry about containers that are not running + if c.Bool("all") && errors.Cause(err) == libpod.ErrCtrRemoved || errors.Cause(err) == libpod.ErrNoSuchCtr || errors.Cause(err) == libpod.ErrCtrStateInvalid { + continue + } return err } containerStats[ctr.ID()] = initialStats diff --git a/test/e2e/stats_test.go b/test/e2e/stats_test.go index 8096f58b2..e456d7114 100644 --- a/test/e2e/stats_test.go +++ b/test/e2e/stats_test.go @@ -31,12 +31,6 @@ var _ = Describe("Podman stats", func() { GinkgoWriter.Write([]byte(timedResult)) }) - It("podman stats should run with no containers", func() { - session := podmanTest.Podman([]string{"stats", "--no-stream"}) - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) - }) - It("podman stats with bogus container", func() { session := podmanTest.Podman([]string{"stats", "--no-stream", "123"}) session.WaitWithDefaultTimeout() @@ -53,15 +47,6 @@ var _ = Describe("Podman stats", func() { Expect(session.ExitCode()).To(Equal(0)) }) - It("podman stats on a running container no id", func() { - session := podmanTest.RunTopContainer("") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) - session = podmanTest.Podman([]string{"stats", "--no-stream"}) - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) - }) - It("podman stats on all containers", func() { session := podmanTest.RunTopContainer("") session.WaitWithDefaultTimeout() @@ -75,7 +60,7 @@ var _ = Describe("Podman stats", func() { session := podmanTest.RunTopContainer("") session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - session = podmanTest.Podman([]string{"stats", "--no-stream", "--format", "\"{{.Container}}\""}) + session = podmanTest.Podman([]string{"stats", "--all", "--no-stream", "--format", "\"{{.Container}}\""}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) }) @@ -84,7 +69,7 @@ var _ = Describe("Podman stats", func() { session := podmanTest.RunTopContainer("") session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - session = podmanTest.Podman([]string{"stats", "--no-stream", "--format", "json"}) + session = podmanTest.Podman([]string{"stats", "--all", "--no-stream", "--format", "json"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) Expect(session.IsJSONOutputValid()).To(BeTrue()) |