mirror of
https://github.com/containers/podman.git
synced 2025-05-20 00:27:03 +08:00
ExitWithError() - pod_xxx tests
Followup to #22270: wherever possible/practical, extend command error checks to include explicit exit status codes and error strings. This commit handles a subset of test/e2e/pod_xxxx_test.go (I stopped before this grew too huge for review) Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
@ -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() {
|
||||
@ -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() {
|
||||
@ -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() {
|
||||
@ -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() {
|
||||
@ -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() {
|
||||
@ -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() {
|
||||
@ -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"})
|
||||
@ -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() {
|
||||
@ -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"})
|
||||
@ -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() {
|
||||
@ -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"
|
||||
@ -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"))
|
||||
})
|
||||
|
||||
@ -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"
|
||||
@ -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`))
|
||||
|
||||
})
|
||||
|
||||
@ -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() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
. "github.com/containers/podman/v5/test/utils"
|
||||
@ -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()
|
||||
@ -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() {
|
||||
@ -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()
|
||||
@ -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"})
|
||||
|
@ -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() {
|
||||
|
@ -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 pod kill", func() {
|
||||
@ -12,7 +11,11 @@ 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() {
|
||||
@ -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))
|
||||
})
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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"))
|
||||
|
||||
})
|
||||
|
||||
|
@ -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() {
|
||||
@ -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()
|
||||
@ -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() {
|
||||
@ -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() {
|
||||
|
Reference in New Issue
Block a user