Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExitWithError() - more r files #22661

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/e2e/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ = Describe("podman rename", func() {
It("podman rename on non-existent container", func() {
session := podmanTest.Podman([]string{"rename", "doesNotExist", "aNewName"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, `no container with name or ID "doesNotExist" found: no such container`))
})

It("Podman rename on existing container with bad name", func() {
Expand All @@ -25,7 +25,7 @@ var _ = Describe("podman rename", func() {
newName := "invalid<>:char"
rename := podmanTest.Podman([]string{"rename", ctrName, newName})
rename.WaitWithDefaultTimeout()
Expect(rename).To(ExitWithError())
Expect(rename).To(ExitWithError(125, "names must match [a-zA-Z0-9][a-zA-Z0-9_.-]*: invalid argument"))

ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", ctrName), "--format", "{{ .Names }}"})
ps.WaitWithDefaultTimeout()
Expand Down
31 changes: 12 additions & 19 deletions test/e2e/run_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,9 @@ var _ = Describe("Podman run networking", func() {
session := podmanTest.RunContainerWithNetworkTest("none")
session.WaitWithDefaultTimeout()
if _, found := os.LookupEnv("http_proxy"); found {
Expect(session).Should(Exit(5))
Expect(session.ErrorToString()).To(ContainSubstring("Could not resolve proxy:"))
Expect(session).Should(ExitWithError(5, "Could not resolve proxy:"))
} else {
Expect(session).Should(Exit(6))
Expect(session.ErrorToString()).To(ContainSubstring("Could not resolve host: www.redhat.com"))
Expect(session).Should(ExitWithError(6, "Could not resolve host: www.redhat.com"))
}
})

Expand Down Expand Up @@ -498,7 +496,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
Expect(results.OutputToString()).To(ContainSubstring(strconv.Itoa(port2)))

ncBusy := SystemExec("nc", []string{"-l", "-p", strconv.Itoa(port1)})
Expect(ncBusy).To(ExitWithError())
Expect(ncBusy).To(ExitWithError(2, fmt.Sprintf("Ncat: bind to 0.0.0.0:%d: Address already in use. QUITTING.", port1)))
})

It("podman run network expose host port 18081 to container port 8000 using rootlesskit port handler", func() {
Expand All @@ -509,7 +507,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
Expect(session).Should(ExitCleanly())

ncBusy := SystemExec("nc", []string{"-l", "-p", strconv.Itoa(port2)})
Expect(ncBusy).To(ExitWithError())
Expect(ncBusy).To(ExitWithError(2, fmt.Sprintf("Ncat: bind to [::]:%d: Address already in use. QUITTING.", port2)))
})

It("podman run slirp4netns verify net.ipv6.conf.default.accept_dad=0", func() {
Expand All @@ -534,13 +532,13 @@ EXPOSE 2004-2005/tcp`, ALPINE)

It("podman run network expose host port 8080 to container port 8000 using invalid port handler", func() {
session := podmanTest.Podman([]string{"run", "--network", "slirp4netns:port_handler=invalid", "-dt", "-p", "8080:8000", ALPINE, "/bin/sh"})
session.Wait(30)
Expect(session).To(ExitWithError())
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError(126, `unknown port_handler for slirp4netns: "invalid"`))
})

It("podman run slirp4netns network with host loopback", func() {
session := podmanTest.Podman([]string{"run", "--cap-add", "net_raw", "--network", "slirp4netns:allow_host_loopback=true", ALPINE, "ping", "-c1", "10.0.2.2"})
session.Wait(30)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
})

Expand All @@ -562,8 +560,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
if strings.Contains(slirp4netnsHelp.OutputToString(), "cidr") {
Expect(session).Should(ExitCleanly())
} else {
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("cidr not supported"))
Expect(session).To(ExitWithError(125, "cidr not supported"))
}
})

Expand All @@ -585,8 +582,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
} else {
session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, "-dt", ALPINE, "nc", "-w", "2", "10.0.2.2", port})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("outbound_addr not supported"))
Expect(session).To(ExitWithError(125, "outbound_addr not supported"))
}
})

Expand Down Expand Up @@ -615,8 +611,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
} else {
session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, ALPINE, "nc", "-w", "2", "10.0.2.2", port})
session.Wait(30)
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("outbound_addr not supported"))
Expect(session).To(ExitWithError(125, "outbound_addr not supported"))
}
})

Expand Down Expand Up @@ -723,8 +718,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)

ctr2 := podmanTest.Podman([]string{"run", "-d", "--net=container:" + ctrName, "--add-host", "host1:127.0.0.1", ALPINE, "true"})
ctr2.WaitWithDefaultTimeout()
Expect(ctr2).Should(ExitWithError())
Expect(ctr2.ErrorToString()).Should(ContainSubstring("cannot set extra host entries when the container is joined to another containers network namespace: invalid configuration"))
Expect(ctr2).Should(ExitWithError(125, "cannot set extra host entries when the container is joined to another containers network namespace: invalid configuration"))
})

It("podman run --net container: copies hosts and resolv", func() {
Expand Down Expand Up @@ -972,8 +966,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
It("podman run network in bogus user created network namespace", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--net", "ns:/run/netns/xxy", ALPINE, "wget", "www.redhat.com"})
session.Wait(90)
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("faccessat /run/netns/xxy: no such file or directory"))
Expect(session).To(ExitWithError(125, "faccessat /run/netns/xxy: no such file or directory"))
})

It("podman run in custom CNI network with --static-ip", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/run_signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = Describe("Podman run with --sig-proxy", func() {
Expect(killSession).Should(ExitCleanly())

session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(2, "SIGFPE: floating-point exception"))
Expect(session.OutputToString()).To(Not(ContainSubstring("Received")))
})

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/run_staticip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ var _ = Describe("Podman run with --ip flag", func() {
It("Podman run --ip with garbage address", func() {
result := podmanTest.Podman([]string{"run", "--ip", "114232346", ALPINE, "ls"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
Expect(result).To(ExitWithError(125, `"114232346" is not an ip address`))
})

It("Podman run --ip with v6 address", func() {
result := podmanTest.Podman([]string{"run", "--ip", "2001:db8:bad:beef::1", ALPINE, "ls"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
Expect(result).To(ExitWithError(126, "requested static ip 2001:db8:bad:beef::1 not in any subnet on network podman"))
})

It("Podman run --ip with non-allocatable IP", func() {
result := podmanTest.Podman([]string{"run", "--ip", "203.0.113.124", ALPINE, "ls"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
Expect(result).To(ExitWithError(126, "requested static ip 203.0.113.124 not in any subnet on network podman"))
})

It("Podman run with specified static IP has correct IP", func() {
Expand Down
24 changes: 13 additions & 11 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var _ = Describe("Podman run with volumes", func() {

session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=tmpfs,target=/etc/ssl,tmpcopyup,notmpcopyup", ALPINE, "ls", "/etc/ssl"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "cannot pass 'tmpcopyup' and 'notmpcopyup' mnt.Options more than once: must provide an argument for option"))

// test csv escaping
session = podmanTest.Podman([]string{"run", "--rm", "--mount=type=tmpfs,tmpfs-size=512M,\"destination=/test,\"", ALPINE, "ls", "/test,"})
Expand All @@ -106,11 +106,11 @@ var _ = Describe("Podman run with volumes", func() {

session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=bind,src=/tmp,target=/tmp,tmpcopyup", ALPINE, "true"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, `"tmpcopyup" option not supported for "bind" mount types`))

session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=bind,src=/tmp,target=/tmp,notmpcopyup", ALPINE, "true"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, `"notmpcopyup" option not supported for "bind" mount types`))

session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=tmpfs,target=/etc/ssl,notmpcopyup", ALPINE, "ls", "/etc/ssl"})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -161,7 +161,7 @@ var _ = Describe("Podman run with volumes", func() {

session = podmanTest.Podman([]string{"run", "--rm", "--mount", mount + ",ro=true,rw=false", ALPINE, "grep", dest, "/proc/self/mountinfo"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "cannot pass 'readonly', 'ro', or 'rw' mnt.Options more than once: must provide an argument for option"))
})

It("podman run with volume flag and multiple named volumes", func() {
Expand Down Expand Up @@ -344,7 +344,7 @@ var _ = Describe("Podman run with volumes", func() {
It("podman run with noexec can't exec", func() {
session := podmanTest.Podman([]string{"run", "--rm", "-v", "/bin:/hostbin:noexec", ALPINE, "/hostbin/ls", "/"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(126, "ermission denied"))
})

It("podman run with tmpfs named volume mounts and unmounts", func() {
Expand Down Expand Up @@ -569,7 +569,7 @@ RUN sh -c "cd /etc/apk && ln -s ../../testfile"`, ALPINE)

volMount := podmanTest.Podman([]string{"run", "--rm", "-v", fmt.Sprintf("%s:/tmp", volName), ALPINE, "ls"})
volMount.WaitWithDefaultTimeout()
Expect(volMount).To(ExitWithError())
Expect(volMount).To(ExitWithError(126, "mounting volume testVol for container "))
})

It("Podman fix for CVE-2020-1726", func() {
Expand Down Expand Up @@ -667,7 +667,7 @@ VOLUME /test/`, ALPINE)
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"exec", "-l", "ls", "/run/test/container"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(1, "ls: /run/test/container: No such file or directory"))
})

It("overlay volume conflicts with named volume and mounts", func() {
Expand All @@ -688,18 +688,20 @@ VOLUME /test/`, ALPINE)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())

expectErr := fmt.Sprintf("%s: duplicate mount destination", mountDest)

// overlay and named volume destinations conflict
session = podmanTest.Podman([]string{"run", "--rm", "-v", fmt.Sprintf("%s:%s:O", mountPath, mountDest), "-v", fmt.Sprintf("%s:%s", volName, mountDest), ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, expectErr))
// overlay and bind mount destinations conflict
session = podmanTest.Podman([]string{"run", "--rm", "-v", fmt.Sprintf("%s:%s:O", mountPath, mountDest), "--mount", fmt.Sprintf("type=bind,src=%s,target=%s", mountSrc, mountDest), ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, expectErr))
// overlay and tmpfs mount destinations conflict
session = podmanTest.Podman([]string{"run", "--rm", "-v", fmt.Sprintf("%s:%s:O", mountPath, mountDest), "--mount", fmt.Sprintf("type=tmpfs,target=%s", mountDest), ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, expectErr))
})

It("same volume in multiple places does not deadlock", func() {
Expand Down Expand Up @@ -788,7 +790,7 @@ VOLUME /test/`, ALPINE)
vol = "type=bind,src=" + mountPath + ",dst=" + dest + ",U=invalid"
session = podmanTest.Podman([]string{"run", "--rm", "--user", "888:888", "--mount", vol, ALPINE, "stat", "-c", "%u:%g", dest})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, `'U' or 'chown' must be set to true or false, instead received "invalid": must provide an argument for option`))

// true bind mount
vol = "type=bind,src=" + mountPath + ",dst=" + dest + ",U=true"
Expand Down