Merge pull request #7691 from rhatdan/mount

Fix podman image unmount to only report images unmounted
This commit is contained in:
OpenShift Merge Robot
2020-09-22 12:43:56 +00:00
committed by GitHub
2 changed files with 32 additions and 0 deletions

View File

@ -191,6 +191,15 @@ func (ir *ImageEngine) Unmount(ctx context.Context, nameOrIDs []string, options
reports := []*entities.ImageUnmountReport{} reports := []*entities.ImageUnmountReport{}
for _, img := range images { for _, img := range images {
report := entities.ImageUnmountReport{Id: img.ID()} report := entities.ImageUnmountReport{Id: img.ID()}
mounted, _, err := img.Mounted()
if err != nil {
// Errors will be caught in Unmount call below
// Default assumption to mounted
mounted = true
}
if !mounted {
continue
}
if err := img.Unmount(options.Force); err != nil { if err := img.Unmount(options.Force); err != nil {
if options.All && errors.Cause(err) == storage.ErrLayerNotMounted { if options.All && errors.Cause(err) == storage.ErrLayerNotMounted {
logrus.Debugf("Error umounting image %s, storage.ErrLayerNotMounted", img.ID()) logrus.Debugf("Error umounting image %s, storage.ErrLayerNotMounted", img.ID())

View File

@ -348,6 +348,25 @@ var _ = Describe("Podman mount", func() {
Expect(umount.ExitCode()).To(Equal(0)) Expect(umount.ExitCode()).To(Equal(0))
}) })
It("podman umount --all", func() {
setup := podmanTest.PodmanNoCache([]string{"pull", fedoraMinimal})
setup.WaitWithDefaultTimeout()
Expect(setup.ExitCode()).To(Equal(0))
setup = podmanTest.PodmanNoCache([]string{"pull", ALPINE})
setup.WaitWithDefaultTimeout()
Expect(setup.ExitCode()).To(Equal(0))
mount := podmanTest.Podman([]string{"image", "mount", fedoraMinimal})
mount.WaitWithDefaultTimeout()
Expect(mount.ExitCode()).To(Equal(0))
umount := podmanTest.Podman([]string{"image", "umount", "--all"})
umount.WaitWithDefaultTimeout()
Expect(umount.ExitCode()).To(Equal(0))
Expect(len(umount.OutputToStringArray())).To(Equal(1))
})
It("podman mount many", func() { It("podman mount many", func() {
setup := podmanTest.PodmanNoCache([]string{"pull", fedoraMinimal}) setup := podmanTest.PodmanNoCache([]string{"pull", fedoraMinimal})
setup.WaitWithDefaultTimeout() setup.WaitWithDefaultTimeout()
@ -402,6 +421,10 @@ var _ = Describe("Podman mount", func() {
Expect(mount.ExitCode()).To(Equal(0)) Expect(mount.ExitCode()).To(Equal(0))
Expect(mount.OutputToString()).To(Equal("")) Expect(mount.OutputToString()).To(Equal(""))
umount = podmanTest.PodmanNoCache([]string{"image", "umount", fedoraMinimal, ALPINE})
umount.WaitWithDefaultTimeout()
Expect(umount.ExitCode()).To(Equal(0))
mount1 = podmanTest.PodmanNoCache([]string{"image", "mount", "--all"}) mount1 = podmanTest.PodmanNoCache([]string{"image", "mount", "--all"})
mount1.WaitWithDefaultTimeout() mount1.WaitWithDefaultTimeout()
Expect(mount1.ExitCode()).To(Equal(0)) Expect(mount1.ExitCode()).To(Equal(0))