From c5922cc6f00a64ad8ada0637400a891f0af44c3c Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 14 Apr 2023 11:47:41 +0200 Subject: [PATCH] test/e2e: fix CleanupVolume/Secrets() Just like Cleanup() they should check the error codes. While doing this it was clear that some volume tests were calling Cleanup() twice so remove this. Instead make sure they call Cleanup() themselves so callers only need to do one call. This is required because we cannot use Expect().To() before doing all the cleanup. An error causes panic does results in an early return thus missing potentially important cleanup. Signed-off-by: Paul Holzinger --- test/e2e/common_test.go | 18 ++++++++---------- test/e2e/prune_test.go | 2 -- test/e2e/volume_prune_test.go | 8 -------- test/e2e/volume_rm_test.go | 2 -- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index b6926e6706..429df12e20 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -602,28 +602,26 @@ func (p *PodmanTestIntegration) Cleanup() { Expect(rmall).To(Exit(0), "command: %v\nstdout: %s\nstderr: %s", rmall.Command.Args, rmall.OutputToString(), rmall.ErrorToString()) } -// CleanupVolume cleans up the temporary store +// CleanupVolume cleans up the volumes and containers. +// This already calls Cleanup() internally. func (p *PodmanTestIntegration) CleanupVolume() { // Remove all containers session := p.Podman([]string{"volume", "rm", "-fa"}) - session.Wait(90) + session.WaitWithDefaultTimeout() p.Cleanup() + Expect(session).To(Exit(0), "command: %v\nstdout: %s\nstderr: %s", session.Command.Args, session.OutputToString(), session.ErrorToString()) } -// CleanupSecret cleans up the temporary store +// CleanupSecret cleans up the secrets and containers. +// This already calls Cleanup() internally. func (p *PodmanTestIntegration) CleanupSecrets() { // Remove all containers session := p.Podman([]string{"secret", "rm", "-a"}) session.Wait(90) - // Stop remove service on secret cleanup - p.StopRemoteService() - - // Nuke tempdir - if err := os.RemoveAll(p.TempDir); err != nil { - GinkgoWriter.Printf("%q\n", err) - } + p.Cleanup() + Expect(session).To(Exit(0), "command: %v\nstdout: %s\nstderr: %s", session.Command.Args, session.OutputToString(), session.ErrorToString()) } // InspectContainerToJSON takes the session output of an inspect diff --git a/test/e2e/prune_test.go b/test/e2e/prune_test.go index 89b60493b4..aa8d009862 100644 --- a/test/e2e/prune_test.go +++ b/test/e2e/prune_test.go @@ -521,8 +521,6 @@ var _ = Describe("Podman prune", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) Expect(session.OutputToStringArray()).To(HaveLen(3)) - - podmanTest.Cleanup() }) It("podman system prune --all --external fails", func() { diff --git a/test/e2e/volume_prune_test.go b/test/e2e/volume_prune_test.go index 6abee31a71..35a1d7fe25 100644 --- a/test/e2e/volume_prune_test.go +++ b/test/e2e/volume_prune_test.go @@ -58,8 +58,6 @@ var _ = Describe("Podman volume prune", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) Expect(session.OutputToStringArray()).To(HaveLen(2)) - - podmanTest.Cleanup() }) It("podman prune volume --filter until", func() { @@ -89,8 +87,6 @@ var _ = Describe("Podman volume prune", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) Expect(session.OutputToStringArray()).To(BeEmpty()) - - podmanTest.Cleanup() }) It("podman prune volume --filter", func() { @@ -157,8 +153,6 @@ var _ = Describe("Podman volume prune", func() { session = podmanTest.Podman([]string{"volume", "prune", "--force", "--filter", "label!=testlabel"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - - podmanTest.Cleanup() }) It("podman system prune --volume", func() { @@ -188,7 +182,5 @@ var _ = Describe("Podman volume prune", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) Expect(session.OutputToStringArray()).To(BeEmpty()) - - podmanTest.Cleanup() }) }) diff --git a/test/e2e/volume_rm_test.go b/test/e2e/volume_rm_test.go index a24f667362..ae6f4e4f59 100644 --- a/test/e2e/volume_rm_test.go +++ b/test/e2e/volume_rm_test.go @@ -66,8 +66,6 @@ var _ = Describe("Podman volume rm", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) Expect(session.OutputToStringArray()).To(BeEmpty()) - - podmanTest.Cleanup() }) It("podman volume remove bogus", func() {