File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -208,7 +208,10 @@ func initMachine(cmd *cobra.Command, args []string) error {
208208 // Check if machine already exists
209209 var errNotExists * define.ErrVMDoesNotExist
210210 _ , _ , err := shim .VMExists (initOpts .Name )
211- // errors.As checks for nil so safe to use.
211+ // if nil, means we found a vm and need to reject it by name
212+ if err == nil {
213+ return & define.ErrVMAlreadyExists {Name : initOpts .Name }
214+ }
212215 if ! errors .As (err , & errNotExists ) {
213216 return err
214217 }
Original file line number Diff line number Diff line change @@ -117,6 +117,11 @@ var _ = Describe("podman machine init", func() {
117117 Expect (testMachine .Resources .CPUs ).To (Equal (uint64 (cpus )))
118118 Expect (testMachine .Resources .Memory ).To (BeEquivalentTo (uint64 (2048 )))
119119 }
120+ // creating a new VM with the same name must fail
121+ repeatSession , err := mb .setCmd (i .withImage (mb .imagePath )).run ()
122+ Expect (err ).ToNot (HaveOccurred ())
123+ Expect (repeatSession ).To (Exit (125 ))
124+ Expect (repeatSession .errorToString ()).To (ContainSubstring (fmt .Sprintf ("Error: machine %q already exists" , mb .names [0 ])))
120125 })
121126
122127 It ("run playbook" , func () {
@@ -655,7 +660,6 @@ var _ = Describe("podman machine init", func() {
655660 session , err := mb .setName (machineName ).setCmd (i .withImage (mb .imagePath ).withProvider (providerOverride )).run ()
656661 Expect (err ).ToNot (HaveOccurred ())
657662 Expect (session .errorToString ()).To (ContainSubstring (fmt .Sprintf ("unsupported provider %q" , providerOverride )))
658-
659663 })
660664
661665 It ("machine init --provider" , func () {
@@ -699,7 +703,6 @@ var _ = Describe("podman machine init", func() {
699703 Expect (p ).To (Equal (l .VMType ))
700704 }
701705 })
702-
703706})
704707
705708var p4Config = []byte (`{
You can’t perform that action at this time.
0 commit comments