From 082d792693504848e186a29db717ce20c7ff7774 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 13 Mar 2019 20:19:31 +0100 Subject: Make 'podman rm' exit with 125 if it had a bogus & a running container Getting a list of containers, and then deleting them are two separate fallible steps that can run into different sets of errors. eg., in the case of a bogus missing container and a container that's running or paused, the first step will only trigger libpod.ErrNoSuchCtr. At this point it might appear that the exit code ought to be 1. However, when attempting the deletion, it will fail once more due to the status of the running or paused container. Since libpod.ErrNoSuchCtr is no longer the only error encountered, the exit code should be reset to 125. This problem is currently masked for rootless usage due to commit 35432ecaae4a8372 ("rootless: fix rm when uid in the container != 0"). Fixes: 85db895012bead6b ("rm: set exit code to 1 if a specified ...") e41279b902a334e5 ("Change exit code to 1 on podman rm ...") Signed-off-by: Debarshi Ray --- test/e2e/rm_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/e2e') diff --git a/test/e2e/rm_test.go b/test/e2e/rm_test.go index 1f67780da..9bf742a63 100644 --- a/test/e2e/rm_test.go +++ b/test/e2e/rm_test.go @@ -139,9 +139,23 @@ var _ = Describe("Podman rm", func() { Expect(podmanTest.NumberOfContainers()).To(Equal(1)) }) + It("podman rm bogus container", func() { session := podmanTest.Podman([]string{"rm", "bogus"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(1)) }) + It("podman rm bogus container and a running container", func() { + session := podmanTest.RunTopContainer("test1") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"rm", "bogus", "test1"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(125)) + + session = podmanTest.Podman([]string{"rm", "test1", "bogus"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(125)) + }) }) -- cgit v1.2.3-54-g00ecf