mirror of
https://github.com/containers/podman.git
synced 2025-10-17 11:14:40 +08:00
Merge pull request #25340 from giuseppe/fix-crun-error-messages
tests: adapt e2e tests new crun error messages
This commit is contained in:
@ -421,19 +421,20 @@ var _ = Describe("Podman exec", func() {
|
||||
session := podmanTest.Podman([]string{"exec", "test1", "/etc"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
|
||||
// crun (and, we hope, any other future runtimes)
|
||||
expectedStatus := 126
|
||||
expectedMessage := "open executable: Operation not permitted: OCI permission denied"
|
||||
|
||||
// ...but it's much more complicated under runc (#19552)
|
||||
if podmanTest.OCIRuntime == "runc" {
|
||||
expectedMessage = `exec failed: unable to start container process: exec: "/etc": is a directory`
|
||||
expectedStatus = 255
|
||||
expectedMessage := `exec failed: unable to start container process: exec: "/etc": is a directory`
|
||||
expectedStatus := 255
|
||||
if IsRemote() {
|
||||
expectedStatus = 125
|
||||
}
|
||||
Expect(session).Should(ExitWithError(expectedStatus, expectedMessage))
|
||||
} else {
|
||||
// crun (and, we hope, any other future runtimes)
|
||||
expectedStatus := 126
|
||||
expectedMessage := ".*(open executable|the path `/etc` is not a regular file): Operation not permitted: OCI permission denied.*"
|
||||
Expect(session).Should(ExitWithErrorRegex(expectedStatus, expectedMessage))
|
||||
}
|
||||
Expect(session).Should(ExitWithError(expectedStatus, expectedMessage))
|
||||
})
|
||||
|
||||
It("podman exec command not found", func() {
|
||||
|
@ -18,7 +18,7 @@ CMD []
|
||||
podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
|
||||
session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitWithError(126, "open executable: Operation not permitted: OCI permission denied"))
|
||||
Expect(session).Should(ExitWithErrorRegex(126, ".*(open executable|executable path is empty): Operation not permitted: OCI permission denied.*"))
|
||||
})
|
||||
|
||||
It("podman run entrypoint == [\"\"]", func() {
|
||||
|
@ -22,7 +22,7 @@ var _ = Describe("Podman run exit", func() {
|
||||
It("podman run exit ExecErrorCodeCannotInvoke", func() {
|
||||
result := podmanTest.Podman([]string{"run", ALPINE, "/etc"})
|
||||
result.WaitWithDefaultTimeout()
|
||||
Expect(result).Should(ExitWithError(define.ExecErrorCodeCannotInvoke, "open executable: Operation not permitted: OCI permission denied"))
|
||||
Expect(result).Should(ExitWithErrorRegex(define.ExecErrorCodeCannotInvoke, ".*(open executable|the path `/etc` is not a regular file): Operation not permitted: OCI permission denied.*"))
|
||||
})
|
||||
|
||||
It("podman run exit ExecErrorCodeNotFound", func() {
|
||||
|
@ -1135,12 +1135,6 @@ echo -n madeit-$teststring >$tmpfile
|
||||
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(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()
|
||||
|
@ -10,7 +10,7 @@ load helpers.network
|
||||
err_no_such_cmd="Error:.*/no/such/command.*[Nn]o such file or directory"
|
||||
# runc: RHEL8 on 2023-07-17: "is a directory".
|
||||
# Everything else (crun; runc on debian): "permission denied"
|
||||
err_no_exec_dir="Error:.*exec.*\\\(permission denied\\\|is a directory\\\)"
|
||||
err_no_exec_dir="Error:.*\\\(exec.*\\\(permission denied\\\|is a directory\\\)\\\|is not a regular file\\\)"
|
||||
|
||||
tests="
|
||||
true | 0 |
|
||||
@ -1657,14 +1657,14 @@ search | $IMAGE |
|
||||
# runc and crun emit different diagnostics
|
||||
runtime=$(podman_runtime)
|
||||
case "$runtime" in
|
||||
crun) expect='crun: executable file `` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found' ;;
|
||||
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\)' ;;
|
||||
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
|
||||
|
||||
# The '.*' in the error below is for dealing with podman-remote, which
|
||||
# includes "error preparing container <sha> for attach" in output.
|
||||
is "$output" "Error.*: $expect" "podman emits useful diagnostic when no entrypoint is set"
|
||||
is "$output" "Error.* $expect" "podman emits useful diagnostic when no entrypoint is set"
|
||||
}
|
||||
|
||||
# bats test_tags=ci:parallel
|
||||
|
@ -3,6 +3,7 @@ package utils
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
@ -17,10 +18,11 @@ type podmanSession interface {
|
||||
|
||||
type ExitMatcher struct {
|
||||
types.GomegaMatcher
|
||||
ExpectedExitCode int
|
||||
ExitCode int
|
||||
ExpectedStderr string
|
||||
msg string
|
||||
ExpectedExitCode int
|
||||
ExitCode int
|
||||
ExpectedStderr string
|
||||
ExpectedStderrRegex string
|
||||
msg string
|
||||
}
|
||||
|
||||
// ExitWithError checks both exit code and stderr, fails if either does not match
|
||||
@ -29,6 +31,12 @@ func ExitWithError(expectExitCode int, expectStderr string) *ExitMatcher {
|
||||
return &ExitMatcher{ExpectedExitCode: expectExitCode, ExpectedStderr: expectStderr}
|
||||
}
|
||||
|
||||
// ExitWithErrorRegex checks both exit code and the stderr regex, fails if either does not match
|
||||
// Modeled after the gomega Exit() matcher and also operates on sessions.
|
||||
func ExitWithErrorRegex(expectExitCode int, expectStderrRegex string) *ExitMatcher {
|
||||
return &ExitMatcher{ExpectedExitCode: expectExitCode, ExpectedStderrRegex: expectStderrRegex}
|
||||
}
|
||||
|
||||
// Match follows gexec.Matcher interface.
|
||||
func (matcher *ExitMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
session, ok := actual.(podmanSession)
|
||||
@ -49,12 +57,23 @@ func (matcher *ExitMatcher) Match(actual interface{}) (success bool, err error)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if matcher.ExpectedStderr != "" {
|
||||
switch {
|
||||
case matcher.ExpectedStderrRegex != "":
|
||||
matched, err := regexp.MatchString(matcher.ExpectedStderrRegex, session.ErrorToString())
|
||||
if err != nil {
|
||||
matcher.msg = fmt.Sprintf("Invalid regex pattern: %s", err)
|
||||
return false, err
|
||||
}
|
||||
if !matched {
|
||||
matcher.msg = fmt.Sprintf("Command exited %d as expected, but stderr did not match regex '%s'", matcher.ExitCode, matcher.ExpectedStderrRegex)
|
||||
return false, nil
|
||||
}
|
||||
case matcher.ExpectedStderr != "":
|
||||
if !strings.Contains(session.ErrorToString(), matcher.ExpectedStderr) {
|
||||
matcher.msg = fmt.Sprintf("Command exited %d as expected, but did not emit '%s'", matcher.ExitCode, matcher.ExpectedStderr)
|
||||
return false, nil
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
if session.ErrorToString() != "" {
|
||||
matcher.msg = "Command exited with expected exit status, but emitted unwanted stderr"
|
||||
return false, nil
|
||||
|
Reference in New Issue
Block a user