Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit69b397a

Browse files
Merge pull request#27410 from baude/fixdupmachinenames
Fix use of duplicate machine names
2 parents937636b +553c4a1 commit69b397a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

‎cmd/podman/machine/init.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ func initMachine(cmd *cobra.Command, args []string) error {
208208
// Check if machine already exists
209209
varerrNotExists*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+
iferr==nil {
213+
return&define.ErrVMAlreadyExists{Name:initOpts.Name}
214+
}
212215
if!errors.As(err,&errNotExists) {
213216
returnerr
214217
}

‎pkg/machine/e2e/init_test.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff 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

705708
varp4Config= []byte(`{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp