Skip to content

Commit

Permalink
Merge pull request #22552 from edsantiago/exitwitherror-part3
Browse files Browse the repository at this point in the history
ExitWithError() - pod_xxx tests
  • Loading branch information
openshift-merge-bot[bot] authored May 3, 2024
2 parents c9644eb + 275c068 commit 6ec2c0b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 34 deletions.
38 changes: 22 additions & 16 deletions test/e2e/pod_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var _ = Describe("Podman pod create", func() {
name := "test"
session := podmanTest.Podman([]string{"pod", "create", "--infra=false", "--name", name, "-p", "80:80"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "you must have an infra container to publish port bindings to the host"))
})

It("podman create pod with --no-hosts", func() {
Expand All @@ -126,7 +126,7 @@ var _ = Describe("Podman pod create", func() {
name := "test"
podCreate := podmanTest.Podman([]string{"pod", "create", "--no-hosts", "--name", name, "--infra=false"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "cannot specify --no-hosts without an infra container"))
})

It("podman create pod with --add-host", func() {
Expand All @@ -145,7 +145,7 @@ var _ = Describe("Podman pod create", func() {
name := "test"
podCreate := podmanTest.Podman([]string{"pod", "create", "--add-host", "test.example.com:12.34.56.78", "--name", name, "--infra=false"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "NoInfra and HostAdd are mutually exclusive pod options: invalid pod spec"))
})

It("podman create pod with DNS server set", func() {
Expand All @@ -166,7 +166,7 @@ var _ = Describe("Podman pod create", func() {
server := "12.34.56.78"
podCreate := podmanTest.Podman([]string{"pod", "create", "--dns", server, "--name", name, "--infra=false"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "NoInfra and DNSServer are mutually exclusive pod options: invalid pod spec"))
})

It("podman create pod with DNS option set", func() {
Expand All @@ -187,7 +187,7 @@ var _ = Describe("Podman pod create", func() {
option := "attempts:5"
podCreate := podmanTest.Podman([]string{"pod", "create", "--dns-opt", option, "--name", name, "--infra=false"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "NoInfra and DNSOption are mutually exclusive pod options: invalid pod spec"))
})

It("podman create pod with DNS search domain set", func() {
Expand All @@ -208,7 +208,7 @@ var _ = Describe("Podman pod create", func() {
search := "example.com"
podCreate := podmanTest.Podman([]string{"pod", "create", "--dns-search", search, "--name", name, "--infra=false"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "NoInfo and DNSSearch are mutually exclusive pod options: invalid pod spec"))
})

It("podman create pod with IP address", func() {
Expand All @@ -218,7 +218,7 @@ var _ = Describe("Podman pod create", func() {
podCreate.WaitWithDefaultTimeout()
// Rootless should error without network
if isRootless() {
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "invalid config provided: networks and static ip/mac address can only be used with Bridge mode networking"))
} else {
Expect(podCreate).Should(ExitCleanly())
podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "--rm", ALPINE, "ip", "addr"})
Expand Down Expand Up @@ -251,7 +251,7 @@ var _ = Describe("Podman pod create", func() {
ip := GetSafeIPAddress()
podCreate := podmanTest.Podman([]string{"pod", "create", "--ip", ip, "--name", name, "--infra=false"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "cannot set --ip without infra container: invalid argument"))
})

It("podman create pod with MAC address", func() {
Expand All @@ -261,7 +261,7 @@ var _ = Describe("Podman pod create", func() {
podCreate.WaitWithDefaultTimeout()
// Rootless should error
if isRootless() {
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "invalid config provided: networks and static ip/mac address can only be used with Bridge mode networking"))
} else {
Expect(podCreate).Should(ExitCleanly())
podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "--rm", ALPINE, "ip", "addr"})
Expand All @@ -276,7 +276,7 @@ var _ = Describe("Podman pod create", func() {
mac := "92:d0:c6:0a:29:35"
podCreate := podmanTest.Podman([]string{"pod", "create", "--mac-address", mac, "--name", name, "--infra=false"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "cannot set --mac without infra container: invalid argument"))
})

It("podman create pod and print id to external file", func() {
Expand All @@ -302,9 +302,9 @@ var _ = Describe("Podman pod create", func() {

It("podman pod create --replace", func() {
// Make sure we error out with --name.
session := podmanTest.Podman([]string{"pod", "create", "--replace", ALPINE, "/bin/sh"})
session := podmanTest.Podman([]string{"pod", "create", "--replace"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "cannot replace pod without --name being set"))

// Create and replace 5 times in a row the "same" pod.
podName := "testCtr"
Expand Down Expand Up @@ -460,7 +460,7 @@ entrypoint ["/fromimage"]
It("podman create with unsupported network options", func() {
podCreate := podmanTest.Podman([]string{"pod", "create", "--network", "container:doesnotmatter"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(Exit(125))
Expect(podCreate).Should(ExitWithError(125, "pods presently do not support network mode container"))
Expect(podCreate.ErrorToString()).To(ContainSubstring("pods presently do not support network mode container"))
})

Expand Down Expand Up @@ -586,7 +586,7 @@ ENTRYPOINT ["sleep","99999"]

podCreate = podmanTest.Podman([]string{"pod", "create", "--pid", ns, "--name", podName, "--share", "pid"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(ExitWithError())
Expect(podCreate).Should(ExitWithError(125, "cannot use pod namespace as container is not joining a pod or pod has no infra container: invalid argument"))

podName = "pidPod3"
ns = "host"
Expand Down Expand Up @@ -619,7 +619,13 @@ ENTRYPOINT ["sleep","99999"]

podCreate = podmanTest.Podman([]string{"pod", "create", "--pid", ns, "--name", podName, "--share", "pid"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(ExitWithError())
// This can fail in two ways, depending on intricate SELinux specifics:
// There are actually two different failure messages:
// container "randomfakeid" not found: no container with name ...
// looking up container to share pid namespace with: no container with name ...
// Too complicated to differentiate in test context, so we ignore the first part
// and just check for the "no container" substring, which is common to both.
Expect(podCreate).Should(ExitWithError(125, `no container with name or ID "randomfakeid" found: no such container`))

})

Expand Down Expand Up @@ -656,7 +662,7 @@ ENTRYPOINT ["sleep","99999"]
// fail if --pod and --userns set together
session = podmanTest.Podman([]string{"run", "--pod", podName, "--userns", "keep-id", ALPINE, "id", "-u"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "--userns and --pod cannot be set together"))
})

It("podman pod create with --userns=keep-id can add users", func() {
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/pod_infra_container_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"fmt"
"strconv"

. "github.com/containers/podman/v5/test/utils"
Expand Down Expand Up @@ -101,7 +102,7 @@ var _ = Describe("Podman pod create", func() {

session = podmanTest.Podman([]string{"run", fedoraMinimal, "curl", "-f", "localhost"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(7, "Failed to connect to localhost port 80 "))

session = podmanTest.Podman([]string{"pod", "create", "--network", "host"})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -220,7 +221,7 @@ var _ = Describe("Podman pod create", func() {

session = podmanTest.Podman([]string{"run", "--pod", podID, "--network", "bridge", NGINX_IMAGE, "curl", "-f", "localhost"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(7, "Failed to connect to localhost port 80 "))
})

It("podman pod container can override pod pid NS", func() {
Expand Down Expand Up @@ -311,14 +312,14 @@ var _ = Describe("Podman pod create", func() {
Expect(session).Should(ExitCleanly())
podID := session.OutputToString()

session = podmanTest.Podman([]string{"ps", "-aq"})
session = podmanTest.Podman([]string{"ps", "-aq", "--no-trunc"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
infraID := session.OutputToString()

session = podmanTest.Podman([]string{"rm", infraID})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, fmt.Sprintf("container %s is the infra container of pod %s and cannot be removed without removing the pod", infraID, podID)))

session = podmanTest.Podman([]string{"pod", "rm", podID})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -384,8 +385,7 @@ var _ = Describe("Podman pod create", func() {

session = podmanTest.Podman([]string{"create", "--pod", podID, "--add-host", "foobar:127.0.0.1", ALPINE, "ping", "-c", "1", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("extra host entries must be specified on the pod: network cannot be configured when it is shared with a pod"))
Expect(session).Should(ExitWithError(125, "extra host entries must be specified on the pod: network cannot be configured when it is shared with a pod"))

// verify we can see the pods hosts
session = podmanTest.Podman([]string{"run", "--cap-add", "net_raw", "--pod", podID, ALPINE, "ping", "-c", "1", "host1"})
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/pod_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ var _ = Describe("Podman pod inspect", func() {
It("podman inspect bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "inspect", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError())
expect := "no such pod foobar"
if IsRemote() {
expect = `no such pod "foobar"`
}
Expect(session).Should(ExitWithError(125, expect))
})

It("podman inspect a pod", func() {
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/pod_kill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ 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 pod kill", func() {

It("podman pod kill bogus", func() {
session := podmanTest.Podman([]string{"pod", "kill", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
expect := "no pod with name or ID foobar found: no such pod"
if IsRemote() {
expect = `unable to find pod "foobar": no such pod`
}
Expect(session).To(ExitWithError(125, expect))
})

It("podman pod kill a pod by id", func() {
Expand Down Expand Up @@ -71,7 +74,7 @@ var _ = Describe("Podman pod kill", func() {

result := podmanTest.Podman([]string{"pod", "kill", "-s", "bogus", "test1"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "invalid signal: bogus"))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
})

Expand Down
12 changes: 10 additions & 2 deletions test/e2e/pod_pause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ var _ = Describe("Podman pod pause", func() {
It("podman pod pause bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "pause", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
expect := "no pod with name or ID foobar found: no such pod"
if IsRemote() {
expect = `unable to find pod "foobar": no such pod`
}
Expect(session).To(ExitWithError(125, expect))
})

It("podman unpause bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "unpause", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
expect := "no pod with name or ID foobar found: no such pod"
if IsRemote() {
expect = `unable to find pod "foobar": no such pod`
}
Expect(session).To(ExitWithError(125, expect))
})

It("podman pod pause a created pod by id", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/pod_ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var _ = Describe("Podman ps", func() {
It("podman pod ps mutually exclusive flags", func() {
session := podmanTest.Podman([]string{"pod", "ps", "-q", "--format", "{{.ID}}"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "quiet and format cannot be used together"))

})

Expand Down
25 changes: 20 additions & 5 deletions test/e2e/pod_rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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 pod rm", func() {
Expand Down Expand Up @@ -122,7 +121,7 @@ var _ = Describe("Podman pod rm", func() {
GinkgoWriter.Printf("Removing all empty pods\n")
result := podmanTest.Podman([]string{"pod", "rm", "-a"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
Expect(result).To(ExitWithError(125, "it is running - running or paused containers cannot be removed without force: container state improper"))
Expect(result.ErrorToString()).To(ContainSubstring("not all containers could be removed from pod"))

numPods = podmanTest.NumberOfPods()
Expand Down Expand Up @@ -176,7 +175,11 @@ var _ = Describe("Podman pod rm", func() {
It("podman rm bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "rm", "bogus"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
expect := "no pod with name or ID bogus found: no such pod"
if IsRemote() {
expect = `unable to find pod "bogus": no such pod`
}
Expect(session).Should(ExitWithError(1, expect))
})

It("podman rm bogus pod and a running pod", func() {
Expand All @@ -189,11 +192,23 @@ var _ = Describe("Podman pod rm", func() {

session = podmanTest.Podman([]string{"pod", "rm", "bogus", "test1"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
expect := "no pod with name or ID bogus found: no such pod"
if IsRemote() {
expect = `unable to find pod "bogus": no such pod`
}
Expect(session).Should(ExitWithError(1, expect))

session = podmanTest.Podman([]string{"pod", "rm", "test1", "bogus"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
// FIXME-someday: consolidate different error messages
expect = "no pod with name or ID test1 found"
if podmanTest.DatabaseBackend == "boltdb" {
expect = "test1 is a container, not a pod"
}
if IsRemote() {
expect = `unable to find pod "test1"`
}
Expect(session).Should(ExitWithError(1, expect+": no such pod"))
})

It("podman rm --ignore bogus pod and a running pod", func() {
Expand Down

1 comment on commit 6ec2c0b

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