diff --git a/pkg/machine/applehv/config.go b/pkg/machine/applehv/config.go index 5eeab76db2..0332c37cd9 100644 --- a/pkg/machine/applehv/config.go +++ b/pkg/machine/applehv/config.go @@ -19,8 +19,8 @@ import ( ) const ( - defaultVFKitEndpoint = "http://localhost:8081" - ignitionSocketName = "ignition.sock" + localhostURI = "http://localhost" + ignitionSocketName = "ignition.sock" ) type AppleHVVirtualization struct { diff --git a/pkg/machine/applehv/machine.go b/pkg/machine/applehv/machine.go index 2e511ef69f..7cb7151f2a 100644 --- a/pkg/machine/applehv/machine.go +++ b/pkg/machine/applehv/machine.go @@ -129,7 +129,12 @@ func (m *MacMachine) setVfkitInfo(cfg *config.Config, readySocket define.VMFile) } m.Vfkit.VirtualMachine.Devices = defaultDevices - m.Vfkit.Endpoint = defaultVFKitEndpoint + randPort, err := utils.GetRandomPort() + if err != nil { + return err + } + + m.Vfkit.Endpoint = localhostURI + ":" + strconv.Itoa(randPort) m.Vfkit.VfkitBinaryPath = vfkitBinaryPath return nil @@ -769,8 +774,13 @@ func (m *MacMachine) Stop(name string, opts machine.StopOptions) error { logrus.Error(err) } }() + if err := m.Vfkit.stop(false, true); err != nil { + return err + } - return m.Vfkit.stop(false, true) + // keep track of last up + m.LastUp = time.Now() + return m.writeConfig() } // getVMConfigPath is a simple wrapper for getting the fully-qualified diff --git a/pkg/machine/e2e/config_inspect_test.go b/pkg/machine/e2e/config_inspect_test.go index ffd74220f1..f0d4aa5bdd 100644 --- a/pkg/machine/e2e/config_inspect_test.go +++ b/pkg/machine/e2e/config_inspect_test.go @@ -13,7 +13,7 @@ func (i *inspectMachine) buildCmd(m *machineTestBuilder) []string { if len(i.format) > 0 { cmd = append(cmd, "--format", i.format) } - cmd = append(cmd, m.names...) + cmd = append(cmd, m.name) i.cmd = cmd return cmd } diff --git a/pkg/machine/e2e/config_test.go b/pkg/machine/e2e/config_test.go index 60e9187a5a..625d97966d 100644 --- a/pkg/machine/e2e/config_test.go +++ b/pkg/machine/e2e/config_test.go @@ -131,7 +131,7 @@ func (m *machineTestBuilder) setCmd(mc machineCommand) *machineTestBuilder { return m } -func (m *machineTestBuilder) setTimeout(timeout time.Duration) *machineTestBuilder { +func (m *machineTestBuilder) setTimeout(timeout time.Duration) *machineTestBuilder { //nolint: unparam m.timeout = timeout return m } diff --git a/pkg/machine/e2e/start_test.go b/pkg/machine/e2e/start_test.go index b62ff9396f..0e4dfe002a 100644 --- a/pkg/machine/e2e/start_test.go +++ b/pkg/machine/e2e/start_test.go @@ -1,6 +1,8 @@ package e2e_test import ( + "time" + "github.com/containers/podman/v4/pkg/machine" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -84,4 +86,36 @@ var _ = Describe("podman machine start", func() { Expect(startSession).To(Exit(125)) Expect(startSession.errorToString()).To(ContainSubstring("VM already running or starting")) }) + It("start only starts specified machine", func() { + i := initMachine{} + startme := randomString() + session, err := mb.setName(startme).setCmd(i.withImagePath(mb.imagePath)).run() + Expect(err).ToNot(HaveOccurred()) + Expect(session).To(Exit(0)) + + j := initMachine{} + dontstartme := randomString() + session2, err := mb.setName(dontstartme).setCmd(j.withImagePath(mb.imagePath)).run() + Expect(err).ToNot(HaveOccurred()) + Expect(session2).To(Exit(0)) + + s := startMachine{} + session3, err := mb.setName(startme).setCmd(s).setTimeout(time.Minute * 10).run() + Expect(err).ToNot(HaveOccurred()) + Expect(session3).Should(Exit(0)) + + inspect := new(inspectMachine) + inspect = inspect.withFormat("{{.State}}") + inspectSession, err := mb.setName(startme).setCmd(inspect).run() + Expect(err).ToNot(HaveOccurred()) + Expect(inspectSession).To(Exit(0)) + Expect(inspectSession.outputToString()).To(Equal(machine.Running)) + + inspect2 := new(inspectMachine) + inspect2 = inspect2.withFormat("{{.State}}") + inspectSession2, err := mb.setName(dontstartme).setCmd(inspect2).run() + Expect(err).ToNot(HaveOccurred()) + Expect(inspectSession2).To(Exit(0)) + Expect(inspectSession2.outputToString()).To(Not(Equal(machine.Running))) + }) })