Merge pull request #21671 from mheon/e2e_stop_helper

Add a helper for stopping pods and containers in E2E
This commit is contained in:
openshift-merge-bot[bot]
2024-02-15 18:03:56 +00:00
committed by GitHub
13 changed files with 37 additions and 75 deletions

View File

@ -142,16 +142,7 @@ var _ = Describe("Podman checkpoint", func() {
Expect(inspectOut[0].State.CheckpointLog).To(ContainSubstring("userdata/dump.log")) Expect(inspectOut[0].State.CheckpointLog).To(ContainSubstring("userdata/dump.log"))
Expect(inspectOut[0].State.RestoreLog).To(ContainSubstring("userdata/restore.log")) Expect(inspectOut[0].State.RestoreLog).To(ContainSubstring("userdata/restore.log"))
result = podmanTest.Podman([]string{ podmanTest.StopContainer(cid)
"container",
"stop",
"--timeout",
"0",
cid,
})
result.WaitWithDefaultTimeout()
Expect(result).Should(ExitCleanly())
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
result = podmanTest.Podman([]string{ result = podmanTest.Podman([]string{
@ -416,10 +407,7 @@ var _ = Describe("Podman checkpoint", func() {
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
// Stop the container // Stop the container
result = podmanTest.Podman([]string{"container", "stop", cid}) podmanTest.StopContainer(cid)
result.WaitWithDefaultTimeout()
Expect(result).Should(ExitCleanly())
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited"))

View File

@ -454,6 +454,19 @@ func (p *PodmanTestIntegration) InspectContainer(name string) []define.InspectCo
return session.InspectContainerToJSON() return session.InspectContainerToJSON()
} }
// StopContainer stops a container with no timeout, ensuring a fast test.
func (p *PodmanTestIntegration) StopContainer(nameOrID string) {
stop := p.Podman([]string{"stop", "-t0", nameOrID})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
}
func (p *PodmanTestIntegration) StopPod(nameOrID string) {
stop := p.Podman([]string{"pod", "stop", "-t0", nameOrID})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
}
func processTestResult(r SpecReport) { func processTestResult(r SpecReport) {
tr := testResult{length: r.RunTime.Seconds(), name: r.FullText()} tr := testResult{length: r.RunTime.Seconds(), name: r.FullText()}
_, err := timingsFile.WriteString(fmt.Sprintf("%s\t\t%f\n", tr.name, tr.length)) _, err := timingsFile.WriteString(fmt.Sprintf("%s\t\t%f\n", tr.name, tr.length))

View File

@ -87,10 +87,10 @@ var _ = Describe("Podman events", func() {
It("podman events with a type", func() { It("podman events with a type", func() {
setup := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:foobarpod", ALPINE, "top"}) setup := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:foobarpod", ALPINE, "top"})
setup.WaitWithDefaultTimeout() setup.WaitWithDefaultTimeout()
stop := podmanTest.Podman([]string{"pod", "stop", "-t0", "foobarpod"})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
Expect(setup).Should(ExitCleanly()) Expect(setup).Should(ExitCleanly())
podmanTest.StopPod("foobarpod")
result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "type=pod", "--filter", "pod=foobarpod"}) result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "type=pod", "--filter", "pod=foobarpod"})
result.WaitWithDefaultTimeout() result.WaitWithDefaultTimeout()
Expect(result).Should(ExitCleanly()) Expect(result).Should(ExitCleanly())

View File

@ -524,9 +524,7 @@ RUN useradd -u 1000 auser`, fedoraMinimal)
// Ensure that stop with a running detached exec session is // Ensure that stop with a running detached exec session is
// clean. // clean.
stop := podmanTest.Podman([]string{"stop", ctrName}) podmanTest.StopContainer(ctrName)
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
}) })
It("podman exec with env var secret", func() { It("podman exec with env var secret", func() {

View File

@ -282,9 +282,7 @@ var _ = Describe("Podman healthcheck run", func() {
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
stop := podmanTest.Podman([]string{"stop", "-t0", "hc"}) podmanTest.StopContainer("hc")
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
startAgain := podmanTest.Podman([]string{"start", "hc"}) startAgain := podmanTest.Podman([]string{"start", "hc"})
startAgain.WaitWithDefaultTimeout() startAgain.WaitWithDefaultTimeout()

View File

@ -179,9 +179,7 @@ var _ = Describe("Podman mount", func() {
Expect(lmount).Should(ExitCleanly()) Expect(lmount).Should(ExitCleanly())
Expect(lmount.OutputToString()).To(ContainSubstring(cid)) Expect(lmount.OutputToString()).To(ContainSubstring(cid))
stop := podmanTest.Podman([]string{"stop", cid}) podmanTest.StopContainer(cid)
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
lmount = podmanTest.Podman([]string{"mount", "--no-trunc"}) lmount = podmanTest.Podman([]string{"mount", "--no-trunc"})
lmount.WaitWithDefaultTimeout() lmount.WaitWithDefaultTimeout()

View File

@ -94,9 +94,7 @@ var _ = Describe("Podman init containers", func() {
// Expect(check).Should(Exit(1)) // Expect(check).Should(Exit(1))
Expect(check.ExitCode()).To(Equal(1), "I dont understand why the other way does not work") Expect(check.ExitCode()).To(Equal(1), "I dont understand why the other way does not work")
// Let's double check with a stop and start // Let's double check with a stop and start
stopPod := podmanTest.Podman([]string{"pod", "stop", "foobar"}) podmanTest.StopPod("foobar")
stopPod.WaitWithDefaultTimeout()
Expect(stopPod).Should(ExitCleanly())
startPod := podmanTest.Podman([]string{"pod", "start", "foobar"}) startPod := podmanTest.Podman([]string{"pod", "start", "foobar"})
startPod.WaitWithDefaultTimeout() startPod.WaitWithDefaultTimeout()
Expect(startPod).Should(ExitCleanly()) Expect(startPod).Should(ExitCleanly())
@ -129,9 +127,7 @@ var _ = Describe("Podman init containers", func() {
Expect(checkLog).Should(ExitCleanly()) Expect(checkLog).Should(ExitCleanly())
// Stop and start the pod // Stop and start the pod
stopPod := podmanTest.Podman([]string{"pod", "stop", "foobar"}) podmanTest.StopPod("foobar")
stopPod.WaitWithDefaultTimeout()
Expect(stopPod).Should(ExitCleanly())
startPod := podmanTest.Podman([]string{"pod", "start", "foobar"}) startPod := podmanTest.Podman([]string{"pod", "start", "foobar"})
startPod.WaitWithDefaultTimeout() startPod.WaitWithDefaultTimeout()
Expect(startPod).Should(ExitCleanly()) Expect(startPod).Should(ExitCleanly())

View File

@ -34,9 +34,7 @@ var _ = Describe("Podman prune", func() {
Expect(top).Should(ExitCleanly()) Expect(top).Should(ExitCleanly())
cid := top.OutputToString() cid := top.OutputToString()
stop := podmanTest.Podman([]string{"stop", cid}) podmanTest.StopContainer(cid)
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
prune := podmanTest.Podman([]string{"container", "prune", "-f"}) prune := podmanTest.Podman([]string{"container", "prune", "-f"})
prune.WaitWithDefaultTimeout() prune.WaitWithDefaultTimeout()
@ -220,9 +218,7 @@ var _ = Describe("Podman prune", func() {
session = podmanTest.Podman([]string{"pod", "start", podid1}) session = podmanTest.Podman([]string{"pod", "start", podid1})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"pod", "stop", "-t0", podid1}) podmanTest.StopPod(podid1)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
pods := podmanTest.Podman([]string{"pod", "ps"}) pods := podmanTest.Podman([]string{"pod", "ps"})
pods.WaitWithDefaultTimeout() pods.WaitWithDefaultTimeout()
@ -293,9 +289,7 @@ var _ = Describe("Podman prune", func() {
session = podmanTest.Podman([]string{"pod", "start", podid1}) session = podmanTest.Podman([]string{"pod", "start", podid1})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"pod", "stop", "-t0", podid1}) podmanTest.StopPod(podid1)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
// Create a container. This container should be pruned. // Create a container. This container should be pruned.
create := podmanTest.Podman([]string{"create", "--name", "test", BB}) create := podmanTest.Podman([]string{"create", "--name", "test", BB})
@ -325,9 +319,7 @@ var _ = Describe("Podman prune", func() {
session = podmanTest.Podman([]string{"pod", "start", podid1}) session = podmanTest.Podman([]string{"pod", "start", podid1})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"pod", "stop", "-t0", podid1}) podmanTest.StopPod(podid1)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
// Start a pod and leave it running // Start a pod and leave it running
session = podmanTest.Podman([]string{"pod", "create"}) session = podmanTest.Podman([]string{"pod", "create"})
@ -403,10 +395,7 @@ var _ = Describe("Podman prune", func() {
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"pod", "stop", podid1}) podmanTest.StopPod(podid1)
session.WaitWithDefaultTimeout()
// FIXME - #20196: Cannot use ExitCleanly()
Expect(session).Should(Exit(0))
// Create a container. This container should be pruned. // Create a container. This container should be pruned.
create := podmanTest.Podman([]string{"create", "--name", "test", BB}) create := podmanTest.Podman([]string{"create", "--name", "test", BB})

View File

@ -222,9 +222,7 @@ var _ = Describe("Podman restart", func() {
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))
session = podmanTest.Podman([]string{"stop", "--all"}) podmanTest.StopContainer("--all")
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
session = podmanTest.Podman([]string{"restart", "--all"}) session = podmanTest.Podman([]string{"restart", "--all"})

View File

@ -26,9 +26,7 @@ var _ = Describe("Podman run exit", func() {
Expect(pmount).Should(ExitCleanly()) Expect(pmount).Should(ExitCleanly())
Expect(pmount.OutputToString()).To(ContainSubstring(cid)) Expect(pmount.OutputToString()).To(ContainSubstring(cid))
stop := podmanTest.Podman([]string{"stop", cid}) podmanTest.StopContainer(cid)
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
// We have to force cleanup so the unmount happens // We have to force cleanup so the unmount happens
podmanCleanupSession := podmanTest.Podman([]string{"container", "cleanup", cid}) podmanCleanupSession := podmanTest.Podman([]string{"container", "cleanup", cid})
@ -69,9 +67,7 @@ var _ = Describe("Podman run exit", func() {
Expect(pmount).Should(ExitCleanly()) Expect(pmount).Should(ExitCleanly())
Expect(pmount.OutputToString()).To(ContainSubstring(cid)) Expect(pmount.OutputToString()).To(ContainSubstring(cid))
stop := podmanTest.Podman([]string{"stop", cid}) podmanTest.StopContainer(cid)
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
// We have to force cleanup so the unmount happens // We have to force cleanup so the unmount happens
podmanCleanupSession := podmanTest.Podman([]string{"container", "cleanup", cid}) podmanCleanupSession := podmanTest.Podman([]string{"container", "cleanup", cid})

View File

@ -302,9 +302,7 @@ var _ = Describe("Podman run", func() {
Expect(osession).Should(ExitCleanly()) Expect(osession).Should(ExitCleanly())
Expect(osession.OutputToString()).To(Equal("hello")) Expect(osession.OutputToString()).To(Equal("hello"))
osession = podmanTest.Podman([]string{"stop", "overlay-foo"}) podmanTest.StopContainer("overlay-foo")
osession.WaitWithDefaultTimeout()
Expect(osession).Should(ExitCleanly())
startsession := podmanTest.Podman([]string{"start", "--attach", "overlay-foo"}) startsession := podmanTest.Podman([]string{"start", "--attach", "overlay-foo"})
startsession.WaitWithDefaultTimeout() startsession.WaitWithDefaultTimeout()
@ -1541,9 +1539,7 @@ VOLUME %s`, ALPINE, volPath, volPath)
ctr.WaitWithDefaultTimeout() ctr.WaitWithDefaultTimeout()
Expect(ctr).Should(ExitCleanly()) Expect(ctr).Should(ExitCleanly())
stop := podmanTest.Podman([]string{"stop", "-t0", ctrName}) podmanTest.StopContainer(ctrName)
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
// This is ugly, but I don't see a better way // This is ugly, but I don't see a better way
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
@ -2093,9 +2089,7 @@ WORKDIR /madethis`, BB)
mainContainer.WaitWithDefaultTimeout() mainContainer.WaitWithDefaultTimeout()
Expect(mainContainer).Should(ExitCleanly()) Expect(mainContainer).Should(ExitCleanly())
stop := podmanTest.Podman([]string{"stop", "--all"}) podmanTest.StopContainer("--all")
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
start := podmanTest.Podman([]string{"start", mainName}) start := podmanTest.Podman([]string{"start", mainName})
start.WaitWithDefaultTimeout() start.WaitWithDefaultTimeout()

View File

@ -386,9 +386,7 @@ var _ = Describe("Podman run with volumes", func() {
Expect(mountOut2).To(ContainSubstring(volName)) Expect(mountOut2).To(ContainSubstring(volName))
// Stop the container to unmount // Stop the container to unmount
podmanStopSession := podmanTest.Podman([]string{"stop", "--time", "0", ctrName}) podmanTest.StopContainer(ctrName)
podmanStopSession.WaitWithDefaultTimeout()
Expect(podmanStopSession).Should(ExitCleanly())
// We have to force cleanup so the unmount happens // We have to force cleanup so the unmount happens
podmanCleanupSession := podmanTest.Podman([]string{"container", "cleanup", ctrName}) podmanCleanupSession := podmanTest.Podman([]string{"container", "cleanup", ctrName})
@ -675,9 +673,7 @@ VOLUME /test/`, ALPINE)
session = podmanTest.Podman([]string{"exec", "-l", "ls", "/run/test/container"}) session = podmanTest.Podman([]string{"exec", "-l", "ls", "/run/test/container"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"stop", "-l"}) podmanTest.StopContainer("-l")
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"start", "-l"}) session = podmanTest.Podman([]string{"start", "-l"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())

View File

@ -140,9 +140,7 @@ var _ = Describe("Podman volume plugins", func() {
Expect(arrOutput).To(HaveLen(1)) Expect(arrOutput).To(HaveLen(1))
Expect(arrOutput[0]).To(ContainSubstring(volName)) Expect(arrOutput[0]).To(ContainSubstring(volName))
stop := podmanTest.Podman([]string{"stop", "--timeout", "0", ctrName}) podmanTest.StopContainer(ctrName)
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
// Remove should exit non-zero because missing plugin // Remove should exit non-zero because missing plugin
remove := podmanTest.Podman([]string{"volume", "rm", volName}) remove := podmanTest.Podman([]string{"volume", "rm", volName})