mirror of
https://github.com/containers/podman.git
synced 2025-06-22 01:48:54 +08:00
vmtypes names cannot be used as machine names
florent found a bug where he used "applehv" as a machine name. it turns out when we use a vmtype name, esp. the active type, it really messes up directory structures for configuration and images alike. Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -140,6 +140,12 @@ func initMachine(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
initOpts.Name = args[0]
|
initOpts.Name = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The vmtype names need to be reserved and cannot be used for podman machine names
|
||||||
|
if _, err := machine.ParseVMType(initOpts.Name, machine.UnknownVirt); err == nil {
|
||||||
|
return fmt.Errorf("cannot use %q for a machine name", initOpts.Name)
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := provider.LoadVMByName(initOpts.Name); err == nil {
|
if _, err := provider.LoadVMByName(initOpts.Name); err == nil {
|
||||||
return fmt.Errorf("%s: %w", initOpts.Name, machine.ErrVMAlreadyExists)
|
return fmt.Errorf("%s: %w", initOpts.Name, machine.ErrVMAlreadyExists)
|
||||||
}
|
}
|
||||||
|
@ -346,6 +346,7 @@ const (
|
|||||||
WSLVirt
|
WSLVirt
|
||||||
AppleHvVirt
|
AppleHvVirt
|
||||||
HyperVVirt
|
HyperVVirt
|
||||||
|
UnknownVirt
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v VMType) String() string {
|
func (v VMType) String() string {
|
||||||
@ -383,7 +384,7 @@ func ParseVMType(input string, emptyFallback VMType) (VMType, error) {
|
|||||||
case "":
|
case "":
|
||||||
return emptyFallback, nil
|
return emptyFallback, nil
|
||||||
default:
|
default:
|
||||||
return QemuVirt, fmt.Errorf("unknown VMType `%s`", input)
|
return UnknownVirt, fmt.Errorf("unknown VMType `%s`", input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,12 @@ var _ = Describe("podman machine init", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(session).To(Exit(125))
|
Expect(session).To(Exit(125))
|
||||||
|
|
||||||
|
reservedName := initMachine{}
|
||||||
|
reservedNameSession, err := mb.setName(testProvider.VMType().String()).setCmd(&reservedName).run()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(reservedNameSession).To(Exit(125))
|
||||||
|
Expect(reservedNameSession.errorToString()).To(ContainSubstring(fmt.Sprintf("cannot use %q", testProvider.VMType().String())))
|
||||||
|
|
||||||
badName := "foobar"
|
badName := "foobar"
|
||||||
bm := basicMachine{}
|
bm := basicMachine{}
|
||||||
sysConn, err := mb.setCmd(bm.withPodmanCommand([]string{"system", "connection", "add", badName, "tcp://localhost:8000"})).run()
|
sysConn, err := mb.setCmd(bm.withPodmanCommand([]string{"system", "connection", "add", badName, "tcp://localhost:8000"})).run()
|
||||||
|
Reference in New Issue
Block a user