From 13729859c7d46632f86f57f5fc46509b15174527 Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Fri, 12 Jan 2024 11:43:13 -0500 Subject: [PATCH 1/3] AppleHV: update LastUp time LastUp now correctly reports the lastUp time for podman machine on AppleHV, for both inspect and list. [NO NEW TESTS NEEDED] since this fixes an existing failing test. Signed-off-by: Ashley Cui --- pkg/machine/applehv/machine.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/machine/applehv/machine.go b/pkg/machine/applehv/machine.go index b4bfdcc927..3784bb1510 100644 --- a/pkg/machine/applehv/machine.go +++ b/pkg/machine/applehv/machine.go @@ -741,8 +741,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 From 6bcdad102f6d9f4590e62f65a869f7de85c6dab7 Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Thu, 11 Jan 2024 11:42:54 -0500 Subject: [PATCH 2/3] Fix machine inspect test config Signed-off-by: Ashley Cui --- pkg/machine/e2e/config_inspect_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From 50cf646ff6650d09059f2009faa1e0578f6d29b1 Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Wed, 10 Jan 2024 14:53:02 -0500 Subject: [PATCH 3/3] Assign separate ports for each appleHV machine Previously, every machine created using appleHV interacted with VFKit using port 8081. This meant that if multiple machines existed on the machine, starting one would start all the machines. This patch assigns a separate random port for each machine, so machine commands interact with just the specified machine. Signed-off-by: Ashley Cui --- pkg/machine/applehv/config.go | 4 ++-- pkg/machine/applehv/machine.go | 7 ++++++- pkg/machine/e2e/config_test.go | 2 +- pkg/machine/e2e/start_test.go | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/pkg/machine/applehv/config.go b/pkg/machine/applehv/config.go index 6c22bc8c44..a717e896ed 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 3784bb1510..e6a076b032 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 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))) + }) })