From 08936db354b6fbb042f98a0f6dcff20e624483ea Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Sun, 24 Sep 2023 09:39:50 -0500 Subject: [PATCH] hyperv: set more realistic starting state the window for hyperv's "Starting" state is very narrow; so to more mimic qemu, we follow suit. starting bools are set when the vm boots and when it communicates back on the read socket. this allows pkg/machine/init_test.go to pass [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude --- cmd/podman/machine/list.go | 6 +++--- pkg/machine/hyperv/config.go | 2 +- pkg/machine/hyperv/machine.go | 20 +++++++++++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cmd/podman/machine/list.go b/cmd/podman/machine/list.go index 70acab54d9..a6d5013c93 100644 --- a/cmd/podman/machine/list.go +++ b/cmd/podman/machine/list.go @@ -200,12 +200,12 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*entities.ListReporter, error response.Name = vm.Name } switch { - case vm.Running: - response.LastUp = "Currently running" - response.Running = true case vm.Starting: response.LastUp = "Currently starting" response.Starting = true + case vm.Running: + response.LastUp = "Currently running" + response.Running = true default: response.LastUp = units.HumanDuration(time.Since(vm.LastUp)) + " ago" } diff --git a/pkg/machine/hyperv/config.go b/pkg/machine/hyperv/config.go index 9f92e59b65..342ca2f089 100644 --- a/pkg/machine/hyperv/config.go +++ b/pkg/machine/hyperv/config.go @@ -84,7 +84,7 @@ func (v HyperVVirtualization) List(opts machine.ListOptions) ([]*machine.ListRes CreatedAt: mm.Created, LastUp: mm.LastUp, Running: vm.State() == hypervctl.Enabled, - Starting: vm.IsStarting(), + Starting: mm.isStarting(), Stream: mm.ImageStream, VMType: machine.HyperVVirt.String(), CPUs: mm.CPUs, diff --git a/pkg/machine/hyperv/machine.go b/pkg/machine/hyperv/machine.go index eb7a55cd7c..f908cb892f 100644 --- a/pkg/machine/hyperv/machine.go +++ b/pkg/machine/hyperv/machine.go @@ -478,6 +478,14 @@ func (m *HyperVMachine) Start(name string, opts machine.StartOptions) error { if err != nil { return fmt.Errorf("unable to start host networking: %q", err) } + + // The "starting" status from hyper v is a very small windows and not really + // the same as what we want. so modeling starting behaviour after qemu + m.Starting = true + if err := m.writeConfig(); err != nil { + return fmt.Errorf("writing JSON file: %w", err) + } + if err := vm.Start(); err != nil { return err } @@ -486,16 +494,18 @@ func (m *HyperVMachine) Start(name string, opts machine.StartOptions) error { return err } + // set starting back false now that we are running + m.Starting = false + if m.HostUser.Modified { if machine.UpdatePodmanDockerSockService(m, name, m.UID, m.Rootful) == nil { // Reset modification state if there are no errors, otherwise ignore errors // which are already logged m.HostUser.Modified = false - _ = m.writeConfig() } } - - return nil + // Write the config with updated starting status and hostuser modification + return m.writeConfig() } func (m *HyperVMachine) State(_ bool) (machine.Status, error) { @@ -717,3 +727,7 @@ func (m *HyperVMachine) resizeDisk(newSize strongunits.GiB) error { } return nil } + +func (m *HyperVMachine) isStarting() bool { + return m.Starting +}