From eaf60c7fe7dd7d1aa6ea2df9ac2c1056968a4111 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Thu, 28 Mar 2024 06:46:05 -0600 Subject: [PATCH] e2e tests: use /var/tmp, not $TMPDIR, as workdirs TMPDIR is typically /tmp which is typically(*) a tmpfs. This PR ignores $TMPDIR when $CI is defined, forcing all e2e tests to set up one central working directory in /var/tmp instead. Also, lots of cleanup. (*) For many years, up to and still including the time of this PR, /tmp on Fedora CI VMs is actually NOT tmpfs, it is just / (root). This is nonstandard and undesirable. Efforts are underway to remove this special case. Signed-off-by: Ed Santiago --- .cirrus.yml | 2 +- contrib/cirrus/runner.sh | 2 +- test/e2e/common_test.go | 83 ++++++++++++----------- test/e2e/quadlet/basic.kube | 4 +- test/e2e/quadlet/configmap.kube | 2 +- test/e2e/quadlet/downforce.kube | 2 +- test/e2e/quadlet/env-file.container | 2 +- test/e2e/quadlet/mount.container | 4 +- test/e2e/quadlet/oneshot.kube | 4 +- test/e2e/quadlet/volume.container | 2 +- test/e2e/quadlet/volume.pod | 2 +- test/e2e/quadlet/workingdir-unit.kube | 2 +- test/e2e/quadlet/workingdir-yaml-rel.kube | 2 +- test/e2e/quadlet_test.go | 4 +- test/e2e/run_networking_test.go | 8 --- test/utils/common_function_test.go | 6 -- test/utils/utils.go | 5 -- 17 files changed, 61 insertions(+), 75 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index cd7841180f..ef396fac41 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -33,7 +33,7 @@ env: DEBIAN_NAME: "debian-13" # Image identifiers - IMAGE_SUFFIX: "c20240409t192511z-f39f38d13" + IMAGE_SUFFIX: "c20240411t124913z-f39f38d13" # EC2 images FEDORA_AMI: "fedora-aws-${IMAGE_SUFFIX}" diff --git a/contrib/cirrus/runner.sh b/contrib/cirrus/runner.sh index 017c08f7ef..33a600b219 100755 --- a/contrib/cirrus/runner.sh +++ b/contrib/cirrus/runner.sh @@ -143,7 +143,7 @@ exec_container() { set -x # shellcheck disable=SC2154 exec bin/podman run --rm --privileged --net=host --cgroupns=host \ - -v `mktemp -d -p /var/tmp`:/tmp:Z \ + -v `mktemp -d -p /var/tmp`:/var/tmp:Z \ -v /dev/fuse:/dev/fuse \ -v "$GOPATH:$GOPATH:Z" \ --workdir "$GOSRC" \ diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index a0e715f717..24c6ad0878 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -62,6 +62,7 @@ type PodmanTestIntegration struct { TmpDir string } +var GlobalTmpDir string // Single top-level tmpdir for all tests var LockTmpDir string // PodmanSessionIntegration struct for command line session @@ -101,14 +102,14 @@ func TestLibpod(t *testing.T) { } var ( - tempdir string + tempdir string // Working dir for _one_ subtest err error podmanTest *PodmanTestIntegration safeIPOctets [2]uint8 timingsFile *os.File _ = BeforeEach(func() { - tempdir, err = CreateTempDirInTempDir() + tempdir, err = os.MkdirTemp(GlobalTmpDir, "subtest-") Expect(err).ToNot(HaveOccurred()) podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() @@ -130,26 +131,34 @@ var ( ) const ( - // lockdir - do not use directly use LockTmpDir + // lockdir - do not use directly; use LockTmpDir lockdir = "libpodlock" // imageCacheDir - do not use directly use ImageCacheDir imageCacheDir = "imagecachedir" ) var _ = SynchronizedBeforeSuite(func() []byte { - globalTmpDir := GinkgoT().TempDir() + // One global scratch directory under which all test files will live. + // The usual case is that these tests are running in CI, on VMs + // with limited RAM, so we use /var/tmp. + baseTmpDir := "/var/tmp" + if os.Getenv("CI") == "" { + // Almost certainly a manual run, e.g., a developer with + // a hotrod workstation. Assume they know what they're doing. + baseTmpDir = "" + } + globalTmpDir, err := os.MkdirTemp(baseTmpDir, "podman-e2e-") + Expect(err).ToNot(HaveOccurred()) // make cache dir ImageCacheDir = filepath.Join(globalTmpDir, imageCacheDir) - if err := os.MkdirAll(ImageCacheDir, 0700); err != nil { - GinkgoWriter.Printf("%q\n", err) - os.Exit(1) - } + err = os.MkdirAll(ImageCacheDir, 0700) + Expect(err).ToNot(HaveOccurred()) // Cache images cwd, _ := os.Getwd() INTEGRATION_ROOT = filepath.Join(cwd, "../../") - podman := PodmanTestSetup(GinkgoT().TempDir()) + podman := PodmanTestSetup(filepath.Join(globalTmpDir, "image-init")) // Pull cirros but don't put it into the cache pullImages := []string{CIRROS_IMAGE, fedoraToolbox, volumeTest} @@ -177,16 +186,16 @@ var _ = SynchronizedBeforeSuite(func() []byte { podman.StopRemoteService() } - // remove temporary podman files, images are now cached in ImageCacheDir + // remove temporary podman files; images are now cached in ImageCacheDir rmAll(podman.PodmanBinary, podman.TempDir) return []byte(globalTmpDir) }, func(data []byte) { cwd, _ := os.Getwd() INTEGRATION_ROOT = filepath.Join(cwd, "../../") - globalTmpDir := string(data) - ImageCacheDir = filepath.Join(globalTmpDir, imageCacheDir) - LockTmpDir = filepath.Join(globalTmpDir, lockdir) + GlobalTmpDir = string(data) + ImageCacheDir = filepath.Join(GlobalTmpDir, imageCacheDir) + LockTmpDir = filepath.Join(GlobalTmpDir, lockdir) timingsFile, err = os.Create(fmt.Sprintf("%s/timings-%d", LockTmpDir, GinkgoParallelProcess())) Expect(err).ToNot(HaveOccurred()) @@ -229,7 +238,7 @@ var _ = SynchronizedAfterSuite(func() { } cwd, _ := os.Getwd() - rmAll(getPodmanBinary(cwd), ImageCacheDir) + rmAll(getPodmanBinary(cwd), GlobalTmpDir) }) func getPodmanBinary(cwd string) string { @@ -242,40 +251,38 @@ func getPodmanBinary(cwd string) string { // PodmanTestCreate creates a PodmanTestIntegration instance for the tests func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { - var podmanRemoteBinary string - host := GetHostDistributionInfo() cwd, _ := os.Getwd() root := filepath.Join(tempDir, "root") podmanBinary := getPodmanBinary(cwd) - podmanRemoteBinary = filepath.Join(cwd, "../../bin/podman-remote") - if os.Getenv("PODMAN_REMOTE_BINARY") != "" { - podmanRemoteBinary = os.Getenv("PODMAN_REMOTE_BINARY") + podmanRemoteBinary := os.Getenv("PODMAN_REMOTE_BINARY") + if podmanRemoteBinary == "" { + podmanRemoteBinary = filepath.Join(cwd, "../../bin/podman-remote") } - quadletBinary := filepath.Join(cwd, "../../bin/quadlet") - if os.Getenv("QUADLET_BINARY") != "" { - quadletBinary = os.Getenv("QUADLET_BINARY") + quadletBinary := os.Getenv("QUADLET_BINARY") + if quadletBinary == "" { + quadletBinary = filepath.Join(cwd, "../../bin/quadlet") } - conmonBinary := "/usr/libexec/podman/conmon" - altConmonBinary := "/usr/bin/conmon" - if _, err := os.Stat(conmonBinary); os.IsNotExist(err) { - conmonBinary = altConmonBinary - } - if os.Getenv("CONMON_BINARY") != "" { - conmonBinary = os.Getenv("CONMON_BINARY") + conmonBinary := os.Getenv("CONMON_BINARY") + if conmonBinary == "" { + conmonBinary = "/usr/libexec/podman/conmon" + if _, err := os.Stat(conmonBinary); errors.Is(err, os.ErrNotExist) { + conmonBinary = "/usr/bin/conmon" + } } - storageOptions := STORAGE_OPTIONS - if os.Getenv("STORAGE_OPTIONS") != "" { - storageOptions = os.Getenv("STORAGE_OPTIONS") + + storageOptions := os.Getenv("STORAGE_OPTIONS") + if storageOptions == "" { + storageOptions = STORAGE_OPTIONS } - cgroupManager := CGROUP_MANAGER - if os.Getenv("CGROUP_MANAGER") != "" { - cgroupManager = os.Getenv("CGROUP_MANAGER") + cgroupManager := os.Getenv("CGROUP_MANAGER") + if cgroupManager == "" { + cgroupManager = CGROUP_MANAGER } ociRuntime := os.Getenv("OCI_RUNTIME") @@ -390,10 +397,8 @@ func (p PodmanTestIntegration) AddImageToRWStore(image string) { func imageTarPath(image string) string { cacheDir := os.Getenv("PODMAN_TEST_IMAGE_CACHE_DIR") if cacheDir == "" { - cacheDir = os.Getenv("TMPDIR") - if cacheDir == "" { - cacheDir = "/tmp" - } + // Avoid /tmp: it may be tmpfs, and these images are large + cacheDir = "/var/tmp" } // e.g., registry.com/fubar:latest -> registry.com-fubar-latest.tar diff --git a/test/e2e/quadlet/basic.kube b/test/e2e/quadlet/basic.kube index 1f2bc16dc6..0c5bb76182 100644 --- a/test/e2e/quadlet/basic.kube +++ b/test/e2e/quadlet/basic.kube @@ -1,11 +1,11 @@ ## assert-podman-args "kube" ## assert-podman-args "play" -## assert-podman-final-args-regex .*/podman_test.*/quadlet/deployment.yml +## assert-podman-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml ## assert-podman-args "--replace" ## assert-podman-args "--service-container=true" ## assert-podman-stop-post-args "kube" ## assert-podman-stop-post-args "down" -## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml +## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml ## assert-key-is "Unit" "RequiresMountsFor" "%t/containers" ## assert-key-is "Service" "KillMode" "mixed" ## assert-key-is "Service" "Type" "notify" diff --git a/test/e2e/quadlet/configmap.kube b/test/e2e/quadlet/configmap.kube index 6e09fcd8c6..49c42b7e13 100644 --- a/test/e2e/quadlet/configmap.kube +++ b/test/e2e/quadlet/configmap.kube @@ -1,5 +1,5 @@ ## assert-podman-args "--configmap" "/opt/k8s/abs.yml" -## assert-podman-args-regex "--configmap" ".*/podman_test.*/quadlet/rel.yml" +## assert-podman-args-regex "--configmap" ".*/podman-e2e-.*/subtest-.*/quadlet/rel.yml" [Kube] Yaml=deployment.yml diff --git a/test/e2e/quadlet/downforce.kube b/test/e2e/quadlet/downforce.kube index 19f5fd1b85..081971e8f2 100644 --- a/test/e2e/quadlet/downforce.kube +++ b/test/e2e/quadlet/downforce.kube @@ -1,7 +1,7 @@ ## assert-podman-stop-post-args "kube" ## assert-podman-stop-post-args "down" ## assert-podman-stop-post-args "--force" -## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml +## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml [Kube] Yaml=deployment.yml diff --git a/test/e2e/quadlet/env-file.container b/test/e2e/quadlet/env-file.container index 47bdf7cae4..ebb9549889 100644 --- a/test/e2e/quadlet/env-file.container +++ b/test/e2e/quadlet/env-file.container @@ -1,7 +1,7 @@ ## assert-podman-final-args localhost/imagename ## assert-podman-args --env-file /opt/env/abs-1 ## assert-podman-args --env-file /opt/env/abs-2 -## assert-podman-args-regex --env-file /.*/podman_test.*/quadlet/rel-1 +## assert-podman-args-regex --env-file /.*/podman-e2e-.*/subtest-.*/quadlet/rel-1 ## assert-podman-args --env-file %h/env [Container] diff --git a/test/e2e/quadlet/mount.container b/test/e2e/quadlet/mount.container index 5e16aebc99..b982b73837 100644 --- a/test/e2e/quadlet/mount.container +++ b/test/e2e/quadlet/mount.container @@ -18,11 +18,11 @@ Mount=type=tmpfs,tmpfs-size=512M,destination=/path/in/container Mount=type=image,source=fedora,destination=/fedora-image,rw=true ## assert-podman-args-key-val "--mount" "," "type=devpts,destination=/dev/pts" Mount=type=devpts,destination=/dev/pts -## assert-podman-args-key-val-regex "--mount" "," "type=bind,source=.*/podman_test.*/quadlet/path/on/host,destination=/path/in/container" +## assert-podman-args-key-val-regex "--mount" "," "type=bind,source=.*/podman-e2e-.*/subtest-.*/quadlet/path/on/host,destination=/path/in/container" Mount=type=bind,source=./path/on/host,destination=/path/in/container ## assert-podman-args-key-val "--mount" "," "type=volume,source=vol1,destination=/path/in/container,ro" Mount=type=volume,source=vol1,destination=/path/in/container,ro ## assert-podman-args-key-val "--mount" "," "type=bind,source=/tmp,\"dst=/path,1\"" Mount=type=bind,src=/tmp,\"dst=/path,1\" -## assert-podman-args-key-val-regex "--mount" "," "type=bind,source=.*/podman_test.*/quadlet/src,destination=/dst/,idmap=uids=12-34-1;gids=56-78-1" +## assert-podman-args-key-val-regex "--mount" "," "type=bind,source=.*/podman-e2e-.*/subtest-.*/quadlet/src,destination=/dst/,idmap=uids=12-34-1;gids=56-78-1" Mount=type=bind,source=./src/,destination=/dst/,idmap=uids=12-34-1;gids=56-78-1 diff --git a/test/e2e/quadlet/oneshot.kube b/test/e2e/quadlet/oneshot.kube index 1b96e10337..f743617e85 100644 --- a/test/e2e/quadlet/oneshot.kube +++ b/test/e2e/quadlet/oneshot.kube @@ -1,11 +1,11 @@ ## assert-podman-args "kube" ## assert-podman-args "play" -## assert-podman-final-args-regex .*/podman_test.*/quadlet/deployment.yml +## assert-podman-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml ## assert-podman-args "--replace" ## assert-podman-args "--service-container=true" ## assert-podman-stop-post-args "kube" ## assert-podman-stop-post-args "down" -## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml +## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml ## assert-key-is "Unit" "RequiresMountsFor" "%t/containers" ## assert-key-is "Service" "KillMode" "mixed" ## assert-key-is "Service" "Type" "oneshot" diff --git a/test/e2e/quadlet/volume.container b/test/e2e/quadlet/volume.container index 934ce6f335..b3d033c6f8 100644 --- a/test/e2e/quadlet/volume.container +++ b/test/e2e/quadlet/volume.container @@ -1,6 +1,6 @@ ## assert-podman-args -v /host/dir:/container/volume ## assert-podman-args -v /host/dir2:/container/volume2:Z -## assert-podman-args-regex -v .*/podman_test.*/quadlet/host/dir3:/container/volume3 +## assert-podman-args-regex -v .*/podman-e2e-.*/subtest-.*/quadlet/host/dir3:/container/volume3 ## assert-podman-args -v named:/container/named ## assert-podman-args -v systemd-quadlet:/container/quadlet ## assert-podman-args -v %h/container:/container/volume4 diff --git a/test/e2e/quadlet/volume.pod b/test/e2e/quadlet/volume.pod index 7950b0ab54..b2fa6117fa 100644 --- a/test/e2e/quadlet/volume.pod +++ b/test/e2e/quadlet/volume.pod @@ -1,6 +1,6 @@ ## assert-podman-pre-args -v /host/dir:/container/volume ## assert-podman-pre-args -v /host/dir2:/container/volume2:Z -## assert-podman-pre-args-regex -v .*/podman_test.*/quadlet/host/dir3:/container/volume3 +## assert-podman-pre-args-regex -v .*/podman-e2e-.*/subtest-.*/quadlet/host/dir3:/container/volume3 ## assert-podman-pre-args -v named:/container/named ## assert-podman-pre-args -v systemd-quadlet:/container/quadlet ## assert-podman-pre-args -v %h/container:/container/volume4 diff --git a/test/e2e/quadlet/workingdir-unit.kube b/test/e2e/quadlet/workingdir-unit.kube index ef6adef606..ffc7d04849 100644 --- a/test/e2e/quadlet/workingdir-unit.kube +++ b/test/e2e/quadlet/workingdir-unit.kube @@ -1,4 +1,4 @@ -## assert-key-is-regex "Service" "WorkingDirectory" ".*/podman_test.*/quadlet" +## assert-key-is-regex "Service" "WorkingDirectory" ".*/podman-e2e-.*/subtest-.*/quadlet" [Kube] Yaml=deployment.yml diff --git a/test/e2e/quadlet/workingdir-yaml-rel.kube b/test/e2e/quadlet/workingdir-yaml-rel.kube index ddde1c361d..5a5823833b 100644 --- a/test/e2e/quadlet/workingdir-yaml-rel.kube +++ b/test/e2e/quadlet/workingdir-yaml-rel.kube @@ -1,4 +1,4 @@ -## assert-key-is-regex "Service" "WorkingDirectory" ".*/podman_test.*/quadlet/myservice" +## assert-key-is-regex "Service" "WorkingDirectory" ".*/podman-e2e-.*/subtest-.*/quadlet/myservice" [Kube] Yaml=./myservice/deployment.yml diff --git a/test/e2e/quadlet_test.go b/test/e2e/quadlet_test.go index 238e02326c..92c21cbd0b 100644 --- a/test/e2e/quadlet_test.go +++ b/test/e2e/quadlet_test.go @@ -695,12 +695,12 @@ BOGUS=foo "---basic.service---", "## assert-podman-args \"kube\"", "## assert-podman-args \"play\"", - "## assert-podman-final-args-regex .*/podman_test.*/quadlet/deployment.yml", + "## assert-podman-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml", "## assert-podman-args \"--replace\"", "## assert-podman-args \"--service-container=true\"", "## assert-podman-stop-post-args \"kube\"", "## assert-podman-stop-post-args \"down\"", - "## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml", + "## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml", "## assert-key-is \"Unit\" \"RequiresMountsFor\" \"%t/containers\"", "## assert-key-is \"Service\" \"KillMode\" \"mixed\"", "## assert-key-is \"Service\" \"Type\" \"notify\"", diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index 0576a3aa87..8e26a5ee44 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -532,14 +532,6 @@ EXPOSE 2004-2005/tcp`, ALPINE) Expect(session.OutputToString()).To(Equal(sysctlValue)) }) - It("podman run network expose host port 18082 to container port 8000 using slirp4netns port handler", func() { - session := podmanTest.Podman([]string{"run", "--network", "slirp4netns:port_handler=slirp4netns", "-dt", "-p", "18082:8000", ALPINE, "/bin/sh"}) - session.Wait(30) - Expect(session).Should(ExitCleanly()) - ncBusy := SystemExec("nc", []string{"-l", "-p", "18082"}) - Expect(ncBusy).To(ExitWithError()) - }) - 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) diff --git a/test/utils/common_function_test.go b/test/utils/common_function_test.go index 8f2ac2af1f..6d6c49dcb7 100644 --- a/test/utils/common_function_test.go +++ b/test/utils/common_function_test.go @@ -27,12 +27,6 @@ var _ = Describe("Common functions test", func() { ProcessOneCgroupPath = defaultCgroupPath }) - It("Test CreateTempDirInTempDir", func() { - tmpDir, _ := CreateTempDirInTempDir() - _, err := os.Stat(tmpDir) - Expect(os.IsNotExist(err)).ShouldNot(BeTrue(), "Directory is not created as expect") - }) - It("Test SystemExec", func() { session := SystemExec(GoechoPath, []string{}) Expect(session.Command.Process).ShouldNot(BeNil(), "SystemExec cannot start a process") diff --git a/test/utils/utils.go b/test/utils/utils.go index b3f0a17fca..72af69d555 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -376,11 +376,6 @@ func (s *PodmanSession) WaitWithTimeout(timeout int) { os.Stderr.Sync() } -// CreateTempDirInTempDir create a temp dir with prefix podman_test -func CreateTempDirInTempDir() (string, error) { - return os.MkdirTemp("", "podman_test") -} - // SystemExec is used to exec a system command to check its exit code or output func SystemExec(command string, args []string) *PodmanSession { c := exec.Command(command, args...)