From d124d90e1859e48ffbbd8f67cf071270fbc6eb15 Mon Sep 17 00:00:00 2001 From: Nicola Sella Date: Wed, 4 Sep 2024 16:02:35 +0200 Subject: [PATCH] Improve error when starting multiple machines Instead of ErrVMAlreadyRunning use a more appropriate error. Also improve the message a little bit. Fixes: https://github.com/containers/podman/issues/23436 Signed-off-by: Nicola Sella --- pkg/machine/e2e/start_test.go | 4 ++-- pkg/machine/shim/host.go | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/machine/e2e/start_test.go b/pkg/machine/e2e/start_test.go index efd65311dbd2..d3e2c8cb3427 100644 --- a/pkg/machine/e2e/start_test.go +++ b/pkg/machine/e2e/start_test.go @@ -210,10 +210,10 @@ var _ = Describe("podman machine start", func() { Expect(startSession1).To(Or(Exit(0), Exit(125)), "start command should succeed or fail with 125") if startSession1.ExitCode() == 0 { Expect(startSession2).To(Exit(125), "first start worked, second start must fail") - Expect(startSession2.errorToString()).To(ContainSubstring("machine %s: VM already running or starting", machine1)) + Expect(startSession2.errorToString()).To(ContainSubstring("machine %s is already running: only one VM can be active at a time", machine1)) } else { Expect(startSession2).To(Exit(0), "first start failed, second start succeed") - Expect(startSession1.errorToString()).To(ContainSubstring("machine %s: VM already running or starting", machine2)) + Expect(startSession1.errorToString()).To(ContainSubstring("machine %s is already running: only one VM can be active at a time", machine2)) } }) }) diff --git a/pkg/machine/shim/host.go b/pkg/machine/shim/host.go index e1c1834f60db..4467b3ef0868 100644 --- a/pkg/machine/shim/host.go +++ b/pkg/machine/shim/host.go @@ -283,7 +283,10 @@ func checkExclusiveActiveVM(provider vmconfigs.VMProvider, mc *vmconfigs.Machine return err } if state == machineDefine.Running || state == machineDefine.Starting { - return fmt.Errorf("unable to start %q: machine %s: %w", mc.Name, name, machineDefine.ErrVMAlreadyRunning) + if mc.Name == name { + return fmt.Errorf("unable to start %q: machine %s: %w", mc.Name, name, machineDefine.ErrVMAlreadyRunning) + } + return fmt.Errorf("unable to start %q: machine %s is already running: %w", mc.Name, name, machineDefine.ErrMultipleActiveVM) } } return nil