diff options
Diffstat (limited to 'test')
27 files changed, 402 insertions, 93 deletions
diff --git a/test/apiv2/01-basic.at b/test/apiv2/01-basic.at index 9d4b04edb..f550d5fc3 100644 --- a/test/apiv2/01-basic.at +++ b/test/apiv2/01-basic.at @@ -59,7 +59,10 @@ t GET info 200 \ .DefaultRuntime~.*$runtime \ .MemTotal~[0-9]\\+ -# Timing: make sure server stays responsive +# Timing: make sure server stays responsive. +# Because /info may need to check storage, it may be slow the first time. +# Let's invoke it once to prime caches, then run ten queries in a timed loop. +t GET info 200 t0=$SECONDS for i in $(seq 1 10); do # FIXME: someday: refactor t(), separate out the 'curl' logic so we @@ -70,7 +73,8 @@ t1=$SECONDS delta_t=$((t1 - t2)) # Desired number of seconds in which we expect to run. -want=7 +# FIXME: 10 seconds is a lot! PR #8076 opened to investigate why. +want=10 if [ $delta_t -le $want ]; then _show_ok 1 "Time for ten /info requests ($delta_t seconds) <= ${want}s" else diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index 7fbcd2e9c..c7055dfc4 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -206,16 +206,6 @@ t POST containers/${cid_top}/stop "" 204 t DELETE containers/$cid 204 t DELETE containers/$cid_top 204 -# test the apiv2 create, shouldn't ignore the ENV and WORKDIR from the image -t POST containers/create '"Image":"'$ENV_WORKDIR_IMG'","Env":["testKey1"]' 201 \ - .Id~[0-9a-f]\\{64\\} -cid=$(jq -r '.Id' <<<"$output") -t GET containers/$cid/json 200 \ - .Config.Env~.*REDIS_VERSION= \ - .Config.Env~.*testKey1= \ - .Config.WorkingDir="/data" # default is /data -t DELETE containers/$cid 204 - # test the WORKDIR and StopSignal t POST containers/create '"Image":"'$ENV_WORKDIR_IMG'","WorkingDir":"/dataDir","StopSignal":"9"' 201 \ .Id~[0-9a-f]\\{64\\} diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2 index 78325eb24..c8ca9df3f 100755 --- a/test/apiv2/test-apiv2 +++ b/test/apiv2/test-apiv2 @@ -179,7 +179,7 @@ function t() { # POST requests require an extra params arg if [[ $method = "POST" ]]; then curl_args="-d $(jsonify $1)" - testname="$testname [$1]" + testname="$testname [$curl_args]" shift fi @@ -204,21 +204,30 @@ function t() { echo "-------------------------------------------------------------" >>$LOG echo "\$ $testname" >>$LOG rm -f $WORKDIR/curl.* - curl -s -X $method ${curl_args} \ - -H 'Content-type: application/json' \ - --dump-header $WORKDIR/curl.headers.out \ - -o $WORKDIR/curl.result.out "$url" - - if [[ $? -eq 7 ]]; then - echo "FATAL: curl failure on $url - cannot continue" >&2 + # -s = silent, but --write-out 'format' gives us important response data + response=$(curl -s -X $method ${curl_args} \ + -H 'Content-type: application/json' \ + --dump-header $WORKDIR/curl.headers.out \ + --write-out '%{http_code}^%{content_type}^%{time_total}' \ + -o $WORKDIR/curl.result.out "$url") + + # Any error from curl is instant bad news, from which we can't recover + rc=$? + if [[ $rc -ne 0 ]]; then + echo "FATAL: curl failure ($rc) on $url - cannot continue" >&2 exit 1 fi - cat $WORKDIR/curl.headers.out >>$LOG 2>/dev/null || true + # Show returned headers (without trailing ^M or empty lines) in log file. + # Sometimes -- I can't remember why! -- we don't get headers. + if [[ -e $WORKDIR/curl.headers.out ]]; then + tr -d '\015' < $WORKDIR/curl.headers.out | egrep '.' >>$LOG + fi - # Log results, if text. If JSON, filter through jq for readability. - content_type=$(sed -ne 's/^Content-Type:[ ]\+//pi' <$WORKDIR/curl.headers.out) + IFS='^' read actual_code content_type time_total <<<"$response" + printf "X-Response-Time: ${time_total}s\n\n" >>$LOG + # Log results, if text. If JSON, filter through jq for readability. if [[ $content_type =~ /octet ]]; then output="[$(file --brief $WORKDIR/curl.result.out)]" echo "$output" >>$LOG @@ -233,10 +242,8 @@ function t() { fi # Test return code - actual_code=$(head -n1 $WORKDIR/curl.headers.out | awk '/^HTTP/ { print $2}') is "$actual_code" "$expected_code" "$testname : status" - # Special case: 204/304, by definition, MUST NOT return content (rfc2616) if [[ $expected_code = 204 || $expected_code = 304 ]]; then if [ -n "$*" ]; then diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index 5155bcbc7..572e55fe5 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -220,7 +220,6 @@ var _ = Describe("Podman build", func() { }) It("podman build --http_proxy flag", func() { - SkipIfRemote("FIXME: This is broken should be fixed") // This is hanging currently. os.Setenv("http_proxy", "1.2.3.4") if IsRemote() { podmanTest.StopRemoteService() diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index e36c86690..206c66f9f 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -235,14 +235,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { ociRuntime := os.Getenv("OCI_RUNTIME") if ociRuntime == "" { - var err error - ociRuntime, err = exec.LookPath("crun") - // If we cannot find the crun binary, setting to something static as we have no way - // to return an error. The tests will fail and point out that the runc binary could - // not be found nicely. - if err != nil { - ociRuntime = "/usr/bin/runc" - } + ociRuntime = "crun" } os.Setenv("DISABLE_HC_SYSTEMD", "true") CNIConfigDir := "/etc/cni/net.d" @@ -673,3 +666,9 @@ func (p *PodmanTestIntegration) PodmanAsUser(args []string, uid, gid uint32, cwd podmanSession := p.PodmanAsUserBase(args, uid, gid, cwd, env, false, false, nil) return &PodmanSessionIntegration{podmanSession} } + +// We don't support running Varlink when local +func (p *PodmanTestIntegration) RestartRemoteService() { + p.StopRemoteService() + p.StartRemoteService() +} diff --git a/test/e2e/events_test.go b/test/e2e/events_test.go index bea8caa93..b37bd584e 100644 --- a/test/e2e/events_test.go +++ b/test/e2e/events_test.go @@ -10,6 +10,7 @@ import ( . "github.com/containers/podman/v2/test/utils" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" ) var _ = Describe("Podman events", func() { @@ -126,26 +127,31 @@ var _ = Describe("Podman events", func() { SkipIfNotFedora() _, ec, _ := podmanTest.RunLsContainer("") Expect(ec).To(Equal(0)) + test := podmanTest.Podman([]string{"events", "--stream=false", "--format", "json"}) test.WaitWithDefaultTimeout() - Expect(test.ExitCode()).To(BeZero()) + Expect(test).To(Exit(0)) + jsonArr := test.OutputToStringArray() - Expect(len(jsonArr)).To(Not(BeZero())) + Expect(test.OutputToStringArray()).ShouldNot(BeEmpty()) + eventsMap := make(map[string]string) err := json.Unmarshal([]byte(jsonArr[0]), &eventsMap) - Expect(err).To(BeNil()) - _, exist := eventsMap["Status"] - Expect(exist).To(BeTrue()) + Expect(err).ToNot(HaveOccurred()) + + Expect(eventsMap).To(HaveKey("Status")) test = podmanTest.Podman([]string{"events", "--stream=false", "--format", "{{json.}}"}) test.WaitWithDefaultTimeout() - Expect(test.ExitCode()).To(BeZero()) + Expect(test).To(Exit(0)) + jsonArr = test.OutputToStringArray() - Expect(len(jsonArr)).To(Not(BeZero())) + Expect(test.OutputToStringArray()).ShouldNot(BeEmpty()) + eventsMap = make(map[string]string) err = json.Unmarshal([]byte(jsonArr[0]), &eventsMap) - Expect(err).To(BeNil()) - _, exist = eventsMap["Status"] - Expect(exist).To(BeTrue()) + Expect(err).ToNot(HaveOccurred()) + + Expect(eventsMap).To(HaveKey("Status")) }) }) diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 3906fa49d..7ab8dc6f8 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -1447,4 +1447,23 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) Expect(inspect.OutputToString()).To(ContainSubstring("Memory: " + expectedMemoryLimit)) } }) + + It("podman play kube reports invalid image name", func() { + invalidImageName := "./myimage" + + pod := getPod( + withCtr( + getCtr( + withImage(invalidImageName), + ), + ), + ) + err := generateKubeYaml("pod", pod, kubeYaml) + Expect(err).To(BeNil()) + + kube := podmanTest.Podman([]string{"play", "kube", kubeYaml}) + kube.WaitWithDefaultTimeout() + Expect(kube.ExitCode()).To(Equal(125)) + Expect(kube.ErrorToString()).To(ContainSubstring(invalidImageName)) + }) }) diff --git a/test/e2e/pod_create_test.go b/test/e2e/pod_create_test.go index f69b6ca7b..83a66d2b9 100644 --- a/test/e2e/pod_create_test.go +++ b/test/e2e/pod_create_test.go @@ -245,6 +245,24 @@ var _ = Describe("Podman pod create", func() { } }) + It("podman container in pod with IP address shares IP address", func() { + SkipIfRootless("Rootless does not support --ip") + podName := "test" + ctrName := "testCtr" + ip := GetRandomIPAddress() + podCreate := podmanTest.Podman([]string{"pod", "create", "--ip", ip, "--name", podName}) + podCreate.WaitWithDefaultTimeout() + Expect(podCreate.ExitCode()).To(Equal(0)) + podCtr := podmanTest.Podman([]string{"run", "--name", ctrName, "--pod", podName, "-d", "-t", ALPINE, "top"}) + podCtr.WaitWithDefaultTimeout() + Expect(podCtr.ExitCode()).To(Equal(0)) + ctrInspect := podmanTest.Podman([]string{"inspect", ctrName}) + ctrInspect.WaitWithDefaultTimeout() + Expect(ctrInspect.ExitCode()).To(Equal(0)) + ctrJSON := ctrInspect.InspectContainerToJSON() + Expect(ctrJSON[0].NetworkSettings.IPAddress).To(Equal(ip)) + }) + It("podman create pod with IP address and no infra should fail", func() { name := "test" ip := GetRandomIPAddress() diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index 48ef566ce..c65738993 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -411,18 +411,43 @@ var _ = Describe("Podman ps", func() { Expect(output).To(ContainSubstring(podName)) }) - It("podman ps test with port range", func() { - session := podmanTest.RunTopContainer("") + It("podman ps test with single port range", func() { + session := podmanTest.Podman([]string{"run", "-dt", "-p", "2000-2006:2000-2006", ALPINE, "top"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - session = podmanTest.Podman([]string{"run", "-dt", "-p", "2000-2006:2000-2006", ALPINE, "top"}) + session = podmanTest.Podman([]string{"ps", "--format", "{{.Ports}}"}) + session.WaitWithDefaultTimeout() + Expect(session.OutputToString()).To(ContainSubstring("0.0.0.0:2000-2006")) + }) + + It("podman ps test with invalid port range", func() { + session := podmanTest.Podman([]string{ + "run", "-p", "1000-2000:2000-3000", "-p", "1999-2999:3001-4001", ALPINE, + }) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(125)) + Expect(session.ErrorToString()).To(ContainSubstring("conflicting port mappings for host port 1999")) + }) + + It("podman ps test with multiple port range", func() { + session := podmanTest.Podman([]string{ + "run", "-dt", + "-p", "3000-3001:3000-3001", + "-p", "3100-3102:4000-4002", + "-p", "30080:30080", + "-p", "30443:30443", + "-p", "8000:8080", + ALPINE, "top"}, + ) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) session = podmanTest.Podman([]string{"ps", "--format", "{{.Ports}}"}) session.WaitWithDefaultTimeout() - Expect(session.OutputToString()).To(ContainSubstring("0.0.0.0:2000-2006")) + Expect(session.OutputToString()).To(ContainSubstring( + "0.0.0.0:3000-3001->3000-3001/tcp, 0.0.0.0:3100-3102->4000-4002/tcp, 0.0.0.0:8000->8080/tcp, 0.0.0.0:30080->30080/tcp, 0.0.0.0:30443->30443/tcp", + )) }) It("podman ps sync flag", func() { diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index e14482db7..540ac5409 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -571,4 +571,19 @@ var _ = Describe("Podman run networking", func() { podrm.WaitWithDefaultTimeout() Expect(podrm.ExitCode()).To(BeZero()) }) + + It("podman run net=host adds entry to /etc/hosts", func() { + run := podmanTest.Podman([]string{"run", "--net=host", ALPINE, "cat", "/etc/hosts"}) + run.WaitWithDefaultTimeout() + Expect(run.ExitCode()).To(BeZero()) + Expect(strings.Contains(run.OutputToString(), "127.0.1.1")).To(BeTrue()) + }) + + It("podman run with --net=host and --hostname sets correct hostname", func() { + hostname := "testctr" + run := podmanTest.Podman([]string{"run", "--net=host", "--hostname", hostname, ALPINE, "hostname"}) + run.WaitWithDefaultTimeout() + Expect(run.ExitCode()).To(BeZero()) + Expect(strings.Contains(run.OutputToString(), "testctr")).To(BeTrue()) + }) }) diff --git a/test/e2e/runlabel_test.go b/test/e2e/runlabel_test.go index 81a746b86..7c0b8bc9b 100644 --- a/test/e2e/runlabel_test.go +++ b/test/e2e/runlabel_test.go @@ -88,12 +88,15 @@ var _ = Describe("podman container runlabel", func() { result := podmanTest.Podman([]string{"container", "runlabel", "RUN", ALPINE}) result.WaitWithDefaultTimeout() Expect(result).To(ExitWithError()) + // should not panic when label missing the value or don't have the label + Expect(result.LineInOutputContains("panic")).NotTo(BeTrue()) }) It("podman container runlabel bogus label in remote image should result in non-zero exit", func() { result := podmanTest.Podman([]string{"container", "runlabel", "RUN", "docker.io/library/ubuntu:latest"}) result.WaitWithDefaultTimeout() Expect(result).To(ExitWithError()) - + // should not panic when label missing the value or don't have the label + Expect(result.LineInOutputContains("panic")).NotTo(BeTrue()) }) It("podman container runlabel global options", func() { diff --git a/test/e2e/search_test.go b/test/e2e/search_test.go index 0cf005529..4f2751099 100644 --- a/test/e2e/search_test.go +++ b/test/e2e/search_test.go @@ -237,7 +237,6 @@ registries = ['{{.Host}}:{{.Port}}']` }) It("podman search attempts HTTP if registry is in registries.insecure and force secure is false", func() { - SkipIfRemote("--tls-verify is not supported on podman-remote search") if podmanTest.Host.Arch == "ppc64le" { Skip("No registry image for ppc64le") } @@ -264,6 +263,10 @@ registries = ['{{.Host}}:{{.Port}}']` registryFileTmpl.Execute(&buffer, registryEndpoints[4]) podmanTest.setRegistriesConfigEnv(buffer.Bytes()) ioutil.WriteFile(fmt.Sprintf("%s/registry4.conf", tempdir), buffer.Bytes(), 0644) + if IsRemote() { + podmanTest.RestartRemoteService() + defer podmanTest.RestartRemoteService() + } search := podmanTest.PodmanNoCache([]string{"search", image}) search.WaitWithDefaultTimeout() @@ -278,7 +281,7 @@ registries = ['{{.Host}}:{{.Port}}']` }) It("podman search doesn't attempt HTTP if force secure is true", func() { - SkipIfRemote("--tls-verify is not supported on podman-remote search") + SkipIfRemote("FIXME This should work on podman-remote") if podmanTest.Host.Arch == "ppc64le" { Skip("No registry image for ppc64le") } @@ -303,6 +306,10 @@ registries = ['{{.Host}}:{{.Port}}']` registryFileTmpl.Execute(&buffer, registryEndpoints[5]) podmanTest.setRegistriesConfigEnv(buffer.Bytes()) ioutil.WriteFile(fmt.Sprintf("%s/registry5.conf", tempdir), buffer.Bytes(), 0644) + if IsRemote() { + podmanTest.RestartRemoteService() + defer podmanTest.RestartRemoteService() + } search := podmanTest.PodmanNoCache([]string{"search", image, "--tls-verify=true"}) search.WaitWithDefaultTimeout() @@ -317,7 +324,7 @@ registries = ['{{.Host}}:{{.Port}}']` }) It("podman search doesn't attempt HTTP if registry is not listed as insecure", func() { - SkipIfRemote("--tls-verify is not supported on podman-remote search") + SkipIfRemote("FIXME This should work on podman-remote") if podmanTest.Host.Arch == "ppc64le" { Skip("No registry image for ppc64le") } @@ -343,6 +350,11 @@ registries = ['{{.Host}}:{{.Port}}']` podmanTest.setRegistriesConfigEnv(buffer.Bytes()) ioutil.WriteFile(fmt.Sprintf("%s/registry6.conf", tempdir), buffer.Bytes(), 0644) + if IsRemote() { + podmanTest.RestartRemoteService() + defer podmanTest.RestartRemoteService() + } + search := podmanTest.PodmanNoCache([]string{"search", image}) search.WaitWithDefaultTimeout() @@ -393,6 +405,11 @@ registries = ['{{.Host}}:{{.Port}}']` podmanTest.setRegistriesConfigEnv(buffer.Bytes()) ioutil.WriteFile(fmt.Sprintf("%s/registry8.conf", tempdir), buffer.Bytes(), 0644) + if IsRemote() { + podmanTest.RestartRemoteService() + defer podmanTest.RestartRemoteService() + } + search := podmanTest.PodmanNoCache([]string{"search", "my-alpine"}) search.WaitWithDefaultTimeout() diff --git a/test/e2e/toolbox_test.go b/test/e2e/toolbox_test.go index 6122cee19..fbff8d19e 100644 --- a/test/e2e/toolbox_test.go +++ b/test/e2e/toolbox_test.go @@ -222,7 +222,7 @@ var _ = Describe("Toolbox-specific testing", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - Expect(WaitContainerReady(podmanTest, "test", "READY", 2, 1)).To(BeTrue()) + Expect(WaitContainerReady(podmanTest, "test", "READY", 5, 1)).To(BeTrue()) expectedOutput := fmt.Sprintf("%s:x:%s:%s::%s:%s", username, uid, gid, homeDir, shell) @@ -257,7 +257,7 @@ var _ = Describe("Toolbox-specific testing", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - Expect(WaitContainerReady(podmanTest, "test", "READY", 2, 1)).To(BeTrue()) + Expect(WaitContainerReady(podmanTest, "test", "READY", 5, 1)).To(BeTrue()) session = podmanTest.Podman([]string{"exec", "test", "cat", "/etc/group"}) session.WaitWithDefaultTimeout() @@ -301,7 +301,7 @@ var _ = Describe("Toolbox-specific testing", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - Expect(WaitContainerReady(podmanTest, "test", "READY", 2, 1)).To(BeTrue()) + Expect(WaitContainerReady(podmanTest, "test", "READY", 5, 1)).To(BeTrue()) expectedUser := fmt.Sprintf("%s:x:%s:%s::%s:%s", username, uid, gid, homeDir, shell) @@ -358,11 +358,23 @@ var _ = Describe("Toolbox-specific testing", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - Expect(WaitContainerReady(podmanTest, "test", "READY", 2, 1)).To(BeTrue()) + Expect(WaitContainerReady(podmanTest, "test", "READY", 5, 1)).To(BeTrue()) session = podmanTest.Podman([]string{"logs", "test"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) Expect(session.OutputToString()).To(ContainSubstring("READY")) }) + + It("podman run --userns=keep-id check $HOME", func() { + var session *PodmanSessionIntegration + + currentUser, err := user.Current() + Expect(err).To(BeNil()) + session = podmanTest.Podman([]string{"run", "-v", fmt.Sprintf("%s:%s", currentUser.HomeDir, currentUser.HomeDir), "--userns=keep-id", fedoraToolbox, "sh", "-c", "echo $HOME"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(session.OutputToString()).To(ContainSubstring(currentUser.HomeDir)) + }) + }) diff --git a/test/e2e/trust_test.go b/test/e2e/trust_test.go index 82b0f9f26..987023e4c 100644 --- a/test/e2e/trust_test.go +++ b/test/e2e/trust_test.go @@ -74,4 +74,26 @@ var _ = Describe("Podman trust", func() { } Expect(teststruct["default"][0]["type"]).To(Equal("insecureAcceptAnything")) }) + + It("podman image trust show --json", func() { + session := podmanTest.Podman([]string{"image", "trust", "show", "--json"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(session.IsJSONOutputValid()).To(BeTrue()) + var teststruct []map[string]string + json.Unmarshal(session.Out.Contents(), &teststruct) + Expect(teststruct[0]["name"]).To(Equal("* (default)")) + Expect(teststruct[0]["repo_name"]).To(Equal("default")) + Expect(teststruct[0]["type"]).To(Equal("accept")) + Expect(teststruct[1]["type"]).To(Equal("insecureAcceptAnything")) + }) + + It("podman image trust show --raw", func() { + session := podmanTest.Podman([]string{"image", "trust", "show", "--raw"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("default")) + Expect(session.OutputToString()).To(ContainSubstring("insecureAcceptAnything")) + }) }) diff --git a/test/e2e/wait_test.go b/test/e2e/wait_test.go index 4f0129a47..aa8a1f245 100644 --- a/test/e2e/wait_test.go +++ b/test/e2e/wait_test.go @@ -46,6 +46,7 @@ var _ = Describe("Podman wait", func() { Expect(session.ExitCode()).To(Equal(0)) session = podmanTest.Podman([]string{"wait", cid}) session.Wait() + Expect(session.ExitCode()).To(Equal(0)) }) It("podman wait on a sleeping container", func() { @@ -55,22 +56,60 @@ var _ = Describe("Podman wait", func() { Expect(session.ExitCode()).To(Equal(0)) session = podmanTest.Podman([]string{"wait", cid}) session.Wait(20) + Expect(session.ExitCode()).To(Equal(0)) }) It("podman wait on latest container", func() { session := podmanTest.Podman([]string{"run", "-d", ALPINE, "sleep", "1"}) session.Wait(20) Expect(session.ExitCode()).To(Equal(0)) - session = podmanTest.Podman([]string{"wait", "-l"}) - session.Wait(20) + if IsRemote() { + session = podmanTest.Podman([]string{"wait", session.OutputToString()}) + } else { + session = podmanTest.Podman([]string{"wait", "-l"}) + } + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) }) It("podman container wait on latest container", func() { session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"}) session.Wait(20) Expect(session.ExitCode()).To(Equal(0)) - session = podmanTest.Podman([]string{"container", "wait", "-l"}) + if IsRemote() { + session = podmanTest.Podman([]string{"container", "wait", session.OutputToString()}) + } else { + session = podmanTest.Podman([]string{"container", "wait", "-l"}) + } + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + It("podman container wait on latest container with --interval flag", func() { + session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"}) session.Wait(20) + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"container", "wait", "-i", "5000", session.OutputToString()}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + It("podman container wait on latest container with --interval flag", func() { + session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"container", "wait", "--interval", "1s", session.OutputToString()}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + It("podman container wait on container with bogus --interval", func() { + session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"container", "wait", "--interval", "100days", session.OutputToString()}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(125)) }) It("podman wait on three containers", func() { diff --git a/test/endpoint/setup.go b/test/endpoint/setup.go index 56cab06b0..6bbc8d2bc 100644 --- a/test/endpoint/setup.go +++ b/test/endpoint/setup.go @@ -51,14 +51,7 @@ func Setup(tempDir string) *EndpointTestIntegration { ociRuntime := os.Getenv("OCI_RUNTIME") if ociRuntime == "" { - var err error - ociRuntime, err = exec.LookPath("runc") - // If we cannot find the runc binary, setting to something static as we have no way - // to return an error. The tests will fail and point out that the runc binary could - // not be found nicely. - if err != nil { - ociRuntime = "/usr/bin/runc" - } + ociRuntime = "runc" } os.Setenv("DISABLE_HC_SYSTEMD", "true") CNIConfigDir := "/etc/cni/net.d" diff --git a/test/system/015-help.bats b/test/system/015-help.bats index 651fdcd09..22db8be8a 100644 --- a/test/system/015-help.bats +++ b/test/system/015-help.bats @@ -6,7 +6,7 @@ # provides its own --help output. If the usage message ends in '[command]', # treat it as a subcommand, and recurse into its own list of sub-subcommands. # -# Any usage message that ends in '[flags]' is interpreted as a command +# Any usage message that ends in '[options]' is interpreted as a command # that takes no further arguments; we confirm by running with 'invalid-arg' # and confirming that it exits with error status and message. # @@ -17,7 +17,7 @@ load helpers function podman_commands() { dprint "$@" run_podman help "$@" |\ - awk '/^Available Commands:/{ok=1;next}/^Flags:/{ok=0}ok { print $1 }' |\ + awk '/^Available Commands:/{ok=1;next}/^Options:/{ok=0}ok { print $1 }' |\ grep . "$output" } @@ -42,7 +42,7 @@ function check_help() { # e.g. 'podman ps' should not show 'podman container ps' in usage # Trailing space in usage handles 'podman system renumber' which - # has no ' [flags]' + # has no ' [options]' is "$usage " " $command_string .*" "Usage string matches command" # If usage ends in '[command]', recurse into subcommands @@ -52,25 +52,25 @@ function check_help() { continue fi - # We had someone write upper-case '[FLAGS]' once. Prevent it. - if expr "$usage" : '.*\[FLAG' >/dev/null; then - die "'flags' string must be lower-case in usage: $usage" + # We had someone write upper-case '[OPTIONS]' once. Prevent it. + if expr "$usage" : '.*\[OPTION' >/dev/null; then + die "'options' string must be lower-case in usage: $usage" fi - # We had someone do 'podman foo ARG [flags]' one time. Yeah, no. - if expr "$usage" : '.*[A-Z].*\[flag' >/dev/null; then - die "'flags' must precede arguments in usage: $usage" + # We had someone do 'podman foo ARG [options]' one time. Yeah, no. + if expr "$usage" : '.*[A-Z].*\[option' >/dev/null; then + die "'options' must precede arguments in usage: $usage" fi - # Cross-check: if usage includes '[flags]', there must be a - # longer 'Flags:' section in the full --help output; vice-versa, - # if 'Flags:' is in full output, usage line must have '[flags]'. - if expr "$usage" : '.*\[flag' >/dev/null; then - if ! expr "$full_help" : ".*Flags:" >/dev/null; then - die "$command_string: Usage includes '[flags]' but has no 'Flags:' subsection" + # Cross-check: if usage includes '[options]', there must be a + # longer 'Options:' section in the full --help output; vice-versa, + # if 'Options:' is in full output, usage line must have '[options]'. + if expr "$usage" : '.*\[option' >/dev/null; then + if ! expr "$full_help" : ".*Options:" >/dev/null; then + die "$command_string: Usage includes '[options]' but has no 'Options:' subsection" fi - elif expr "$full_help" : ".*Flags:" >/dev/null; then - die "$command_string: --help has 'Flags:' section but no '[flags]' in synopsis" + elif expr "$full_help" : ".*Options:" >/dev/null; then + die "$command_string: --help has 'Options:' section but no '[options]' in synopsis" fi # If usage lists no arguments (strings in ALL CAPS), confirm @@ -102,7 +102,7 @@ function check_help() { # If usage has required arguments, try running without them. # The expression here is 'first capital letter is not in [BRACKETS]'. - # It is intended to handle 'podman foo [flags] ARG' but not ' [ARG]'. + # It is intended to handle 'podman foo [options] ARG' but not ' [ARG]'. if expr "$usage" : '[^A-Z]\+ [A-Z]' >/dev/null; then # Exceptions: these commands don't work rootless if is_rootless; then diff --git a/test/system/030-run.bats b/test/system/030-run.bats index 766948ecc..9f4037730 100644 --- a/test/system/030-run.bats +++ b/test/system/030-run.bats @@ -303,8 +303,36 @@ echo $rand | 0 | $rand # This would always work on root, but is new behavior on rootless: #6829 # adds a user entry to /etc/passwd + whoami=$(id -un) run_podman run --rm --userns=keep-id $IMAGE id -un - is "$output" "$(id -un)" "username on container with keep-id" + is "$output" "$whoami" "username on container with keep-id" + + # Setting user should also set $HOME (#8013). + # Test setup below runs three cases: one with an existing home dir + # and two without (one without any volume mounts, one with a misspelled + # username). In every case, initial cwd should be /home/podman because + # that's the container-defined WORKDIR. In the case of an existing + # home dir, $HOME and ~ (passwd entry) will be /home/user; otherwise + # they should be /home/podman. + if is_rootless; then + tests=" + | /home/podman /home/podman /home/podman | no vol mount +/home/x$whoami | /home/podman /home/podman /home/podman | bad vol mount +/home/$whoami | /home/podman /home/$whoami /home/$whoami | vol mount +" + while read vol expect name; do + opts= + if [[ "$vol" != "''" ]]; then + opts="-v $vol" + fi + run_podman run --rm $opts --userns=keep-id \ + $IMAGE sh -c 'echo $(pwd;printenv HOME;echo ~)' + is "$output" "$expect" "run with --userns=keep-id and $name sets \$HOME" + done < <(parse_table "$tests") + + # Clean up volumes + run_podman volume rm -a + fi # --privileged should make no difference run_podman run --rm --privileged --userns=keep-id $IMAGE id -un @@ -432,4 +460,17 @@ json-file | f is "$output" "$expect" "podman run with --tz=local, matches host" } +# run with --runtime should preserve the named runtime +@test "podman run : full path to --runtime is preserved" { + skip_if_cgroupsv1 + skip_if_remote + run_podman run -d --runtime '/usr/bin/crun' $IMAGE sleep 60 + cid="$output" + + run_podman inspect --format '{{.OCIRuntime}}' $cid + is "$output" "/usr/bin/crun" + + run_podman kill $cid +} + # vim: filetype=sh diff --git a/test/system/055-rm.bats b/test/system/055-rm.bats index 7176ae4b8..0107114b5 100644 --- a/test/system/055-rm.bats +++ b/test/system/055-rm.bats @@ -41,11 +41,14 @@ load helpers run_podman create --name $rand $IMAGE /bin/true # Create a container that podman does not know about - run buildah from $IMAGE - cid="$output" + external_cid=$(buildah from $IMAGE) + + # Plain 'exists' should fail, but should succeed with --external + run_podman 1 container exists $external_cid + run_podman container exists --external $external_cid # rm should succeed - run_podman rm $rand $cid + run_podman rm $rand $external_cid } # I'm sorry! This test takes 13 seconds. There's not much I can do about it, diff --git a/test/system/070-build.bats b/test/system/070-build.bats index 287323bbf..0741357ed 100644 --- a/test/system/070-build.bats +++ b/test/system/070-build.bats @@ -224,6 +224,12 @@ EOF # Confirm that 'podman inspect' shows the expected values # FIXME: can we rely on .Env[0] being PATH, and the rest being in order?? run_podman image inspect build_test + + # (Assert that output is formatted, not a one-line blob: #8011) + if [[ "${#lines[*]}" -lt 10 ]]; then + die "Output from 'image inspect' is only ${#lines[*]} lines; see #8011" + fi + tests=" Env[1] | MYENV1=$s_env1 Env[2] | MYENV2=this-should-be-overridden-by-env-host diff --git a/test/system/140-diff.bats b/test/system/140-diff.bats index 01ec5430e..1277f9bbe 100644 --- a/test/system/140-diff.bats +++ b/test/system/140-diff.bats @@ -32,4 +32,26 @@ load helpers run_podman rm $n } +@test "podman diff with buildah container " { + rand_file=$(random_string 10) + buildah from --name buildahctr $IMAGE + buildah run buildahctr sh -c "touch /$rand_file;rm /etc/services" + + run_podman diff --format json buildahctr + + # Expected results for each type of diff + declare -A expect=( + [added]="/$rand_file" + [changed]="/etc" + [deleted]="/etc/services" + ) + + for field in ${!expect[@]}; do + result=$(jq -r -c ".${field}[]" <<<"$output") + is "$result" "${expect[$field]}" "$field" + done + + buildah rm buildahctr +} + # vim: filetype=sh diff --git a/test/system/160-volumes.bats b/test/system/160-volumes.bats index 1c1e0f4ae..9f4bb76a2 100644 --- a/test/system/160-volumes.bats +++ b/test/system/160-volumes.bats @@ -213,6 +213,12 @@ EOF run_podman volume create $vol done + # (Assert that output is formatted, not a one-line blob: #8011) + run_podman volume inspect ${v[1]} + if [[ "${#lines[*]}" -lt 10 ]]; then + die "Output from 'volume inspect' is only ${#lines[*]} lines; see #8011" + fi + # Run two containers: one mounting v1, one mounting v2 & v3 run_podman run --name c1 --volume ${v[1]}:/vol1 $IMAGE date run_podman run --name c2 --volume ${v[2]}:/vol2 -v ${v[3]}:/vol3 \ diff --git a/test/system/200-pod.bats b/test/system/200-pod.bats index 2ae038dfe..1d17c8cad 100644 --- a/test/system/200-pod.bats +++ b/test/system/200-pod.bats @@ -66,6 +66,12 @@ function teardown() { run_podman pod exists $podname run_podman pod exists $podid + # (Assert that output is formatted, not a one-line blob: #8021) + run_podman pod inspect $podname + if [[ "${#lines[*]}" -lt 10 ]]; then + die "Output from 'pod inspect' is only ${#lines[*]} lines; see #8011" + fi + # Randomly-assigned port in the 5xxx range for port in $(shuf -i 5000-5999);do if ! { exec 3<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then diff --git a/test/system/260-sdnotify.bats b/test/system/260-sdnotify.bats index 06aa3bba7..c99ba4fa6 100644 --- a/test/system/260-sdnotify.bats +++ b/test/system/260-sdnotify.bats @@ -12,8 +12,6 @@ _SOCAT_LOG= function setup() { skip_if_remote "systemd tests are meaningless over remote" - skip "FIXME FIXME FIXME, is this what's causing the CI hang???" - # Skip if systemd is not running systemctl list-units &>/dev/null || skip "systemd not available" @@ -109,6 +107,7 @@ function _assert_mainpid_is_conmon() { # Done. Stop container, clean up. run_podman exec $cid touch /stop + run_podman wait $cid run_podman rm $cid _stop_socat } @@ -144,6 +143,7 @@ function _assert_mainpid_is_conmon() { # Done. Stop container, clean up. run_podman exec $cid touch /stop + run_podman wait $cid run_podman rm $cid run_podman rmi $_FEDORA _stop_socat diff --git a/test/system/420-cgroups.bats b/test/system/420-cgroups.bats new file mode 100644 index 000000000..615e43e6c --- /dev/null +++ b/test/system/420-cgroups.bats @@ -0,0 +1,34 @@ +#!/usr/bin/env bats -*- bats -*- +# +# cgroups-related tests +# + +load helpers + +@test "podman run, preserves initial --cgroup-manager" { + skip_if_remote "podman-remote does not support --cgroup-manager" + + if is_rootless && is_cgroupsv1; then + skip "not supported as rootless under cgroups v1" + fi + + # Find out our default cgroup manager, and from that, get the non-default + run_podman info --format '{{.Host.CgroupManager}}' + case "$output" in + systemd) other="cgroupfs" ;; + cgroupfs) other="systemd" ;; + *) die "Unknown CgroupManager '$output'" ;; + esac + + run_podman --cgroup-manager=$other run --name myc $IMAGE true + run_podman container inspect --format '{{.HostConfig.CgroupManager}}' myc + is "$output" "$other" "podman preserved .HostConfig.CgroupManager" + + # Restart the container, without --cgroup-manager option (ie use default) + # Prior to #7970, this would fail with an OCI runtime error + run_podman start myc + + run_podman rm myc +} + +# vim: filetype=sh diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats index a923402ac..44cc731cf 100644 --- a/test/system/500-networking.bats +++ b/test/system/500-networking.bats @@ -90,7 +90,12 @@ load helpers run_podman network create --subnet "${mysubnet}.0/24" $mynetname is "$output" ".*/cni/net.d/$mynetname.conflist" "output of 'network create'" - # WARNING: this pulls a ~100MB image from quay.io, hence is slow/flaky + # (Assert that output is formatted, not a one-line blob: #8011) + run_podman network inspect $mynetname + if [[ "${#lines[*]}" -lt 5 ]]; then + die "Output from 'pod inspect' is only ${#lines[*]} lines; see #8011" + fi + run_podman run --rm --network $mynetname $IMAGE ip a is "$output" ".* inet ${mysubnet}\.2/24 brd ${mysubnet}\.255 " \ "sdfsdf" diff --git a/test/system/helpers.bash b/test/system/helpers.bash index c6c2c12df..2cced10c2 100644 --- a/test/system/helpers.bash +++ b/test/system/helpers.bash @@ -34,6 +34,14 @@ function basic_setup() { # Clean up all containers run_podman rm --all --force + # ...including external (buildah) ones + run_podman ps --all --external --format '{{.ID}} {{.Names}}' + for line in "${lines[@]}"; do + set $line + echo "# setup(): removing stray external container $1 ($2)" >&3 + run_podman rm $1 + done + # Clean up all images except those desired found_needed_image= run_podman images --all --format '{{.Repository}}:{{.Tag}} {{.ID}}' @@ -245,9 +253,10 @@ function is_cgroupsv1() { ! is_cgroupsv2 } +# True if cgroups v2 are enabled function is_cgroupsv2() { cgroup_type=$(stat -f -c %T /sys/fs/cgroup) - test "$cgroup_type" = "cgroupfs" + test "$cgroup_type" = "cgroup2fs" } ########################### @@ -297,6 +306,15 @@ function skip_if_no_selinux() { fi } +####################### +# skip_if_cgroupsv1 # ...with an optional message +####################### +function skip_if_cgroupsv1() { + if ! is_cgroupsv2; then + skip "${1:-test requires cgroupsv2}" + fi +} + ######### # die # Abort with helpful message ######### |