mirror of
https://github.com/containers/podman.git
synced 2025-09-10 08:22:23 +08:00

e2e test failures are rife with messages like: Expected 1 to equal 0 These make me cry. They're anti-helpful, requiring the reader to dive into the source code to figure out what those numbers mean. Solution: Go tests have a '.Should(Exit(NNN))' mechanism. I don't know if it spits out a better diagnostic (I have no way to run e2e tests on my laptop), but I have to fantasize that it will, and given the state of our flakes I assume that at least one test will fail and give me the opportunity to see what the error message looks like. THIS IS NOT REVIEWABLE CODE. There is no way for a human to review it. Don't bother. Maybe look at a few random ones for sanity. If you want to really review, here is a reproducer of what I did: cd test/e2e ! positive assertions. The second is the same as the first, ! with the addition of (unnecessary) parentheses because ! some invocations were written that way. The third is BeZero(). perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Equal\((\d+)\)\)/Expect($1).Should(Exit($2))/' *_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(\(Equal\((\d+)\)\)\)/Expect($1).Should(Exit($2))/' *_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(BeZero\(\)\)/Expect($1).Should(Exit(0))/' *_test.go ! Same as above, but handles three non-numeric exit codes ! in run_exit_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Equal\((\S+)\)\)/Expect($1).Should(Exit($2))/' *_test.go ! negative assertions. Difference is the spelling of 'To(Not)', ! 'ToNot', and 'NotTo'. I assume those are all the same. perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Not\(Equal\((0)\)\)\)/Expect($1).To(ExitWithError())/' *_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.ToNot\(Equal\((0)\)\)/Expect($1).To(ExitWithError())/' *_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.NotTo\(Equal\((0)\)\)/Expect($1).To(ExitWithError())/' *_test.go ! negative, old use of BeZero() perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.ToNot\(BeZero\(\)\)/Expect($1).Should(ExitWithError())/' *_test.go Run those on a clean copy of main branch (at the same branch point as my PR, of course), then diff against a checked-out copy of my PR. There should be no differences. Then all you have to review is that my replacements above are sane. UPDATE: nope, that's not enough, you also need to add gomega/gexec to the files that don't have it: perl -pi -e '$_ .= "$1/gexec\"\n" if m!^(.*/onsi/gomega)"!' $(grep -L gomega/gexec $(git log -1 --stat | awk '$1 ~ /test\/e2e\// { print $1}')) UPDATE 2: hand-edit run_volume_test.go UPDATE 3: sigh, add WaitWithDefaultTimeout() to a couple of places UPDATE 4: skip a test due to bug #10935 (race condition) Signed-off-by: Ed Santiago <santiago@redhat.com>
319 lines
9.7 KiB
Go
319 lines
9.7 KiB
Go
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
. "github.com/containers/podman/v3/test/utils"
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
. "github.com/onsi/gomega/gexec"
|
|
)
|
|
|
|
var _ = Describe("Podman pause", func() {
|
|
var (
|
|
tempdir string
|
|
err error
|
|
podmanTest *PodmanTestIntegration
|
|
)
|
|
|
|
pausedState := "paused"
|
|
createdState := "created"
|
|
|
|
BeforeEach(func() {
|
|
SkipIfRootlessCgroupsV1("Pause is not supported in cgroups v1")
|
|
tempdir, err = CreateTempDirInTempDir()
|
|
if err != nil {
|
|
os.Exit(1)
|
|
}
|
|
|
|
if CGROUPSV2 {
|
|
b, err := ioutil.ReadFile("/proc/self/cgroup")
|
|
if err != nil {
|
|
Skip("cannot read self cgroup")
|
|
}
|
|
|
|
path := filepath.Join("/sys/fs/cgroup", strings.TrimSuffix(strings.Replace(string(b), "0::", "", 1), "\n"), "cgroup.freeze")
|
|
_, err = os.Stat(path)
|
|
if err != nil {
|
|
Skip("freezer controller not available on the current kernel")
|
|
}
|
|
}
|
|
|
|
podmanTest = PodmanTestCreate(tempdir)
|
|
podmanTest.Setup()
|
|
podmanTest.SeedImages()
|
|
})
|
|
|
|
AfterEach(func() {
|
|
podmanTest.Cleanup()
|
|
f := CurrentGinkgoTestDescription()
|
|
processTestResult(f)
|
|
|
|
})
|
|
|
|
It("podman pause bogus container", func() {
|
|
session := podmanTest.Podman([]string{"pause", "foobar"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).To(ExitWithError())
|
|
})
|
|
|
|
It("podman unpause bogus container", func() {
|
|
session := podmanTest.Podman([]string{"unpause", "foobar"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).To(ExitWithError())
|
|
})
|
|
|
|
It("podman pause a created container by id", func() {
|
|
session := podmanTest.Podman([]string{"create", ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"pause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).To(ExitWithError())
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(createdState))
|
|
})
|
|
|
|
It("podman pause a running container by id", func() {
|
|
session := podmanTest.RunTopContainer("")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
cid := session.OutputToString()
|
|
result := podmanTest.Podman([]string{"pause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(pausedState))
|
|
|
|
result = podmanTest.Podman([]string{"unpause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
})
|
|
|
|
It("podman container pause a running container by id", func() {
|
|
session := podmanTest.RunTopContainer("")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"container", "pause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(pausedState))
|
|
|
|
result = podmanTest.Podman([]string{"container", "unpause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
})
|
|
|
|
It("podman unpause a running container by id", func() {
|
|
session := podmanTest.RunTopContainer("")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"unpause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(125))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
|
|
|
|
})
|
|
|
|
It("podman remove a paused container by id without force", func() {
|
|
session := podmanTest.RunTopContainer("")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"pause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(pausedState))
|
|
|
|
result = podmanTest.Podman([]string{"rm", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(2))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(pausedState))
|
|
|
|
})
|
|
|
|
It("podman remove a paused container by id with force", func() {
|
|
session := podmanTest.RunTopContainer("")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"pause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(pausedState))
|
|
|
|
result = podmanTest.Podman([]string{"rm", "--force", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
})
|
|
|
|
It("podman stop a paused container by id", func() {
|
|
session := podmanTest.RunTopContainer("")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"pause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(pausedState))
|
|
|
|
result = podmanTest.Podman([]string{"stop", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(125))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(pausedState))
|
|
|
|
result = podmanTest.Podman([]string{"unpause", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
|
|
|
|
result = podmanTest.Podman([]string{"rm", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(2))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
|
|
|
|
result = podmanTest.Podman([]string{"rm", "-f", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
|
|
})
|
|
|
|
It("podman pause a running container by name", func() {
|
|
session := podmanTest.RunTopContainer("test1")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
|
|
result := podmanTest.Podman([]string{"pause", "test1"})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(Equal(pausedState))
|
|
|
|
result = podmanTest.Podman([]string{"unpause", "test1"})
|
|
result.WaitWithDefaultTimeout()
|
|
})
|
|
|
|
It("podman pause a running container by id and another by name", func() {
|
|
session1 := podmanTest.RunTopContainer("test1")
|
|
session1.WaitWithDefaultTimeout()
|
|
Expect(session1).Should(Exit(0))
|
|
|
|
session2 := podmanTest.RunTopContainer("")
|
|
session2.WaitWithDefaultTimeout()
|
|
Expect(session2).Should(Exit(0))
|
|
cid2 := session2.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"pause", cid2})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
|
|
|
|
result = podmanTest.Podman([]string{"pause", "test1"})
|
|
result.WaitWithDefaultTimeout()
|
|
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
|
|
result = podmanTest.Podman([]string{"unpause", "test1"})
|
|
result.WaitWithDefaultTimeout()
|
|
result = podmanTest.Podman([]string{"unpause", cid2})
|
|
result.WaitWithDefaultTimeout()
|
|
})
|
|
|
|
It("Pause all containers (no containers exist)", func() {
|
|
result := podmanTest.Podman([]string{"pause", "--all"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
|
|
})
|
|
|
|
It("Unpause all containers (no paused containers exist)", func() {
|
|
result := podmanTest.Podman([]string{"unpause", "--all"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
|
})
|
|
|
|
It("Pause a bunch of running containers", func() {
|
|
for i := 0; i < 3; i++ {
|
|
name := fmt.Sprintf("test%d", i)
|
|
run := podmanTest.Podman([]string{"run", "-dt", "--name", name, nginx})
|
|
run.WaitWithDefaultTimeout()
|
|
Expect(run).Should(Exit(0))
|
|
|
|
}
|
|
running := podmanTest.Podman([]string{"ps", "-q"})
|
|
running.WaitWithDefaultTimeout()
|
|
Expect(running).Should(Exit(0))
|
|
Expect(len(running.OutputToStringArray())).To(Equal(3))
|
|
|
|
pause := podmanTest.Podman([]string{"pause", "--all"})
|
|
pause.WaitWithDefaultTimeout()
|
|
Expect(pause).Should(Exit(0))
|
|
|
|
running = podmanTest.Podman([]string{"ps", "-q"})
|
|
running.WaitWithDefaultTimeout()
|
|
Expect(running).Should(Exit(0))
|
|
Expect(len(running.OutputToStringArray())).To(Equal(0))
|
|
|
|
unpause := podmanTest.Podman([]string{"unpause", "--all"})
|
|
unpause.WaitWithDefaultTimeout()
|
|
Expect(unpause).Should(Exit(0))
|
|
})
|
|
|
|
It("Unpause a bunch of running containers", func() {
|
|
for i := 0; i < 3; i++ {
|
|
name := fmt.Sprintf("test%d", i)
|
|
run := podmanTest.Podman([]string{"run", "-dt", "--name", name, nginx})
|
|
run.WaitWithDefaultTimeout()
|
|
Expect(run).Should(Exit(0))
|
|
|
|
}
|
|
pause := podmanTest.Podman([]string{"pause", "--all"})
|
|
pause.WaitWithDefaultTimeout()
|
|
Expect(pause).Should(Exit(0))
|
|
|
|
unpause := podmanTest.Podman([]string{"unpause", "--all"})
|
|
unpause.WaitWithDefaultTimeout()
|
|
Expect(unpause).Should(Exit(0))
|
|
|
|
running := podmanTest.Podman([]string{"ps", "-q"})
|
|
running.WaitWithDefaultTimeout()
|
|
Expect(running).Should(Exit(0))
|
|
Expect(len(running.OutputToStringArray())).To(Equal(3))
|
|
})
|
|
|
|
})
|