Merge pull request #23101 from edsantiago/exitwitherror-yetmore

ExitWithError() - more upgrades from Exit()
This commit is contained in:
openshift-merge-bot[bot] 2024-06-25 18:01:40 +00:00 committed by GitHub
commit 242fdb51a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 62 deletions

View File

@ -4,7 +4,6 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("Podman run entrypoint", func() {
@ -17,7 +16,7 @@ CMD []
podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Or(Exit(126), Exit(127)))
Expect(session).Should(ExitWithError(126, "open executable: Operation not permitted: OCI permission denied"))
})
It("podman run entrypoint == [\"\"]", func() {

View File

@ -232,8 +232,7 @@ var _ = Describe("Podman run", func() {
run := podmanTest.Podman([]string{"run", pushedImage, "date"})
run.WaitWithDefaultTimeout()
Expect(run).Should(Exit(125))
Expect(run.ErrorToString()).To(ContainSubstring("pinging container registry localhost:" + port))
Expect(run).Should(ExitWithError(125, "pinging container registry localhost:"+port))
Expect(run.ErrorToString()).To(ContainSubstring("http: server gave HTTP response to HTTPS client"))
run = podmanTest.Podman([]string{"run", "--tls-verify=false", pushedImage, "echo", "got here"})
@ -393,8 +392,7 @@ var _ = Describe("Podman run", func() {
if _, err := os.Stat(mask); err == nil {
session = podmanTest.Podman([]string{"exec", "maskCtr", "touch", mask})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session.ErrorToString()).To(Equal(fmt.Sprintf("touch: %s: Read-only file system", mask)))
Expect(session).Should(ExitWithError(1, fmt.Sprintf("touch: %s: Read-only file system", mask)))
}
}
})
@ -530,15 +528,13 @@ var _ = Describe("Podman run", func() {
cmd = append(secOpts, cmd...)
session = podmanTest.Podman(append([]string{"run"}, cmd...))
session.WaitWithDefaultTimeout()
Expect(session).To(Exit(1))
Expect(session.ErrorToString()).To(ContainSubstring("ln: /linkNotAllowed: Operation not permitted"))
Expect(session).To(ExitWithError(1, "ln: /linkNotAllowed: Operation not permitted"))
// ...even with --privileged
cmd = append([]string{"--privileged"}, cmd...)
session = podmanTest.Podman(append([]string{"run"}, cmd...))
session.WaitWithDefaultTimeout()
Expect(session).To(Exit(1))
Expect(session.ErrorToString()).To(ContainSubstring("ln: /linkNotAllowed: Operation not permitted"))
Expect(session).To(ExitWithError(1, "ln: /linkNotAllowed: Operation not permitted"))
})
It("podman run seccomp test --privileged no profile should be unconfined", func() {
@ -791,7 +787,7 @@ USER bin`, BB)
// network sysctls should fail if --net=host is set
session = podmanTest.Podman([]string{"run", "--net", "host", "--rm", "--sysctl", "net.core.somaxconn=65535", ALPINE, "sysctl", "net.core.somaxconn"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "sysctl net.core.somaxconn=65535 can't be set since Network Namespace set to host: invalid argument"))
})
It("podman run blkio-weight test", func() {
@ -1126,19 +1122,19 @@ echo -n %s >%s
It("podman run attach nonsense errors", func() {
session := podmanTest.Podman([]string{"run", "--rm", "--attach", "asdfasdf", ALPINE, "ls", "/"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, `invalid stream "asdfasdf" for --attach - must be one of stdin, stdout, or stderr: invalid argument`))
})
It("podman run exit code on failure to exec", func() {
session := podmanTest.Podman([]string{"run", ALPINE, "/etc"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(126))
Expect(session).Should(ExitWithError(126, "open executable: Operation not permitted: OCI permission denied"))
})
It("podman run error on exec", func() {
session := podmanTest.Podman([]string{"run", ALPINE, "sh", "-c", "exit 100"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(100))
Expect(session).Should(ExitWithError(100, ""))
})
It("podman run with named volume", func() {
@ -1222,8 +1218,7 @@ USER mail`, BB)
// check that the read-only option works
session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID + ":ro", ALPINE, "touch", mountpoint + "abc.txt"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session.ErrorToString()).To(ContainSubstring("Read-only file system"))
Expect(session).Should(ExitWithError(1, "Read-only file system"))
// check that both z and ro options work
session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID + ":ro,z", ALPINE, "cat", mountpoint + filename})
@ -1234,14 +1229,12 @@ USER mail`, BB)
// check that multiple ro/rw are not working
session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID + ":ro,rw", ALPINE, "cat", mountpoint + filename})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("cannot set ro or rw options more than once"))
Expect(session).Should(ExitWithError(125, "cannot set ro or rw options more than once"))
// check that multiple z options are not working
session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID + ":z,z,ro", ALPINE, "cat", mountpoint + filename})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("cannot set :z more than once in mount options"))
Expect(session).Should(ExitWithError(125, "cannot set :z more than once in mount options"))
// create new read-only volume
session = podmanTest.Podman([]string{"create", "--volume", vol + ":" + mountpoint + ":ro", ALPINE, "cat", mountpoint + filename})
@ -1252,8 +1245,7 @@ USER mail`, BB)
// check if the original volume was mounted as read-only that --volumes-from also mount it as read-only
session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID, ALPINE, "touch", mountpoint + "abc.txt"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session.ErrorToString()).To(ContainSubstring("Read-only file system"))
Expect(session).Should(ExitWithError(1, "Read-only file system"))
})
It("podman run --volumes-from flag with built-in volumes", func() {
@ -1699,8 +1691,7 @@ VOLUME %s`, ALPINE, volPath, volPath)
// Make sure we error out with --name.
session := podmanTest.Podman([]string{"create", "--replace", ALPINE, "/bin/sh"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("cannot replace container without --name being set"))
Expect(session).Should(ExitWithError(125, "cannot replace container without --name being set"))
// Run and replace 5 times in a row the "same" container.
ctrName := "testCtr"
@ -1852,7 +1843,7 @@ WORKDIR /madethis`, BB)
It("podman run a container with --pull never should fail if no local store", func() {
session := podmanTest.Podman([]string{"run", "--pull", "never", "docker.io/library/debian:latest", "ls"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "Error: docker.io/library/debian:latest: image not known"))
})
It("podman run container with --pull missing and only pull once", func() {
@ -2180,8 +2171,7 @@ WORKDIR /madethis`, BB)
// Must fail without --decryption-key
session = podmanTest.Podman([]string{"run", "--tls-verify=false", imgPath})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("Trying to pull " + imgPath))
Expect(session).Should(ExitWithError(125, "Trying to pull "+imgPath))
Expect(session.ErrorToString()).To(ContainSubstring("invalid tar header"))
// With

View File

@ -9,7 +9,6 @@ import (
"github.com/containers/storage/pkg/stringid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("Podman secret", func() {
@ -430,6 +429,6 @@ var _ = Describe("Podman secret", func() {
exists := podmanTest.Podman([]string{"secret", "exists", secretName})
exists.WaitWithDefaultTimeout()
Expect(exists).Should(Exit(1))
Expect(exists).Should(ExitWithError(1, ""))
})
})

View File

@ -16,7 +16,7 @@ var _ = Describe("Podman stop", func() {
It("podman stop bogus container", func() {
session := podmanTest.Podman([]string{"stop", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, `no container with name or ID "foobar" found: no such container`))
})
It("podman stop --ignore bogus container", func() {
@ -307,19 +307,19 @@ var _ = Describe("Podman stop", func() {
result := podmanTest.Podman([]string{"stop", "--cidfile", "foobar", "--latest"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together"))
result = podmanTest.Podman([]string{"stop", "--cidfile", "foobar", "--all"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together"))
result = podmanTest.Podman([]string{"stop", "--cidfile", "foobar", "--all", "--latest"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together"))
result = podmanTest.Podman([]string{"stop", "--latest", "--all"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "--all and --latest cannot be used together"))
})
It("podman stop --all", func() {
@ -348,7 +348,7 @@ var _ = Describe("Podman stop", func() {
session = podmanTest.Podman([]string{"stop", "bogus", cid})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, `no container with name or ID "bogus" found: no such container`))
session = podmanTest.Podman([]string{"stop", "--ignore", "bogus", cid})
session.WaitWithDefaultTimeout()
@ -384,7 +384,7 @@ var _ = Describe("Podman stop", func() {
session1 = podmanTest.Podman([]string{"stop", cid1, "-f", "status=running"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(125))
Expect(session1).Should(ExitWithError(125, "--filter takes no arguments"))
session1 = podmanTest.Podman([]string{"stop", "-a", "--filter", fmt.Sprintf("id=%swrongid", shortCid3)})
session1.WaitWithDefaultTimeout()

View File

@ -4,7 +4,6 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("podman system dial-stdio", func() {
@ -22,7 +21,6 @@ var _ = Describe("podman system dial-stdio", func() {
}
session := podmanTest.Podman([]string{"system", "dial-stdio"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("Error: failed to open connection to podman"))
Expect(session).Should(ExitWithError(125, "Error: failed to open connection to podman"))
})
})

View File

@ -7,7 +7,6 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("Podman top", func() {
@ -15,13 +14,17 @@ var _ = Describe("Podman top", func() {
It("podman top without container name or id", func() {
result := podmanTest.Podman([]string{"top"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "you must provide the name or id of a running container"))
})
It("podman top on bogus container", func() {
result := podmanTest.Podman([]string{"top", "1234"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
expect := `no container with name or ID "1234" found: no such container`
if !IsRemote() {
expect = `unable to look up requested container: ` + expect
}
Expect(result).Should(ExitWithError(125, expect))
})
It("podman top on non-running container", func() {
@ -29,7 +32,7 @@ var _ = Describe("Podman top", func() {
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"top", cid})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "top can only be used on running containers"))
})
It("podman top on container", func() {
@ -115,8 +118,7 @@ var _ = Describe("Podman top", func() {
// Because the image does not contain this must fail and we know we use the correct podman exec fallback.
exec := podmanTest.Podman([]string{"top", session.OutputToString(), "aux"})
exec.WaitWithDefaultTimeout()
Expect(exec).Should(Exit(125))
Expect(exec.ErrorToString()).Should(ContainSubstring("OCI runtime attempted to invoke a command that was not found"))
Expect(exec).Should(ExitWithError(125, "OCI runtime attempted to invoke a command that was not found"))
})
It("podman top with comma-separated options", func() {
@ -142,7 +144,7 @@ var _ = Describe("Podman top", func() {
// the wrong input and still print the -ef output instead.
result := podmanTest.Podman([]string{"top", cid, "-eo", "invalid"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, `Error: ps(1) failed with exit code 1: error: unknown user-defined format specifier "invalid"`))
})
It("podman top on privileged container", func() {

View File

@ -6,7 +6,6 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("Podman unshare", func() {
@ -33,40 +32,34 @@ var _ = Describe("Podman unshare", func() {
SkipIfRemote("podman-remote unshare is not supported")
session := podmanTest.Podman([]string{"unshare", "false"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, ""))
Expect(session.OutputToString()).Should(Equal(""))
Expect(session.ErrorToString()).Should(Equal(""))
session = podmanTest.Podman([]string{"unshare", "/usr/bin/bogus"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(127))
Expect(session).Should(ExitWithError(127, "no such file or directory"))
Expect(session.OutputToString()).Should(Equal(""))
Expect(session.ErrorToString()).Should(ContainSubstring("no such file or directory"))
session = podmanTest.Podman([]string{"unshare", "bogus"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(127))
Expect(session).Should(ExitWithError(127, "executable file not found in $PATH"))
Expect(session.OutputToString()).Should(Equal(""))
Expect(session.ErrorToString()).Should(ContainSubstring("executable file not found in $PATH"))
session = podmanTest.Podman([]string{"unshare", "/usr"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(126))
Expect(session).Should(ExitWithError(126, "permission denied"))
Expect(session.OutputToString()).Should(Equal(""))
Expect(session.ErrorToString()).Should(ContainSubstring("permission denied"))
session = podmanTest.Podman([]string{"unshare", "--bogus"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "unknown flag: --bogus"))
Expect(session.OutputToString()).Should(Equal(""))
Expect(session.ErrorToString()).Should(ContainSubstring("unknown flag: --bogus"))
})
It("podman unshare check remote error", func() {
SkipIfNotRemote("check for podman-remote unshare error")
session := podmanTest.Podman([]string{"unshare"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(Equal(`Error: cannot use command "podman-remote unshare" with the remote podman client`))
Expect(session).Should(ExitWithError(125, `Error: cannot use command "podman-remote unshare" with the remote podman client`))
})
})

View File

@ -4,7 +4,6 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("Podman wait", func() {
@ -12,7 +11,7 @@ var _ = Describe("Podman wait", func() {
It("podman wait on bogus container", func() {
session := podmanTest.Podman([]string{"wait", "1234"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, `no container with name or ID "1234" found: no such container`))
})
@ -86,7 +85,7 @@ var _ = Describe("Podman wait", func() {
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"container", "wait", "--interval", "100days", session.OutputToString()})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, `time: unknown unit "days" in duration "100days"`))
})
It("podman wait on three containers", func() {