Files
podman/pkg/machine/e2e/reset_test.go
Paul Holzinger 3c0176b2d0 pkg/machine/e2e: fix broken cleanup
Currently all podman machine rm errors in AfterEach were ignored.
This means some leaked and caused issues later on, see #22844.

To fix it first rework the logic to only remove machines when needed at
the place were they are created using DeferCleanup(), however
DeferCleanup() does not work well together with AfterEach() as it always
run AfterEach() before DeferCleanup(). As AfterEach() deletes the dir
the podman machine rm call can not be done afterwards.

As such migrate all cleanup to use DeferCleanup() and while I have to
touch this fix the code to remove the per file duplciation and define
the setup/cleanup once in the global scope.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-07-01 14:23:11 +02:00

78 lines
2.4 KiB
Go

package e2e_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("podman machine reset", func() {
It("starting from scratch should not error", func() {
i := resetMachine{}
session, err := mb.setCmd(i.withForce()).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(0))
})
It("reset machine with one defined machine", func() {
name := randomString()
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(0))
ls := new(listMachine)
beforeSession, err := mb.setCmd(ls.withNoHeading()).run()
Expect(err).ToNot(HaveOccurred())
Expect(beforeSession).To(Exit(0))
Expect(beforeSession.outputToStringSlice()).To(HaveLen(1))
reset := resetMachine{}
resetSession, err := mb.setCmd(reset.withForce()).run()
Expect(err).ToNot(HaveOccurred())
Expect(resetSession).To(Exit(0))
afterSession, err := mb.setCmd(ls.withNoHeading()).run()
Expect(err).ToNot(HaveOccurred())
Expect(afterSession).To(Exit(0))
Expect(afterSession.outputToStringSlice()).To(BeEmpty())
})
It("reset with running machine and other machines idle ", func() {
name := randomString()
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow()).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(0))
ls := new(listMachine)
beforeSession, err := mb.setCmd(ls.withNoHeading()).run()
Expect(err).ToNot(HaveOccurred())
Expect(beforeSession).To(Exit(0))
Expect(beforeSession.outputToStringSlice()).To(HaveLen(1))
name2 := randomString()
i2 := new(initMachine)
session2, err := mb.setName(name2).setCmd(i2.withImage(mb.imagePath)).run()
Expect(err).ToNot(HaveOccurred())
Expect(session2).To(Exit(0))
beforeSession, err = mb.setCmd(ls.withNoHeading()).run()
Expect(err).ToNot(HaveOccurred())
Expect(beforeSession).To(Exit(0))
Expect(beforeSession.outputToStringSlice()).To(HaveLen(2))
reset := resetMachine{}
resetSession, err := mb.setCmd(reset.withForce()).run()
Expect(err).ToNot(HaveOccurred())
Expect(resetSession).To(Exit(0))
afterSession, err := mb.setCmd(ls.withNoHeading()).run()
Expect(err).ToNot(HaveOccurred())
Expect(afterSession).To(Exit(0))
Expect(afterSession.outputToStringSlice()).To(BeEmpty())
})
})