From e7df73efadd36e2489954ee9a766a3fbfe4eafeb Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 18 Jan 2021 14:49:53 -0500 Subject: Fix handling of container remove I found several problems with container remove podman-remote rm --all Was not handled podman-remote rm --ignore Was not handled Return better errors when attempting to remove an --external container. Currently we return the container does not exists, as opposed to container is an external container that is being used. This patch also consolidates the tunnel code to use the same code for removing the container, as the local API, removing duplication of code and potential problems. Signed-off-by: Daniel J Walsh --- test/e2e/rm_test.go | 34 ++++++++++++++++++++++++++++++++++ test/system/040-ps.bats | 7 +++++-- 2 files changed, 39 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/e2e/rm_test.go b/test/e2e/rm_test.go index 524c07cc6..ca142d7f3 100644 --- a/test/e2e/rm_test.go +++ b/test/e2e/rm_test.go @@ -215,6 +215,40 @@ var _ = Describe("Podman rm", func() { Expect(result.ExitCode()).To(Equal(125)) }) + It("podman rm --all", func() { + session := podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + + session = podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(2)) + + session = podmanTest.Podman([]string{"rm", "--all"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(0)) + }) + + It("podman rm --ignore", func() { + session := podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToStringArray()[0] + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + + session = podmanTest.Podman([]string{"rm", "bogus", cid}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(1)) + + session = podmanTest.Podman([]string{"rm", "--ignore", "bogus", cid}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(0)) + }) + It("podman rm bogus container", func() { session := podmanTest.Podman([]string{"rm", "bogus"}) session.WaitWithDefaultTimeout() diff --git a/test/system/040-ps.bats b/test/system/040-ps.bats index 0447122b1..0ae8b0ce0 100644 --- a/test/system/040-ps.bats +++ b/test/system/040-ps.bats @@ -111,8 +111,11 @@ EOF run_podman ps --storage -a is "${#lines[@]}" "2" "podman ps -a --storage sees buildah container" - # This is what deletes the container - # FIXME: why doesn't "podman rm --storage $cid" do anything? + # We can't rm it without -f, but podman should issue a helpful message + run_podman 2 rm "$cid" + is "$output" "Error: container .* is mounted and cannot be removed without using force: container state improper" "podman rm without -f" + + # With -f, we can remove it. run_podman rm -f "$cid" run_podman ps --storage -a -- cgit v1.2.3-54-g00ecf