mirror of
https://github.com/containers/podman.git
synced 2025-06-24 03:08:13 +08:00
hyperV: Update lastUp time
LastUp now correctly reports the lastUp time for podman machine on hyperv, for both inspect and list. Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
@ -2,6 +2,7 @@ package e2e_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -32,6 +33,7 @@ var _ = Describe("podman machine stop", func() {
|
||||
It("Stop running machine", func() {
|
||||
name := randomString()
|
||||
i := new(initMachine)
|
||||
starttime := time.Now()
|
||||
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withNow()).run()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(session).To(Exit(0))
|
||||
@ -46,5 +48,14 @@ var _ = Describe("podman machine stop", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(stopAgain).To(Exit((0)))
|
||||
Expect(stopAgain.outputToString()).To(ContainSubstring(fmt.Sprintf("Machine \"%s\" stopped successfully", name)))
|
||||
|
||||
// Stopping a machine should update the last up time
|
||||
inspect := new(inspectMachine)
|
||||
inspectSession, err := mb.setName(name).setCmd(inspect.withFormat("{{.LastUp.Format \"2006-01-02T15:04:05Z07:00\"}}")).run()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(inspectSession).To(Exit(0))
|
||||
lastupTime, err := time.Parse(time.RFC3339, inspectSession.outputToString())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(lastupTime).To(BeTemporally(">", starttime))
|
||||
})
|
||||
})
|
||||
|
@ -605,8 +605,13 @@ func (m *HyperVMachine) Stop(name string, opts machine.StopOptions) error {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
return vm.Stop()
|
||||
if err := vm.Stop(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// keep track of last up
|
||||
m.LastUp = time.Now()
|
||||
return m.writeConfig()
|
||||
}
|
||||
|
||||
func (m *HyperVMachine) jsonConfigPath() (string, error) {
|
||||
@ -660,7 +665,6 @@ func (m *HyperVMachine) loadFromFile() (*HyperVMachine, error) {
|
||||
if cfg.Hardware.Memory > 0 {
|
||||
mm.Memory = uint64(cfg.Hardware.Memory)
|
||||
}
|
||||
mm.LastUp = cfg.Status.LastUp
|
||||
|
||||
return &mm, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user