From bcfd9f3403099b785c0b3a8a99ef52de706f67e0 Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Thu, 28 Sep 2023 14:02:48 -0400 Subject: [PATCH] New machines should show Never as LastUp After creating a podman machine, and before starting it, the LastUp value for podman machine ls should display Never. Previously, the LastUp value was the same as creation time. This also changes the LastUp value for inspect to ZeroTime instead of creation time. Signed-off-by: Ashley Cui --- cmd/podman/machine/list.go | 2 ++ pkg/machine/applehv/machine.go | 11 +---------- pkg/machine/e2e/list_test.go | 10 ++++++++-- pkg/machine/qemu/config.go | 11 +---------- pkg/machine/wsl/config.go | 1 - 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/cmd/podman/machine/list.go b/cmd/podman/machine/list.go index a6d5013c93..beac82edce 100644 --- a/cmd/podman/machine/list.go +++ b/cmd/podman/machine/list.go @@ -206,6 +206,8 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*entities.ListReporter, error case vm.Running: response.LastUp = "Currently running" response.Running = true + case vm.LastUp.IsZero(): + response.LastUp = "Never" default: response.LastUp = units.HumanDuration(time.Since(vm.LastUp)) + " ago" } diff --git a/pkg/machine/applehv/machine.go b/pkg/machine/applehv/machine.go index f41aa948eb..9777060c9d 100644 --- a/pkg/machine/applehv/machine.go +++ b/pkg/machine/applehv/machine.go @@ -787,16 +787,7 @@ func getVMInfos() ([]*machine.ListResponse, error) { return err } listEntry.Running = vmState == machine.Running - - if !vm.LastUp.IsZero() { // this means we have already written a time to the config - listEntry.LastUp = vm.LastUp - } else { // else we just created the machine AKA last up = created time - listEntry.LastUp = vm.Created - vm.LastUp = listEntry.LastUp - if err := vm.writeConfig(); err != nil { - return err - } - } + listEntry.LastUp = vm.LastUp listed = append(listed, listEntry) } diff --git a/pkg/machine/e2e/list_test.go b/pkg/machine/e2e/list_test.go index 272ddf692c..2c94a8582c 100644 --- a/pkg/machine/e2e/list_test.go +++ b/pkg/machine/e2e/list_test.go @@ -84,10 +84,16 @@ var _ = Describe("podman machine list", func() { session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).ToNot(HaveOccurred()) Expect(session).To(Exit(0)) + + l := new(listMachine) + listSession, err := mb.setCmd(l.withFormat("{{.LastUp}}")).run() + Expect(err).NotTo(HaveOccurred()) + Expect(listSession).To(Exit(0)) + Expect(listSession.outputToString()).To(Equal("Never")) + s := new(startMachine) startSession, err := mb.setCmd(s).runWithoutWait() Expect(err).ToNot(HaveOccurred()) - l := new(listMachine) for i := 0; i < 30; i++ { listSession, err := mb.setCmd(l).run() Expect(listSession).To(Exit(0)) @@ -100,7 +106,7 @@ var _ = Describe("podman machine list", func() { time.Sleep(3 * time.Second) } Expect(startSession).To(Exit(0)) - listSession, err := mb.setCmd(l).run() + listSession, err = mb.setCmd(l).run() Expect(listSession).To(Exit(0)) Expect(err).ToNot(HaveOccurred()) Expect(listSession.outputToString()).To(ContainSubstring("Currently running")) diff --git a/pkg/machine/qemu/config.go b/pkg/machine/qemu/config.go index 632848bd07..b1a84964f0 100644 --- a/pkg/machine/qemu/config.go +++ b/pkg/machine/qemu/config.go @@ -204,16 +204,7 @@ func getVMInfos() ([]*machine.ListResponse, error) { return err } listEntry.Running = state == machine.Running - - if !vm.LastUp.IsZero() { // this means we have already written a time to the config - listEntry.LastUp = vm.LastUp - } else { // else we just created the machine AKA last up = created time - listEntry.LastUp = vm.Created - vm.LastUp = listEntry.LastUp - if err := vm.writeConfig(); err != nil { - return err - } - } + listEntry.LastUp = vm.LastUp listed = append(listed, listEntry) } diff --git a/pkg/machine/wsl/config.go b/pkg/machine/wsl/config.go index 8d3b95d1d2..5e158a2fe2 100644 --- a/pkg/machine/wsl/config.go +++ b/pkg/machine/wsl/config.go @@ -46,7 +46,6 @@ func (p *WSLVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, er } vm.Created = time.Now() - vm.LastUp = vm.Created // Default is false if opts.UserModeNetworking != nil {