diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/e2e/inspect_test.go | 10 | ||||
-rw-r--r-- | test/e2e/play_kube_test.go | 81 | ||||
-rw-r--r-- | test/e2e/run_test.go | 16 | ||||
-rw-r--r-- | test/e2e/save_test.go | 4 | ||||
-rw-r--r-- | test/e2e/start_test.go | 24 | ||||
-rw-r--r-- | test/system/330-corrupt-images.bats | 134 |
6 files changed, 267 insertions, 2 deletions
diff --git a/test/e2e/inspect_test.go b/test/e2e/inspect_test.go index 772ebed05..ba018b5ad 100644 --- a/test/e2e/inspect_test.go +++ b/test/e2e/inspect_test.go @@ -508,4 +508,14 @@ var _ = Describe("Podman inspect", func() { Expect(data[0].HostConfig.CapDrop[1]).To(Equal("CAP_MKNOD")) Expect(data[0].HostConfig.CapDrop[2]).To(Equal("CAP_NET_RAW")) }) + + It("podman inspect container with GO format for PidFile", func() { + SkipIfRemote("pidfile not handled by remote") + session, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) + + session = podmanTest.Podman([]string{"inspect", "--format", "{{.PidFile}}", "test1"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) }) diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index e479b88cc..f89da4c05 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -12,6 +12,7 @@ import ( "github.com/containers/podman/v3/pkg/util" . "github.com/containers/podman/v3/test/utils" + "github.com/containers/storage/pkg/stringid" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/opencontainers/selinux/go-selinux" @@ -1716,6 +1717,38 @@ spec: } }) + It("podman play kube --ip", func() { + var i, numReplicas int32 + numReplicas = 3 + deployment := getDeployment(withReplicas(numReplicas)) + err := generateKubeYaml("deployment", deployment, kubeYaml) + Expect(err).To(BeNil()) + + net := "playkube" + stringid.GenerateNonCryptoID() + session := podmanTest.Podman([]string{"network", "create", "--subnet", "10.25.31.0/24", net}) + session.WaitWithDefaultTimeout() + defer podmanTest.removeCNINetwork(net) + Expect(session.ExitCode()).To(BeZero()) + + ips := []string{"10.25.31.5", "10.25.31.10", "10.25.31.15"} + playArgs := []string{"play", "kube", "--network", net} + for _, ip := range ips { + playArgs = append(playArgs, "--ip", ip) + } + + kube := podmanTest.Podman(append(playArgs, kubeYaml)) + kube.WaitWithDefaultTimeout() + Expect(kube.ExitCode()).To(Equal(0)) + + podNames := getPodNamesInDeployment(deployment) + for i = 0; i < numReplicas; i++ { + inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(&podNames[i]), "--format", "{{ .NetworkSettings.Networks." + net + ".IPAddress }}"}) + inspect.WaitWithDefaultTimeout() + Expect(inspect.ExitCode()).To(Equal(0)) + Expect(inspect.OutputToString()).To(Equal(ips[i])) + } + }) + It("podman play kube test with network portbindings", func() { ip := "127.0.0.100" port := "5000" @@ -1861,6 +1894,54 @@ spec: Expect(inspect.OutputToString()).To(ContainSubstring(correct)) }) + It("podman play kube test duplicate volume destination between host path and image volumes", func() { + // Create host test directory and file + testdir := "testdir" + testfile := "testfile" + + hostPathDir := filepath.Join(tempdir, testdir) + err := os.Mkdir(hostPathDir, 0755) + Expect(err).To(BeNil()) + + hostPathDirFile := filepath.Join(hostPathDir, testfile) + f, err := os.Create(hostPathDirFile) + Expect(err).To(BeNil()) + f.Close() + + // Create container image with named volume + containerfile := fmt.Sprintf(` +FROM %s +VOLUME %s`, ALPINE, hostPathDir+"/") + + image := "podman-kube-test:podman" + podmanTest.BuildImage(containerfile, image, "false") + + // Create and play kube pod + ctr := getCtr(withVolumeMount(hostPathDir+"/", false), withImage(image)) + pod := getPod(withCtr(ctr), withVolume(getHostPathVolume("Directory", hostPathDir+"/"))) + err = generateKubeYaml("pod", pod, kubeYaml) + Expect(err).To(BeNil()) + + kube := podmanTest.Podman([]string{"play", "kube", kubeYaml}) + kube.WaitWithDefaultTimeout() + Expect(kube.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "ls", hostPathDir + "/" + testfile}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + + inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod)}) + inspect.WaitWithDefaultTimeout() + Expect(inspect.ExitCode()).To(Equal(0)) + + // If two volumes are specified and share the same destination, + // only one will be mounted. Host path volumes take precedence. + ctrJSON := inspect.InspectContainerToJSON() + Expect(len(ctrJSON[0].Mounts)).To(Equal(1)) + Expect(ctrJSON[0].Mounts[0].Type).To(Equal("bind")) + + }) + It("podman play kube test with PersistentVolumeClaim volume", func() { volumeName := "namedVolume" diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index cefe00655..93505d742 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -1613,4 +1613,20 @@ WORKDIR /madethis`, BB) Expect(running.ExitCode()).To(Equal(0)) Expect(len(running.OutputToStringArray())).To(Equal(2)) }) + + It("podman run with pidfile", func() { + SkipIfRemote("pidfile not handled by remote") + pidfile := tempdir + "pidfile" + session := podmanTest.Podman([]string{"run", "--pidfile", pidfile, ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + readFirstLine := func(path string) string { + content, err := ioutil.ReadFile(path) + Expect(err).To(BeNil()) + return strings.Split(string(content), "\n")[0] + } + containerPID := readFirstLine(pidfile) + _, err = strconv.Atoi(containerPID) // Make sure it's a proper integer + Expect(err).To(BeNil()) + }) }) diff --git a/test/e2e/save_test.go b/test/e2e/save_test.go index 42ee7440b..69184649f 100644 --- a/test/e2e/save_test.go +++ b/test/e2e/save_test.go @@ -79,7 +79,7 @@ var _ = Describe("Podman save", func() { }) It("podman save to directory with oci format", func() { - if rootless.IsRootless() && podmanTest.RemoteTest { + if rootless.IsRootless() { Skip("Requires a fix in containers image for chown/lchown") } outdir := filepath.Join(podmanTest.TempDir, "save") @@ -90,7 +90,7 @@ var _ = Describe("Podman save", func() { }) It("podman save to directory with v2s2 docker format", func() { - if rootless.IsRootless() && podmanTest.RemoteTest { + if rootless.IsRootless() { Skip("Requires a fix in containers image for chown/lchown") } outdir := filepath.Join(podmanTest.TempDir, "save") diff --git a/test/e2e/start_test.go b/test/e2e/start_test.go index f527b67f6..cb2db0810 100644 --- a/test/e2e/start_test.go +++ b/test/e2e/start_test.go @@ -1,7 +1,10 @@ package integration import ( + "io/ioutil" "os" + "strconv" + "strings" . "github.com/containers/podman/v3/test/utils" . "github.com/onsi/ginkgo" @@ -206,4 +209,25 @@ var _ = Describe("Podman start", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(125)) }) + + It("podman start container with special pidfile", func() { + SkipIfRemote("pidfile not handled by remote") + pidfile := tempdir + "pidfile" + session := podmanTest.Podman([]string{"create", "--pidfile", pidfile, ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + session = podmanTest.Podman([]string{"start", cid}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + readFirstLine := func(path string) string { + content, err := ioutil.ReadFile(path) + Expect(err).To(BeNil()) + return strings.Split(string(content), "\n")[0] + } + containerPID := readFirstLine(pidfile) + _, err = strconv.Atoi(containerPID) // Make sure it's a proper integer + Expect(err).To(BeNil()) + }) }) diff --git a/test/system/330-corrupt-images.bats b/test/system/330-corrupt-images.bats new file mode 100644 index 000000000..9836de363 --- /dev/null +++ b/test/system/330-corrupt-images.bats @@ -0,0 +1,134 @@ +#!/usr/bin/env bats -*- bats -*- +# +# All tests in here perform nasty manipulations on image storage. +# + +load helpers + +############################################################################### +# BEGIN setup/teardown + +# Create a scratch directory; this is what we'll use for image store and cache +if [ -z "${PODMAN_CORRUPT_TEST_WORKDIR}" ]; then + export PODMAN_CORRUPT_TEST_WORKDIR=$(mktemp -d --tmpdir=${BATS_TMPDIR:-${TMPDIR:-/tmp}} podman_corrupt_test.XXXXXX) +fi + +PODMAN_CORRUPT_TEST_IMAGE_FQIN=quay.io/libpod/alpine@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00 +PODMAN_CORRUPT_TEST_IMAGE_ID=961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4 + +# All tests in this file (and ONLY in this file) run with a custom rootdir +function setup() { + skip_if_remote "none of these tests run under podman-remote" + _PODMAN_TEST_OPTS="--root ${PODMAN_CORRUPT_TEST_WORKDIR}/root" +} + +function teardown() { + # No other tests should ever run with this custom rootdir + unset _PODMAN_TEST_OPTS + + is_remote && return + + # Clean up + umount ${PODMAN_CORRUPT_TEST_WORKDIR}/root/overlay || true + if is_rootless; then + run_podman unshare rm -rf ${PODMAN_CORRUPT_TEST_WORKDIR}/root + else + rm -rf ${PODMAN_CORRUPT_TEST_WORKDIR}/root + fi +} + +# END setup/teardown +############################################################################### +# BEGIN primary test helper + +# This is our main action, invoked by every actual test. It: +# - creates a new empty rootdir +# - populates it with our crafted test image +# - removes [ manifest, blob ] +# - confirms that "podman images" throws an error +# - runs the specified command (rmi -a -f, prune, reset, etc) +# - confirms that it succeeds, and also emits expected warnings +function _corrupt_image_test() { + # Run this test twice: once removing manifest, once removing blob + for what_to_rm in manifest blob; do + # I have no idea, but this sometimes remains mounted + umount ${PODMAN_CORRUPT_TEST_WORKDIR}/root/overlay || true + # Start with a fresh storage root, load prefetched image into it. + /bin/rm -rf ${PODMAN_CORRUPT_TEST_WORKDIR}/root + mkdir -p ${PODMAN_CORRUPT_TEST_WORKDIR}/root + run_podman load -i ${PODMAN_CORRUPT_TEST_WORKDIR}/img.tar + # "podman load" restores it without a tag, which (a) causes rmi-by-name + # to fail, and (b) causes "podman images" to exit 0 instead of 125 + run_podman tag ${PODMAN_CORRUPT_TEST_IMAGE_ID} ${PODMAN_CORRUPT_TEST_IMAGE_FQIN} + + # shortcut variable name + local id=${PODMAN_CORRUPT_TEST_IMAGE_ID} + + case "$what_to_rm" in + manifest) rm_path=manifest ;; + blob) rm_path="=$(echo -n "sha256:$id" | base64 -w0)" ;; + *) die "Internal error: unknown action '$what_to_rm'" ;; + esac + + # Corruptify, and confirm that 'podman images' throws an error + rm -v ${PODMAN_CORRUPT_TEST_WORKDIR}/root/*-images/$id/${rm_path} + run_podman 125 images + is "$output" "Error: error retrieving label for image \"$id\": you may need to remove the image to resolve the error" + + # Run the requested command. Confirm it succeeds, with suitable warnings + run_podman $* + is "$output" ".*error determining parent of image" \ + "$* with missing $what_to_rm" + + run_podman images -a --noheading + is "$output" "" "podman images -a, after $*, is empty" + done +} + +# END primary test helper +############################################################################### +# BEGIN first "test" does a one-time pull of our desired image + +@test "podman corrupt images - initialize" { + # Pull once, save cached copy. + run_podman pull $PODMAN_CORRUPT_TEST_IMAGE_FQIN + run_podman save -o ${PODMAN_CORRUPT_TEST_WORKDIR}/img.tar \ + $PODMAN_CORRUPT_TEST_IMAGE_FQIN +} + +# END first "test" does a one-time pull of our desired image +############################################################################### +# BEGIN actual tests + +@test "podman corrupt images - rmi -f <image-id>" { + _corrupt_image_test "rmi -f ${PODMAN_CORRUPT_TEST_IMAGE_ID}" +} + +@test "podman corrupt images - rmi -f <image-name>" { + _corrupt_image_test "rmi -f ${PODMAN_CORRUPT_TEST_IMAGE_FQIN}" +} + +@test "podman corrupt images - rmi -f -a" { + _corrupt_image_test "rmi -f -a" +} + +@test "podman corrupt images - image prune" { + _corrupt_image_test "image prune -a -f" +} + +@test "podman corrupt images - system reset" { + _corrupt_image_test "image prune -a -f" +} + +# END actual tests +############################################################################### +# BEGIN final cleanup + +@test "podman corrupt images - cleanup" { + rm -rf ${PODMAN_CORRUPT_TEST_WORKDIR} +} + +# END final cleanup +############################################################################### + +# vim: filetype=sh |