mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
Merge pull request #3360 from baude/fixporttesttiming
fix port -l timing with healthchecks
This commit is contained in:
@ -10,6 +10,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/shared"
|
"github.com/containers/libpod/cmd/podman/shared"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
@ -22,6 +23,7 @@ import (
|
|||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/onsi/gomega/gexec"
|
"github.com/onsi/gomega/gexec"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -367,6 +369,18 @@ func (p *PodmanTestIntegration) RunLsContainer(name string) (*PodmanSessionInteg
|
|||||||
return session, session.ExitCode(), session.OutputToString()
|
return session, session.ExitCode(), session.OutputToString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunNginxWithHealthCheck runs the alpine nginx container with an optional name and adds a healthcheck into it
|
||||||
|
func (p *PodmanTestIntegration) RunNginxWithHealthCheck(name string) (*PodmanSessionIntegration, string) {
|
||||||
|
var podmanArgs = []string{"run"}
|
||||||
|
if name != "" {
|
||||||
|
podmanArgs = append(podmanArgs, "--name", name)
|
||||||
|
}
|
||||||
|
podmanArgs = append(podmanArgs, "-dt", "-P", "--healthcheck-command", "CMD-SHELL curl http://localhost/", nginx)
|
||||||
|
session := p.Podman(podmanArgs)
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
return session, session.OutputToString()
|
||||||
|
}
|
||||||
|
|
||||||
func (p *PodmanTestIntegration) RunLsContainerInPod(name, pod string) (*PodmanSessionIntegration, int, string) {
|
func (p *PodmanTestIntegration) RunLsContainerInPod(name, pod string) (*PodmanSessionIntegration, int, string) {
|
||||||
var podmanArgs = []string{"run", "--pod", pod}
|
var podmanArgs = []string{"run", "--pod", pod}
|
||||||
if name != "" {
|
if name != "" {
|
||||||
@ -508,3 +522,16 @@ func (p *PodmanTestIntegration) ImageExistsInMainStore(idOrName string) bool {
|
|||||||
results.WaitWithDefaultTimeout()
|
results.WaitWithDefaultTimeout()
|
||||||
return Expect(results.ExitCode()).To(Equal(0))
|
return Expect(results.ExitCode()).To(Equal(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PodmanTestIntegration) RunHealthCheck(cid string) error {
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
hc := p.Podman([]string{"healthcheck", "run", cid})
|
||||||
|
hc.WaitWithDefaultTimeout()
|
||||||
|
if hc.ExitCode() == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
fmt.Printf("Waiting for %s to pass healthcheck\n", cid)
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
return errors.Errorf("unable to detect %s as running", cid)
|
||||||
|
}
|
||||||
|
@ -49,10 +49,13 @@ var _ = Describe("Podman port", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman port -l nginx", func() {
|
It("podman port -l nginx", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "-dt", "-P", nginx})
|
session, cid := podmanTest.RunNginxWithHealthCheck("")
|
||||||
session.WaitWithDefaultTimeout()
|
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
if err := podmanTest.RunHealthCheck(cid); err != nil {
|
||||||
|
Fail(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"port", "-l"})
|
result := podmanTest.Podman([]string{"port", "-l"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result.ExitCode()).To(Equal(0))
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
@ -61,10 +64,13 @@ var _ = Describe("Podman port", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman container port -l nginx", func() {
|
It("podman container port -l nginx", func() {
|
||||||
session := podmanTest.Podman([]string{"container", "run", "-dt", "-P", nginx})
|
session, cid := podmanTest.RunNginxWithHealthCheck("")
|
||||||
session.WaitWithDefaultTimeout()
|
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
if err := podmanTest.RunHealthCheck(cid); err != nil {
|
||||||
|
Fail(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"container", "port", "-l"})
|
result := podmanTest.Podman([]string{"container", "port", "-l"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result.ExitCode()).To(Equal(0))
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
@ -73,10 +79,13 @@ var _ = Describe("Podman port", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman port -l port nginx", func() {
|
It("podman port -l port nginx", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "-dt", "-P", nginx})
|
session, cid := podmanTest.RunNginxWithHealthCheck("")
|
||||||
session.WaitWithDefaultTimeout()
|
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
if err := podmanTest.RunHealthCheck(cid); err != nil {
|
||||||
|
Fail(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"port", "-l", "80"})
|
result := podmanTest.Podman([]string{"port", "-l", "80"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result.ExitCode()).To(Equal(0))
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
@ -85,10 +94,13 @@ var _ = Describe("Podman port", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman port -a nginx", func() {
|
It("podman port -a nginx", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "-dt", "-P", nginx})
|
session, cid := podmanTest.RunNginxWithHealthCheck("")
|
||||||
session.WaitWithDefaultTimeout()
|
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
if err := podmanTest.RunHealthCheck(cid); err != nil {
|
||||||
|
Fail(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"port", "-a"})
|
result := podmanTest.Podman([]string{"port", "-a"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result.ExitCode()).To(Equal(0))
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
|
Reference in New Issue
Block a user