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 <acui@redhat.com>
This commit is contained in:
Ashley Cui
2023-09-28 14:02:48 -04:00
parent 87dd939334
commit bcfd9f3403
5 changed files with 12 additions and 23 deletions

View File

@ -206,6 +206,8 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*entities.ListReporter, error
case vm.Running: case vm.Running:
response.LastUp = "Currently running" response.LastUp = "Currently running"
response.Running = true response.Running = true
case vm.LastUp.IsZero():
response.LastUp = "Never"
default: default:
response.LastUp = units.HumanDuration(time.Since(vm.LastUp)) + " ago" response.LastUp = units.HumanDuration(time.Since(vm.LastUp)) + " ago"
} }

View File

@ -787,16 +787,7 @@ func getVMInfos() ([]*machine.ListResponse, error) {
return err return err
} }
listEntry.Running = vmState == machine.Running listEntry.Running = vmState == machine.Running
listEntry.LastUp = vm.LastUp
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
}
}
listed = append(listed, listEntry) listed = append(listed, listEntry)
} }

View File

@ -84,10 +84,16 @@ var _ = Describe("podman machine list", func() {
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run() session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(0)) 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) s := new(startMachine)
startSession, err := mb.setCmd(s).runWithoutWait() startSession, err := mb.setCmd(s).runWithoutWait()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
l := new(listMachine)
for i := 0; i < 30; i++ { for i := 0; i < 30; i++ {
listSession, err := mb.setCmd(l).run() listSession, err := mb.setCmd(l).run()
Expect(listSession).To(Exit(0)) Expect(listSession).To(Exit(0))
@ -100,7 +106,7 @@ var _ = Describe("podman machine list", func() {
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
} }
Expect(startSession).To(Exit(0)) Expect(startSession).To(Exit(0))
listSession, err := mb.setCmd(l).run() listSession, err = mb.setCmd(l).run()
Expect(listSession).To(Exit(0)) Expect(listSession).To(Exit(0))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(listSession.outputToString()).To(ContainSubstring("Currently running")) Expect(listSession.outputToString()).To(ContainSubstring("Currently running"))

View File

@ -204,16 +204,7 @@ func getVMInfos() ([]*machine.ListResponse, error) {
return err return err
} }
listEntry.Running = state == machine.Running listEntry.Running = state == machine.Running
listEntry.LastUp = vm.LastUp
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
}
}
listed = append(listed, listEntry) listed = append(listed, listEntry)
} }

View File

@ -46,7 +46,6 @@ func (p *WSLVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, er
} }
vm.Created = time.Now() vm.Created = time.Now()
vm.LastUp = vm.Created
// Default is false // Default is false
if opts.UserModeNetworking != nil { if opts.UserModeNetworking != nil {