e2e tests: re-enable and fix podman stats tests

Renamed podman pod stats test specs to distinguish them from podman stats tests.
podman stats tests where disabled by a +build flag.
Fix podman stats format test, add negative test.
Fix podman stats cli command, exit non-zero on invalid format string.
Add tests for podman stats interval flag.

Signed-off-by: Thomas Weber <towe75@googlemail.com>
This commit is contained in:
Thomas Weber
2021-07-26 21:25:01 +02:00
parent cdbbd79155
commit 34b28d9598
4 changed files with 53 additions and 19 deletions

View File

@ -17,7 +17,6 @@ import (
"github.com/containers/podman/v3/utils" "github.com/containers/podman/v3/utils"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -140,7 +139,7 @@ func stats(cmd *cobra.Command, args []string) error {
return report.Error return report.Error
} }
if err := outputStats(report.Stats); err != nil { if err := outputStats(report.Stats); err != nil {
logrus.Error(err) return err
} }
} }
return nil return nil

View File

@ -223,6 +223,9 @@ func Stats(ctx context.Context, containers []string, options *StatsOptions) (cha
if err != nil { if err != nil {
return nil, err return nil, err
} }
if !response.IsSuccess() {
return nil, response.Process(nil)
}
statsChan := make(chan entities.ContainerStatsReport) statsChan := make(chan entities.ContainerStatsReport)

View File

@ -37,19 +37,19 @@ var _ = Describe("Podman pod stats", func() {
processTestResult(f) processTestResult(f)
}) })
It("podman stats should run with no pods", func() { It("podman pod stats should run with no pods", func() {
session := podmanTest.Podman([]string{"pod", "stats", "--no-stream"}) session := podmanTest.Podman([]string{"pod", "stats", "--no-stream"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
}) })
It("podman stats with a bogus pod", func() { It("podman pod stats with a bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "stats", "foobar"}) session := podmanTest.Podman([]string{"pod", "stats", "foobar"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125)) Expect(session).Should(Exit(125))
}) })
It("podman stats on a specific running pod", func() { It("podman pod stats on a specific running pod", func() {
_, ec, podid := podmanTest.CreatePod(nil) _, ec, podid := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0)) Expect(ec).To(Equal(0))
@ -66,7 +66,7 @@ var _ = Describe("Podman pod stats", func() {
Expect(stats).Should(Exit(0)) Expect(stats).Should(Exit(0))
}) })
It("podman stats on a specific running pod with shortID", func() { It("podman pod stats on a specific running pod with shortID", func() {
_, ec, podid := podmanTest.CreatePod(nil) _, ec, podid := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0)) Expect(ec).To(Equal(0))
@ -83,7 +83,7 @@ var _ = Describe("Podman pod stats", func() {
Expect(stats).Should(Exit(0)) Expect(stats).Should(Exit(0))
}) })
It("podman stats on a specific running pod with name", func() { It("podman pod stats on a specific running pod with name", func() {
_, ec, podid := podmanTest.CreatePod(map[string][]string{"--name": {"test"}}) _, ec, podid := podmanTest.CreatePod(map[string][]string{"--name": {"test"}})
Expect(ec).To(Equal(0)) Expect(ec).To(Equal(0))
@ -100,7 +100,7 @@ var _ = Describe("Podman pod stats", func() {
Expect(stats).Should(Exit(0)) Expect(stats).Should(Exit(0))
}) })
It("podman stats on running pods", func() { It("podman pod stats on running pods", func() {
_, ec, podid := podmanTest.CreatePod(nil) _, ec, podid := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0)) Expect(ec).To(Equal(0))
@ -117,7 +117,7 @@ var _ = Describe("Podman pod stats", func() {
Expect(stats).Should(Exit(0)) Expect(stats).Should(Exit(0))
}) })
It("podman stats on all pods", func() { It("podman pod stats on all pods", func() {
_, ec, podid := podmanTest.CreatePod(nil) _, ec, podid := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0)) Expect(ec).To(Equal(0))
@ -134,7 +134,7 @@ var _ = Describe("Podman pod stats", func() {
Expect(stats).Should(Exit(0)) Expect(stats).Should(Exit(0))
}) })
It("podman stats with json output", func() { It("podman pod stats with json output", func() {
_, ec, podid := podmanTest.CreatePod(nil) _, ec, podid := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0)) Expect(ec).To(Equal(0))
@ -151,7 +151,7 @@ var _ = Describe("Podman pod stats", func() {
Expect(stats).Should(Exit(0)) Expect(stats).Should(Exit(0))
Expect(stats.IsJSONOutputValid()).To(BeTrue()) Expect(stats.IsJSONOutputValid()).To(BeTrue())
}) })
It("podman stats with GO template", func() { It("podman pod stats with GO template", func() {
_, ec, podid := podmanTest.CreatePod(nil) _, ec, podid := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0)) Expect(ec).To(Equal(0))
@ -163,7 +163,7 @@ var _ = Describe("Podman pod stats", func() {
Expect(stats).To(Exit(0)) Expect(stats).To(Exit(0))
}) })
It("podman stats with invalid GO template", func() { It("podman pod stats with invalid GO template", func() {
_, ec, podid := podmanTest.CreatePod(nil) _, ec, podid := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0)) Expect(ec).To(Equal(0))
@ -175,7 +175,7 @@ var _ = Describe("Podman pod stats", func() {
Expect(stats).To(ExitWithError()) Expect(stats).To(ExitWithError())
}) })
It("podman stats on net=host post", func() { It("podman pod stats on net=host post", func() {
SkipIfRootless("--net=host not supported for rootless pods at present") SkipIfRootless("--net=host not supported for rootless pods at present")
podName := "testPod" podName := "testPod"
podCreate := podmanTest.Podman([]string{"pod", "create", "--net=host", "--name", podName}) podCreate := podmanTest.Podman([]string{"pod", "create", "--net=host", "--name", podName})

View File

@ -1,5 +1,3 @@
// +build
package integration package integration
import ( import (
@ -84,15 +82,49 @@ var _ = Describe("Podman stats", func() {
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
}) })
It("podman stats only output CPU data", func() { It("podman stats with GO template", func() {
session := podmanTest.RunTopContainer("") session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"stats", "--all", "--no-stream", "--format", "\"{{.ID}} {{.UpTime}} {{.AVGCPU}}\""}) stats := podmanTest.Podman([]string{"stats", "-a", "--no-reset", "--no-stream", "--format", "table {{.ID}} {{.AVGCPU}} {{.MemUsage}} {{.CPU}} {{.NetIO}} {{.BlockIO}} {{.PIDS}}"})
stats.WaitWithDefaultTimeout()
Expect(stats).To(Exit(0))
})
It("podman stats with invalid GO template", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session.LineInOutputContains("UpTime")).To(BeTrue())
Expect(session.LineInOutputContains("AVGCPU")).To(BeTrue())
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
stats := podmanTest.Podman([]string{"stats", "-a", "--no-reset", "--no-stream", "--format", "\"table {{.ID}} {{.NoSuchField}} \""})
stats.WaitWithDefaultTimeout()
Expect(stats).To(ExitWithError())
})
It("podman stats with negative interval", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
stats := podmanTest.Podman([]string{"stats", "-a", "--no-reset", "--no-stream", "--interval=-1"})
stats.WaitWithDefaultTimeout()
Expect(stats).To(ExitWithError())
})
It("podman stats with zero interval", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
stats := podmanTest.Podman([]string{"stats", "-a", "--no-reset", "--no-stream", "--interval=0"})
stats.WaitWithDefaultTimeout()
Expect(stats).To(ExitWithError())
})
It("podman stats with interval", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
stats := podmanTest.Podman([]string{"stats", "-a", "--no-reset", "--no-stream", "--interval=5"})
stats.WaitWithDefaultTimeout()
Expect(stats).Should(Exit(0))
}) })
It("podman stats with json output", func() { It("podman stats with json output", func() {