Merge pull request #25350 from giuseppe/unify-error-codes

oci: report empty exec path as ENOENT
This commit is contained in:
openshift-merge-bot[bot] 2025-02-19 14:53:45 +00:00 committed by GitHub
commit 3ab0d82bd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 15 additions and 11 deletions

View File

@ -152,7 +152,7 @@ func getOCIRuntimeError(name, runtimeMsg string) error {
}
return fmt.Errorf("%s: %s: %w", name, strings.Trim(errStr, "\n"), define.ErrOCIRuntimePermissionDenied)
}
if match := regexp.MustCompile("(?i).*executable file not found in.*|.*no such file or directory.*").FindString(runtimeMsg); match != "" {
if match := regexp.MustCompile("(?i).*executable file not found in.*|.*no such file or directory.*|.*open executable.*").FindString(runtimeMsg); match != "" {
errStr := match
if includeFullOutput {
errStr = runtimeMsg

View File

@ -400,17 +400,14 @@ var _ = Describe("Podman exec", func() {
setup.WaitWithDefaultTimeout()
Expect(setup).Should(ExitCleanly())
expect := "chdir to `/missing`: No such file or directory"
if podmanTest.OCIRuntime == "runc" {
expect = "chdir to cwd"
}
expect := ".*(chdir to cwd|chdir to `/missing`: No such file or directory).*"
session := podmanTest.Podman([]string{"exec", "--workdir", "/missing", "test1", "pwd"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError(127, expect))
Expect(session).To(ExitWithErrorRegex(127, expect))
session = podmanTest.Podman([]string{"exec", "-w", "/missing", "test1", "pwd"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError(127, expect))
Expect(session).To(ExitWithErrorRegex(127, expect))
})
It("podman exec cannot be invoked", func() {

View File

@ -18,7 +18,12 @@ CMD []
podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithErrorRegex(126, ".*(open executable|executable path is empty): Operation not permitted: OCI permission denied.*"))
if session.ExitCode() == 126 {
// special case for crun <= 1.20, remove once a new version is out
Expect(session).Should(ExitWithError(126, "open executable: Operation not permitted: OCI permission denied"))
return
}
Expect(session).Should(ExitWithErrorRegex(127, ".*(executable file not found in \\$PATH|cannot find `` in \\$PATH).*: OCI runtime attempted to invoke a command that was not found.*"))
})
It("podman run entrypoint == [\"\"]", func() {

View File

@ -22,13 +22,15 @@ var _ = Describe("Podman run exit", func() {
It("podman run exit ExecErrorCodeCannotInvoke", func() {
result := podmanTest.Podman([]string{"run", ALPINE, "/etc"})
result.WaitWithDefaultTimeout()
Expect(result).Should(ExitWithErrorRegex(define.ExecErrorCodeCannotInvoke, ".*(open executable|the path `/etc` is not a regular file): Operation not permitted: OCI permission denied.*"))
expected := ".*(exec: \"/etc\": is a directory|(open executable|the path `/etc` is not a regular file): Operation not permitted: OCI permission denied).*"
Expect(result).Should(ExitWithErrorRegex(define.ExecErrorCodeCannotInvoke, expected))
})
It("podman run exit ExecErrorCodeNotFound", func() {
result := podmanTest.Podman([]string{"run", ALPINE, "foobar"})
result.WaitWithDefaultTimeout()
Expect(result).Should(ExitWithError(define.ExecErrorCodeNotFound, "executable file `foobar` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found"))
expected := ".*(executable file not found in \\$PATH|executable file `foobar` not found in \\$PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found).*"
Expect(result).Should(ExitWithErrorRegex(define.ExecErrorCodeNotFound, expected))
})
It("podman run exit 0", func() {

View File

@ -1657,7 +1657,7 @@ search | $IMAGE |
# runc and crun emit different diagnostics
runtime=$(podman_runtime)
case "$runtime" in
crun) expect='\(executable file `` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found\|executable path is empty\)' ;;
crun) expect='\(executable file `` not found in $PATH\|cannot find `` in $PATH\): No such file or directory: OCI runtime attempted to invoke a command that was not found' ;;
runc) expect='runc: runc create failed: unable to start container process: exec: "": executable file not found in $PATH: OCI runtime attempted to invoke a command that was not found' ;;
*) skip "Unknown runtime '$runtime'" ;;
esac