mirror of
https://github.com/containers/podman.git
synced 2025-06-25 03:52:15 +08:00
Merge pull request #19667 from ashley-cui/testrm
Update machine rm tests
This commit is contained in:
@ -40,17 +40,17 @@ func (i *rmMachine) withForce() *rmMachine {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *rmMachine) withSaveIgnition() *rmMachine { //nolint:unused
|
func (i *rmMachine) withSaveIgnition() *rmMachine {
|
||||||
i.saveIgnition = true
|
i.saveIgnition = true
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *rmMachine) withSaveImage() *rmMachine { //nolint:unused
|
func (i *rmMachine) withSaveImage() *rmMachine {
|
||||||
i.saveImage = true
|
i.saveImage = true
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *rmMachine) withSaveKeys() *rmMachine { //nolint:unused
|
func (i *rmMachine) withSaveKeys() *rmMachine {
|
||||||
i.saveKeys = true
|
i.saveKeys = true
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package e2e_test
|
package e2e_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
. "github.com/onsi/gomega/gexec"
|
. "github.com/onsi/gomega/gexec"
|
||||||
@ -33,8 +36,9 @@ var _ = Describe("podman machine rm", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(session).To(Exit(0))
|
Expect(session).To(Exit(0))
|
||||||
rm := rmMachine{}
|
rm := rmMachine{}
|
||||||
_, err = mb.setCmd(rm.withForce()).run()
|
removeSession, err := mb.setCmd(rm.withForce()).run()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(removeSession).To(Exit(0))
|
||||||
|
|
||||||
// Inspecting a non-existent machine should fail
|
// Inspecting a non-existent machine should fail
|
||||||
// which means it is gone
|
// which means it is gone
|
||||||
@ -44,8 +48,9 @@ var _ = Describe("podman machine rm", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("Remove running machine", func() {
|
It("Remove running machine", func() {
|
||||||
|
name := randomString()
|
||||||
i := new(initMachine)
|
i := new(initMachine)
|
||||||
session, err := mb.setCmd(i.withImagePath(mb.imagePath).withNow()).run()
|
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withNow()).run()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(session).To(Exit(0))
|
Expect(session).To(Exit(0))
|
||||||
rm := new(rmMachine)
|
rm := new(rmMachine)
|
||||||
@ -54,6 +59,7 @@ var _ = Describe("podman machine rm", func() {
|
|||||||
stop, err := mb.setCmd(rm).run()
|
stop, err := mb.setCmd(rm).run()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(stop).To(Exit(125))
|
Expect(stop).To(Exit(125))
|
||||||
|
Expect(stop.errorToString()).To(ContainSubstring(fmt.Sprintf("vm \"%s\" cannot be destroyed", name)))
|
||||||
|
|
||||||
// Removing again with force
|
// Removing again with force
|
||||||
stopAgain, err := mb.setCmd(rm.withForce()).run()
|
stopAgain, err := mb.setCmd(rm.withForce()).run()
|
||||||
@ -65,4 +71,50 @@ var _ = Describe("podman machine rm", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(ec).To(Equal(125))
|
Expect(ec).To(Equal(125))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("machine rm --save-keys, --save-ignition, --save-image", func() {
|
||||||
|
|
||||||
|
i := new(initMachine)
|
||||||
|
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(session).To(Exit(0))
|
||||||
|
|
||||||
|
inspect := new(inspectMachine)
|
||||||
|
inspect = inspect.withFormat("{{.SSHConfig.IdentityPath}}")
|
||||||
|
inspectSession, err := mb.setCmd(inspect).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
key := inspectSession.outputToString()
|
||||||
|
pubkey := key + ".pub"
|
||||||
|
|
||||||
|
inspect = inspect.withFormat("{{.Image.IgnitionFile.Path}}")
|
||||||
|
inspectSession, err = mb.setCmd(inspect).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
ign := inspectSession.outputToString()
|
||||||
|
|
||||||
|
inspect = inspect.withFormat("{{.Image.ImagePath.Path}}")
|
||||||
|
inspectSession, err = mb.setCmd(inspect).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
img := inspectSession.outputToString()
|
||||||
|
|
||||||
|
rm := rmMachine{}
|
||||||
|
removeSession, err := mb.setCmd(rm.withForce().withSaveIgnition().withSaveImage().withSaveKeys()).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(removeSession).To(Exit(0))
|
||||||
|
|
||||||
|
// Inspecting a non-existent machine should fail
|
||||||
|
// which means it is gone
|
||||||
|
_, ec, err := mb.toQemuInspectInfo()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(ec).To(Equal(125))
|
||||||
|
|
||||||
|
_, err = os.Stat(key)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
_, err = os.Stat(pubkey)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
_, err = os.Stat(ign)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
_, err = os.Stat(img)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user