Skip to content

Commit

Permalink
stats: list all running containers unless specified otherwise
Browse files Browse the repository at this point in the history
Unless specified otherwise by --all, --latest or via arguments, list all
running containers.  This matches the behaviour of Docker and is also
illustrated in the man pages where containers and options are marked to
be optional.

Fixes: containers#4274
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
  • Loading branch information
vrothberg committed Oct 16, 2019
1 parent 5f72e6e commit e8b3d07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 0 additions & 5 deletions cmd/podman/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ var (
statsCommand.Remote = remoteclient
return statsCmd(&statsCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
return checkAllAndLatest(cmd, args, false)
},
Example: `podman stats --all --no-stream
podman stats ctrID
podman stats --no-stream --format "table {{.ID}} {{.Name}} {{.MemUsage}}" ctrID`,
Expand Down Expand Up @@ -92,8 +89,6 @@ func statsCmd(c *cliconfig.StatsValues) error {

if ctr > 1 {
return errors.Errorf("--all, --latest and containers cannot be used together")
} else if ctr == 0 {
return errors.Errorf("you must specify --all, --latest, or at least one container")
}

runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
. "github.com/onsi/gomega"
)

// TODO: we need to check the output. Currently, we only check the exit codes
// which is not enough.
var _ = Describe("Podman stats", func() {
var (
tempdir string
Expand Down Expand Up @@ -61,6 +63,15 @@ var _ = Describe("Podman stats", func() {
Expect(session.ExitCode()).To(Equal(0))
})

It("podman stats on all running containers", 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 only output cids", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expand Down

0 comments on commit e8b3d07

Please sign in to comment.