podman rmi shouldn't delete named referenced images

If an image is created from another and it is deleted,
only delete the actual image and not the parent images
if the parent images have names/references.

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: 
Approved by: mheon
This commit is contained in:
umohnani8
2018-07-27 16:11:47 -04:00
committed by Atomic Bot
parent bd7566f170
commit 87d8edb4c1
2 changed files with 36 additions and 1 deletions
libpod/image
test/e2e

@ -363,7 +363,7 @@ func (i *Image) Remove(force bool) error {
} }
// Do not remove if image is a base image and is not untagged, or if // Do not remove if image is a base image and is not untagged, or if
// the image has more children. // the image has more children.
if (nextParent == nil && len(parent.Names()) > 0) || len(children) > 0 { if len(children) > 0 || len(parent.Names()) > 0 {
return nil return nil
} }
id := parent.ID() id := parent.ID()

@ -141,6 +141,41 @@ var _ = Describe("Podman rmi", func() {
Expect(session.ExitCode()).To(Not(Equal(0))) Expect(session.ExitCode()).To(Not(Equal(0)))
}) })
It("podman rmi image that is created from another named imaged", func() {
session := podmanTest.Podman([]string{"rmi", "-fa"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"run", "--name", "c_test1", ALPINE, "true"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"commit", "-q", "c_test1", "test1"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"run", "--name", "c_test2", "test1", "true"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"commit", "-q", "c_test2", "test2"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"rm", "-a"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"rmi", "test2"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"images", "-q"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(Equal(2))
})
It("podman rmi with cached images", func() { It("podman rmi with cached images", func() {
session := podmanTest.Podman([]string{"rmi", "-fa"}) session := podmanTest.Podman([]string{"rmi", "-fa"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()