Skip to content

Commit

Permalink
Merge pull request #22346 from edsantiago/exitwitherror-part2
Browse files Browse the repository at this point in the history
ExitWithError() - continue tightening
  • Loading branch information
openshift-merge-bot[bot] authored May 8, 2024
2 parents d6b69e9 + 641cd7c commit 092d040
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 90 deletions.
8 changes: 1 addition & 7 deletions test/e2e/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,10 @@ var _ = Describe("Podman import", func() {

importImage := podmanTest.Podman([]string{"import", "-q", "--signature-policy", "/no/such/file", outfile})
importImage.WaitWithDefaultTimeout()
Expect(importImage).To(ExitWithError())
Expect(importImage).To(ExitWithError(125, "open /no/such/file: no such file or directory"))

result := podmanTest.Podman([]string{"import", "-q", "--signature-policy", "/etc/containers/policy.json", outfile})
result.WaitWithDefaultTimeout()
if IsRemote() {
Expect(result).To(ExitWithError())
Expect(result.ErrorToString()).To(ContainSubstring("unknown flag"))
result := podmanTest.Podman([]string{"import", "-q", outfile})
result.WaitWithDefaultTimeout()
}
Expect(result).Should(ExitCleanly())
})
})
42 changes: 27 additions & 15 deletions test/e2e/inspect_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package integration

import (
"fmt"

. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
"github.com/opencontainers/selinux/go-selinux"
)

Expand All @@ -22,7 +23,7 @@ var _ = Describe("Podman inspect", func() {
It("podman inspect bogus container", func() {
session := podmanTest.Podman([]string{"inspect", "foobar4321"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, `no such object: "foobar4321"`))
})

It("podman inspect filter should work if result contains tab", func() {
Expand Down Expand Up @@ -128,7 +129,7 @@ var _ = Describe("Podman inspect", func() {
SkipIfRemote("--latest flag n/a")
result := podmanTest.Podman([]string{"inspect", "-l", "1234foobar"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "--latest and arguments cannot be used together"))
})

It("podman inspect with mount filters", func() {
Expand Down Expand Up @@ -173,7 +174,7 @@ var _ = Describe("Podman inspect", func() {

session := podmanTest.Podman([]string{"inspect", "--latest"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "no containers to inspect: no such container"))
})

It("podman [image,container] inspect on image", func() {
Expand All @@ -185,7 +186,11 @@ var _ = Describe("Podman inspect", func() {

ctrInspect := podmanTest.Podman([]string{"container", "inspect", ALPINE})
ctrInspect.WaitWithDefaultTimeout()
Expect(ctrInspect).To(ExitWithError())
if IsRemote() {
Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", ALPINE)))
} else {
Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %s", ALPINE)))
}

imageInspect := podmanTest.Podman([]string{"image", "inspect", ALPINE})
imageInspect.WaitWithDefaultTimeout()
Expand All @@ -197,7 +202,7 @@ var _ = Describe("Podman inspect", func() {
})

It("podman [image, container] inspect on container", func() {
ctrName := "testCtr"
ctrName := "testctr"
create := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "sh"})
create.WaitWithDefaultTimeout()
Expect(create).Should(ExitCleanly())
Expand All @@ -216,15 +221,15 @@ var _ = Describe("Podman inspect", func() {

imageInspect := podmanTest.Podman([]string{"image", "inspect", ctrName})
imageInspect.WaitWithDefaultTimeout()
Expect(imageInspect).To(ExitWithError())
Expect(imageInspect).To(ExitWithError(125, fmt.Sprintf("%s: image not known", ctrName)))

Expect(baseJSON[0]).To(HaveField("ID", ctrJSON[0].ID))
})

It("podman inspect always produces a valid array", func() {
baseInspect := podmanTest.Podman([]string{"inspect", "doesNotExist"})
baseInspect.WaitWithDefaultTimeout()
Expect(baseInspect).To(ExitWithError())
Expect(baseInspect).To(ExitWithError(125, `no such object: "doesNotExist"`))
emptyJSON := baseInspect.InspectContainerToJSON()
Expect(emptyJSON).To(BeEmpty())
})
Expand All @@ -237,7 +242,7 @@ var _ = Describe("Podman inspect", func() {

baseInspect := podmanTest.Podman([]string{"inspect", ctrName, "doesNotExist"})
baseInspect.WaitWithDefaultTimeout()
Expect(baseInspect).To(ExitWithError())
Expect(baseInspect).To(ExitWithError(125, `no such object: "doesNotExist"`))
baseJSON := baseInspect.InspectContainerToJSON()
Expect(baseJSON).To(HaveLen(1))
Expect(baseJSON[0]).To(HaveField("Name", ctrName))
Expand Down Expand Up @@ -383,6 +388,7 @@ var _ = Describe("Podman inspect", func() {
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(Equal(volName))
})

It("podman inspect --type container on a pod should fail", func() {
podName := "testpod"
create := podmanTest.Podman([]string{"pod", "create", "--name", podName})
Expand All @@ -391,7 +397,11 @@ var _ = Describe("Podman inspect", func() {

inspect := podmanTest.Podman([]string{"inspect", "--type", "container", podName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(ExitWithError())
if IsRemote() {
Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", podName)))
} else {
Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %s", podName)))
}
})

It("podman inspect --type network on a container should fail", func() {
Expand All @@ -402,7 +412,7 @@ var _ = Describe("Podman inspect", func() {

inspect := podmanTest.Podman([]string{"inspect", "--type", "network", ctrName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(ExitWithError())
Expect(inspect).To(ExitWithError(125, " network not found"))
})

It("podman inspect --type pod on a container should fail", func() {
Expand All @@ -413,7 +423,7 @@ var _ = Describe("Podman inspect", func() {

inspect := podmanTest.Podman([]string{"inspect", "--type", "pod", ctrName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(ExitWithError())
Expect(inspect).To(ExitWithError(125, "no such pod "))
})

It("podman inspect --type volume on a container should fail", func() {
Expand All @@ -424,7 +434,7 @@ var _ = Describe("Podman inspect", func() {

inspect := podmanTest.Podman([]string{"inspect", "--type", "volume", ctrName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(ExitWithError())
Expect(inspect).To(ExitWithError(125, "no such volume "))
})

// Fixes https://github.com/containers/podman/issues/8444
Expand Down Expand Up @@ -573,13 +583,15 @@ var _ = Describe("Podman inspect", func() {
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(BeEmpty())

commandNotFound := "OCI runtime attempted to invoke a command that was not found"
session = podmanTest.Podman([]string{"start", cid})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, commandNotFound))

session = podmanTest.Podman([]string{"container", "inspect", cid, "-f", "'{{ .State.Error }}"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).ToNot(BeEmpty())
Expect(session.OutputToString()).To(ContainSubstring(commandNotFound))
})

})
50 changes: 27 additions & 23 deletions test/e2e/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -83,13 +84,12 @@ var _ = Describe("Podman manifest", func() {

session = podmanTest.Podman([]string{"manifest", "create", "foo"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, `image name "localhost/foo:latest" is already associated with image `))

session = podmanTest.Podman([]string{"manifest", "push", "--all", "foo"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
// Push should actually fail since its not valid registry
Expect(session.ErrorToString()).To(ContainSubstring("requested access to the resource is denied"))
// Push should actually fail since it's not valid registry
Expect(session).To(ExitWithError(125, "requested access to the resource is denied"))
Expect(session.OutputToString()).To(Not(ContainSubstring("accepts 2 arg(s), received 1")))

session = podmanTest.Podman([]string{"manifest", "create", amend, "foo"})
Expand Down Expand Up @@ -341,8 +341,8 @@ add_compression = ["zstd"]`), 0o644)
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"manifest", "add", "--annotation", "hoge", "foo", imageList})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("no value given for annotation"))
Expect(session).Should(ExitWithError(125, "no value given for annotation"))

session = podmanTest.Podman([]string{"manifest", "add", "--annotation", "hoge=fuga", "--annotation", "key=val,withcomma", "foo", imageList})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expand Down Expand Up @@ -421,9 +421,18 @@ add_compression = ["zstd"]`), 0o644)
session = podmanTest.Podman([]string{"manifest", "add", "foo", imageList})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"manifest", "remove", "foo", "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"})
bogusID := "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
session = podmanTest.Podman([]string{"manifest", "remove", "foo", bogusID})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())

// FIXME-someday: figure out why message differs in podman-remote
expectMessage := "removing from manifest list foo: "
if IsRemote() {
expectMessage += "removing from manifest foo"
} else {
expectMessage += fmt.Sprintf(`no instance matching digest %q found in manifest list: file does not exist`, bogusID)
}
Expect(session).To(ExitWithError(125, expectMessage))

session = podmanTest.Podman([]string{"manifest", "rm", "foo"})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -493,9 +502,7 @@ RUN touch /file
tmpDir := filepath.Join(podmanTest.TempDir, "wrong-compression")
session = podmanTest.Podman([]string{"manifest", "push", "--compression-format", "gzip", "--compression-level", "50", "foo", "oci:" + tmpDir})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
output := session.ErrorToString()
Expect(output).To(ContainSubstring("invalid compression level"))
Expect(session).Should(ExitWithError(125, "invalid compression level"))

dest := filepath.Join(podmanTest.TempDir, "pushed")
err := os.MkdirAll(dest, os.ModePerm)
Expand Down Expand Up @@ -564,7 +571,7 @@ RUN touch /file

push := podmanTest.Podman([]string{"manifest", "push", "--all", "--tls-verify=false", "--remove-signatures", "foo", "localhost:7000/bogus"})
push.WaitWithDefaultTimeout()
Expect(push).Should(Exit(125))
Expect(push).Should(ExitWithError(125, "Failed, retrying in 1s ... (1/3)"))
Expect(push.ErrorToString()).To(MatchRegexp("Copying blob.*Failed, retrying in 1s \\.\\.\\. \\(1/3\\).*Copying blob.*Failed, retrying in 2s"))
})

Expand Down Expand Up @@ -614,8 +621,7 @@ RUN touch /file

push = podmanTest.Podman([]string{"manifest", "push", "--compression-format=gzip", "--compression-level=2", "--tls-verify=false", "--creds=podmantest:wrongpasswd", "foo", "localhost:" + registry.Port + "/credstest"})
push.WaitWithDefaultTimeout()
Expect(push).To(ExitWithError())
Expect(push.ErrorToString()).To(ContainSubstring(": authentication required"))
Expect(push).To(ExitWithError(125, ": authentication required"))

// push --rm after pull image (#15033)
push = podmanTest.Podman([]string{"manifest", "push", "-q", "--rm", "--tls-verify=false", "--creds=" + registry.User + ":" + registry.Password, "foo", "localhost:" + registry.Port + "/rmtest"})
Expand All @@ -631,8 +637,7 @@ RUN touch /file
It("push with error", func() {
session := podmanTest.Podman([]string{"manifest", "push", "badsrcvalue", "baddestvalue"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("retrieving local image from image name badsrcvalue: badsrcvalue: image not known"))
Expect(session).Should(ExitWithError(125, "retrieving local image from image name badsrcvalue: badsrcvalue: image not known"))
})

It("push --rm to local directory", func() {
Expand All @@ -654,8 +659,8 @@ RUN touch /file
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"manifest", "push", "-p", "foo", "dir:" + dest})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("retrieving local image from image name foo: foo: image not known"))
Expect(session).Should(ExitWithError(125, "retrieving local image from image name foo: foo: image not known"))

session = podmanTest.Podman([]string{"images", "-q", "foo"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expand All @@ -682,9 +687,9 @@ RUN touch /file

session = podmanTest.Podman([]string{"manifest", "rm", "foo", "bar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("foo: image not known"))
Expect(session.ErrorToString()).To(ContainSubstring("bar: image not known"))
Expect(session).Should(ExitWithError(1, " 2 errors occurred:"))
Expect(session.ErrorToString()).To(ContainSubstring("* foo: image not known"))
Expect(session.ErrorToString()).To(ContainSubstring("* bar: image not known"))
})

It("exists", func() {
Expand Down Expand Up @@ -732,8 +737,7 @@ RUN touch /file
// manifest rm should fail with `image is not a manifest list`
session := podmanTest.Podman([]string{"manifest", "rm", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("image is not a manifest list"))
Expect(session).Should(ExitWithError(125, "image is not a manifest list"))

manifestName := "testmanifest:sometag"
session = podmanTest.Podman([]string{"manifest", "create", manifestName})
Expand Down
Loading

1 comment on commit 092d040

@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.