Skip to content

Commit

Permalink
Merge pull request #21671 from mheon/e2e_stop_helper
Browse files Browse the repository at this point in the history
Add a helper for stopping pods and containers in E2E
  • Loading branch information
openshift-merge-bot[bot] authored Feb 15, 2024
2 parents bbd4476 + 3ca2213 commit c84bb81
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 75 deletions.
16 changes: 2 additions & 14 deletions test/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,7 @@ var _ = Describe("Podman checkpoint", func() {
Expect(inspectOut[0].State.CheckpointLog).To(ContainSubstring("userdata/dump.log"))
Expect(inspectOut[0].State.RestoreLog).To(ContainSubstring("userdata/restore.log"))

result = podmanTest.Podman([]string{
"container",
"stop",
"--timeout",
"0",
cid,
})
result.WaitWithDefaultTimeout()

Expect(result).Should(ExitCleanly())
podmanTest.StopContainer(cid)
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))

result = podmanTest.Podman([]string{
Expand Down Expand Up @@ -416,10 +407,7 @@ var _ = Describe("Podman checkpoint", func() {
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))

// Stop the container
result = podmanTest.Podman([]string{"container", "stop", cid})
result.WaitWithDefaultTimeout()

Expect(result).Should(ExitCleanly())
podmanTest.StopContainer(cid)
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited"))

Expand Down
13 changes: 13 additions & 0 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,19 @@ func (p *PodmanTestIntegration) InspectContainer(name string) []define.InspectCo
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) {
tr := testResult{length: r.RunTime.Seconds(), name: r.FullText()}
_, err := timingsFile.WriteString(fmt.Sprintf("%s\t\t%f\n", tr.name, tr.length))
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ var _ = Describe("Podman events", func() {
It("podman events with a type", func() {
setup := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:foobarpod", ALPINE, "top"})
setup.WaitWithDefaultTimeout()
stop := podmanTest.Podman([]string{"pod", "stop", "-t0", "foobarpod"})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
Expect(setup).Should(ExitCleanly())

podmanTest.StopPod("foobarpod")

result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "type=pod", "--filter", "pod=foobarpod"})
result.WaitWithDefaultTimeout()
Expect(result).Should(ExitCleanly())
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,7 @@ RUN useradd -u 1000 auser`, fedoraMinimal)

// Ensure that stop with a running detached exec session is
// clean.
stop := podmanTest.Podman([]string{"stop", ctrName})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
podmanTest.StopContainer(ctrName)
})

It("podman exec with env var secret", func() {
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/healthcheck_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ var _ = Describe("Podman healthcheck run", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())

stop := podmanTest.Podman([]string{"stop", "-t0", "hc"})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
podmanTest.StopContainer("hc")

startAgain := podmanTest.Podman([]string{"start", "hc"})
startAgain.WaitWithDefaultTimeout()
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ var _ = Describe("Podman mount", func() {
Expect(lmount).Should(ExitCleanly())
Expect(lmount.OutputToString()).To(ContainSubstring(cid))

stop := podmanTest.Podman([]string{"stop", cid})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
podmanTest.StopContainer(cid)

lmount = podmanTest.Podman([]string{"mount", "--no-trunc"})
lmount.WaitWithDefaultTimeout()
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/pod_initcontainers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ var _ = Describe("Podman init containers", func() {
// Expect(check).Should(Exit(1))
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
stopPod := podmanTest.Podman([]string{"pod", "stop", "foobar"})
stopPod.WaitWithDefaultTimeout()
Expect(stopPod).Should(ExitCleanly())
podmanTest.StopPod("foobar")
startPod := podmanTest.Podman([]string{"pod", "start", "foobar"})
startPod.WaitWithDefaultTimeout()
Expect(startPod).Should(ExitCleanly())
Expand Down Expand Up @@ -129,9 +127,7 @@ var _ = Describe("Podman init containers", func() {
Expect(checkLog).Should(ExitCleanly())

// Stop and start the pod
stopPod := podmanTest.Podman([]string{"pod", "stop", "foobar"})
stopPod.WaitWithDefaultTimeout()
Expect(stopPod).Should(ExitCleanly())
podmanTest.StopPod("foobar")
startPod := podmanTest.Podman([]string{"pod", "start", "foobar"})
startPod.WaitWithDefaultTimeout()
Expect(startPod).Should(ExitCleanly())
Expand Down
21 changes: 5 additions & 16 deletions test/e2e/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ var _ = Describe("Podman prune", func() {
Expect(top).Should(ExitCleanly())
cid := top.OutputToString()

stop := podmanTest.Podman([]string{"stop", cid})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
podmanTest.StopContainer(cid)

prune := podmanTest.Podman([]string{"container", "prune", "-f"})
prune.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -220,9 +218,7 @@ var _ = Describe("Podman prune", func() {
session = podmanTest.Podman([]string{"pod", "start", podid1})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"pod", "stop", "-t0", podid1})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
podmanTest.StopPod(podid1)

pods := podmanTest.Podman([]string{"pod", "ps"})
pods.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -293,9 +289,7 @@ var _ = Describe("Podman prune", func() {
session = podmanTest.Podman([]string{"pod", "start", podid1})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"pod", "stop", "-t0", podid1})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
podmanTest.StopPod(podid1)

// Create a container. This container should be pruned.
create := podmanTest.Podman([]string{"create", "--name", "test", BB})
Expand Down Expand Up @@ -325,9 +319,7 @@ var _ = Describe("Podman prune", func() {
session = podmanTest.Podman([]string{"pod", "start", podid1})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"pod", "stop", "-t0", podid1})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
podmanTest.StopPod(podid1)

// Start a pod and leave it running
session = podmanTest.Podman([]string{"pod", "create"})
Expand Down Expand Up @@ -403,10 +395,7 @@ var _ = Describe("Podman prune", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())

session = podmanTest.Podman([]string{"pod", "stop", podid1})
session.WaitWithDefaultTimeout()
// FIXME - #20196: Cannot use ExitCleanly()
Expect(session).Should(Exit(0))
podmanTest.StopPod(podid1)

// Create a container. This container should be pruned.
create := podmanTest.Podman([]string{"create", "--name", "test", BB})
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ var _ = Describe("Podman restart", func() {
Expect(session).Should(ExitCleanly())
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))

session = podmanTest.Podman([]string{"stop", "--all"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
podmanTest.StopContainer("--all")
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))

session = podmanTest.Podman([]string{"restart", "--all"})
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/run_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ var _ = Describe("Podman run exit", func() {
Expect(pmount).Should(ExitCleanly())
Expect(pmount.OutputToString()).To(ContainSubstring(cid))

stop := podmanTest.Podman([]string{"stop", cid})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
podmanTest.StopContainer(cid)

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

stop := podmanTest.Podman([]string{"stop", cid})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
podmanTest.StopContainer(cid)

// We have to force cleanup so the unmount happens
podmanCleanupSession := podmanTest.Podman([]string{"container", "cleanup", cid})
Expand Down
12 changes: 3 additions & 9 deletions test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ var _ = Describe("Podman run", func() {
Expect(osession).Should(ExitCleanly())
Expect(osession.OutputToString()).To(Equal("hello"))

osession = podmanTest.Podman([]string{"stop", "overlay-foo"})
osession.WaitWithDefaultTimeout()
Expect(osession).Should(ExitCleanly())
podmanTest.StopContainer("overlay-foo")

startsession := podmanTest.Podman([]string{"start", "--attach", "overlay-foo"})
startsession.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -1541,9 +1539,7 @@ VOLUME %s`, ALPINE, volPath, volPath)
ctr.WaitWithDefaultTimeout()
Expect(ctr).Should(ExitCleanly())

stop := podmanTest.Podman([]string{"stop", "-t0", ctrName})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
podmanTest.StopContainer(ctrName)

// This is ugly, but I don't see a better way
time.Sleep(10 * time.Second)
Expand Down Expand Up @@ -2093,9 +2089,7 @@ WORKDIR /madethis`, BB)
mainContainer.WaitWithDefaultTimeout()
Expect(mainContainer).Should(ExitCleanly())

stop := podmanTest.Podman([]string{"stop", "--all"})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
podmanTest.StopContainer("--all")

start := podmanTest.Podman([]string{"start", mainName})
start.WaitWithDefaultTimeout()
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,7 @@ var _ = Describe("Podman run with volumes", func() {
Expect(mountOut2).To(ContainSubstring(volName))

// Stop the container to unmount
podmanStopSession := podmanTest.Podman([]string{"stop", "--time", "0", ctrName})
podmanStopSession.WaitWithDefaultTimeout()
Expect(podmanStopSession).Should(ExitCleanly())
podmanTest.StopContainer(ctrName)

// We have to force cleanup so the unmount happens
podmanCleanupSession := podmanTest.Podman([]string{"container", "cleanup", ctrName})
Expand Down Expand Up @@ -675,9 +673,7 @@ VOLUME /test/`, ALPINE)
session = podmanTest.Podman([]string{"exec", "-l", "ls", "/run/test/container"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"stop", "-l"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
podmanTest.StopContainer("-l")
session = podmanTest.Podman([]string{"start", "-l"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/volume_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ var _ = Describe("Podman volume plugins", func() {
Expect(arrOutput).To(HaveLen(1))
Expect(arrOutput[0]).To(ContainSubstring(volName))

stop := podmanTest.Podman([]string{"stop", "--timeout", "0", ctrName})
stop.WaitWithDefaultTimeout()
Expect(stop).Should(ExitCleanly())
podmanTest.StopContainer(ctrName)

// Remove should exit non-zero because missing plugin
remove := podmanTest.Podman([]string{"volume", "rm", volName})
Expand Down

1 comment on commit c84bb81

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.