Skip to content

Commit

Permalink
Merge pull request #20412 from ashley-cui/lastup
Browse files Browse the repository at this point in the history
hyperV: Update lastUp time
  • Loading branch information
openshift-ci[bot] authored Oct 21, 2023
2 parents 8022d69 + d6f44d9 commit 3661c87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions pkg/machine/e2e/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e_test

import (
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -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))
Expand All @@ -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))
})
})
8 changes: 6 additions & 2 deletions pkg/machine/hyperv/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 3661c87

Please sign in to comment.