summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcdoern <cbdoer23@g.holycross.edu>2022-04-12 22:21:33 -0400
committerMatthew Heon <matthew.heon@pm.me>2022-05-03 13:41:06 -0400
commit07bc615b491836e88a331f8ab6e2ffdf34bc6905 (patch)
treee213570f594f668fb2371d46130f7072d48c755b
parent66500b82a645428e1a59ce25fda1b76965df21cf (diff)
downloadpodman-07bc615b491836e88a331f8ab6e2ffdf34bc6905.tar.gz
podman-07bc615b491836e88a331f8ab6e2ffdf34bc6905.tar.bz2
podman-07bc615b491836e88a331f8ab6e2ffdf34bc6905.zip
podman machine starting test
add a test to make sure machines are not running while still starting in order to do this, I added a parameter to `run()` to delineate whether or not the command should block or not. The non blocking run allows for tests to get and use the `machineSession` pointer and check the exit code to see if it has finished. also fix a bug (created by #13996) that before started, the machines would always say "LastUp" and "Created" Less than one second ago Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
-rw-r--r--pkg/machine/e2e/config.go16
-rw-r--r--pkg/machine/e2e/list_test.go27
-rw-r--r--pkg/machine/qemu/machine.go6
3 files changed, 41 insertions, 8 deletions
diff --git a/pkg/machine/e2e/config.go b/pkg/machine/e2e/config.go
index 7d75ca6bc..c17b840d3 100644
--- a/pkg/machine/e2e/config.go
+++ b/pkg/machine/e2e/config.go
@@ -131,7 +131,7 @@ func (m *machineTestBuilder) setTimeout(timeout time.Duration) *machineTestBuild
func (mb *machineTestBuilder) toQemuInspectInfo() ([]qemuMachineInspectInfo, int, error) {
args := []string{"machine", "inspect"}
args = append(args, mb.names...)
- session, err := runWrapper(mb.podmanBinary, args, defaultTimeout)
+ session, err := runWrapper(mb.podmanBinary, args, defaultTimeout, true)
if err != nil {
return nil, -1, err
}
@@ -140,11 +140,15 @@ func (mb *machineTestBuilder) toQemuInspectInfo() ([]qemuMachineInspectInfo, int
return mii, session.ExitCode(), err
}
+func (m *machineTestBuilder) runWithoutWait() (*machineSession, error) {
+ return runWrapper(m.podmanBinary, m.cmd, m.timeout, false)
+}
+
func (m *machineTestBuilder) run() (*machineSession, error) {
- return runWrapper(m.podmanBinary, m.cmd, m.timeout)
+ return runWrapper(m.podmanBinary, m.cmd, m.timeout, true)
}
-func runWrapper(podmanBinary string, cmdArgs []string, timeout time.Duration) (*machineSession, error) {
+func runWrapper(podmanBinary string, cmdArgs []string, timeout time.Duration, wait bool) (*machineSession, error) {
if len(os.Getenv("DEBUG")) > 0 {
cmdArgs = append([]string{"--log-level=debug"}, cmdArgs...)
}
@@ -156,8 +160,10 @@ func runWrapper(podmanBinary string, cmdArgs []string, timeout time.Duration) (*
return nil, err
}
ms := machineSession{session}
- ms.waitWithTimeout(timeout)
- fmt.Println("output:", ms.outputToString())
+ if wait {
+ ms.waitWithTimeout(timeout)
+ fmt.Println("output:", ms.outputToString())
+ }
return &ms, nil
}
diff --git a/pkg/machine/e2e/list_test.go b/pkg/machine/e2e/list_test.go
index e7a439945..0ce9063f9 100644
--- a/pkg/machine/e2e/list_test.go
+++ b/pkg/machine/e2e/list_test.go
@@ -70,6 +70,33 @@ var _ = Describe("podman machine list", func() {
Expect(util.StringInSlice(name1, listNames)).To(BeTrue())
Expect(util.StringInSlice(name2, listNames)).To(BeTrue())
})
+
+ It("list machine: check if running while starting", func() {
+ i := new(initMachine)
+ session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
+ Expect(err).To(BeNil())
+ Expect(session).To(Exit(0))
+ s := new(startMachine)
+ startSession, err := mb.setCmd(s).runWithoutWait()
+ Expect(err).To(BeNil())
+ l := new(listMachine)
+ for { // needs to be infinite because we need to check if running when inspect returns to avoid race conditions.
+ listSession, err := mb.setCmd(l).run()
+ Expect(listSession).To(Exit(0))
+ Expect(err).To(BeNil())
+ if startSession.ExitCode() == -1 {
+ Expect(listSession.outputToString()).NotTo(ContainSubstring("Currently running"))
+ } else {
+ break
+ }
+ }
+ Expect(startSession).To(Exit(0))
+ listSession, err := mb.setCmd(l).run()
+ Expect(listSession).To(Exit(0))
+ Expect(err).To(BeNil())
+ Expect(listSession.outputToString()).To(ContainSubstring("Currently running"))
+ Expect(listSession.outputToString()).NotTo(ContainSubstring("Less than a second ago")) // check to make sure time created is accurate
+ })
})
func stripAsterisk(sl []string) {
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index ccfad90f7..30e64e44e 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -1066,11 +1066,11 @@ func getVMInfos() ([]*machine.ListResponse, error) {
return err
}
- if !vm.LastUp.IsZero() {
+ if !vm.LastUp.IsZero() { // this means we have already written a time to the config
listEntry.LastUp = vm.LastUp
- } else {
+ } else { // else we just created the machine AKA last up = created time
listEntry.LastUp = vm.Created
- vm.Created = time.Now()
+ vm.LastUp = listEntry.LastUp
if err := vm.writeConfig(); err != nil {
return err
}