Merge pull request #14024 from cdoern/machine

podman machine starting test
This commit is contained in:
OpenShift Merge Robot 2022-04-28 13:59:23 -04:00 committed by GitHub
commit b2725024f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 9 deletions

View File

@ -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) run() (*machineSession, error) {
return runWrapper(m.podmanBinary, m.cmd, m.timeout)
func (m *machineTestBuilder) runWithoutWait() (*machineSession, error) {
return runWrapper(m.podmanBinary, m.cmd, m.timeout, false)
}
func runWrapper(podmanBinary string, cmdArgs []string, timeout time.Duration) (*machineSession, error) {
func (m *machineTestBuilder) run() (*machineSession, error) {
return runWrapper(m.podmanBinary, m.cmd, m.timeout, true)
}
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
}

View File

@ -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) {

View File

@ -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
}