mirror of
https://github.com/containers/podman.git
synced 2025-11-30 18:18:18 +08:00
Fix use of duplicate machine names
A condition was changed in the refgactor of init where duplicate names would be allowed but no machine was created. Duplicate names are not permitted and should return an error. Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@@ -208,7 +208,10 @@ func initMachine(cmd *cobra.Command, args []string) error {
|
||||
// Check if machine already exists
|
||||
var errNotExists *define.ErrVMDoesNotExist
|
||||
_, _, err := shim.VMExists(initOpts.Name)
|
||||
// errors.As checks for nil so safe to use.
|
||||
// if nil, means we found a vm and need to reject it by name
|
||||
if err == nil {
|
||||
return &define.ErrVMAlreadyExists{Name: initOpts.Name}
|
||||
}
|
||||
if !errors.As(err, &errNotExists) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -117,6 +117,11 @@ var _ = Describe("podman machine init", func() {
|
||||
Expect(testMachine.Resources.CPUs).To(Equal(uint64(cpus)))
|
||||
Expect(testMachine.Resources.Memory).To(BeEquivalentTo(uint64(2048)))
|
||||
}
|
||||
// creating a new VM with the same name must fail
|
||||
repeatSession, err := mb.setCmd(i.withImage(mb.imagePath)).run()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(repeatSession).To(Exit(125))
|
||||
Expect(repeatSession.errorToString()).To(ContainSubstring(fmt.Sprintf("Error: machine %q already exists", mb.names[0])))
|
||||
})
|
||||
|
||||
It("run playbook", func() {
|
||||
@@ -655,7 +660,6 @@ var _ = Describe("podman machine init", func() {
|
||||
session, err := mb.setName(machineName).setCmd(i.withImage(mb.imagePath).withProvider(providerOverride)).run()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(session.errorToString()).To(ContainSubstring(fmt.Sprintf("unsupported provider %q", providerOverride)))
|
||||
|
||||
})
|
||||
|
||||
It("machine init --provider", func() {
|
||||
@@ -699,7 +703,6 @@ var _ = Describe("podman machine init", func() {
|
||||
Expect(p).To(Equal(l.VMType))
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
var p4Config = []byte(`{
|
||||
|
||||
Reference in New Issue
Block a user