diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index bb6de0c694..a4b211b331 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -211,16 +211,10 @@ var _ = Describe("Podman build", func() { Expect(os.Chdir(os.TempDir())).To(Succeed()) defer Expect(os.Chdir(cwd)).To(BeNil()) - // Write target and fake files - targetPath, err := CreateTempDirInTempDir() - if err != nil { - os.Exit(1) - } - fakeFile := filepath.Join(os.TempDir(), "Containerfile") Expect(os.WriteFile(fakeFile, []byte(fmt.Sprintf("FROM %s", ALPINE)), 0755)).To(Succeed()) - targetFile := filepath.Join(targetPath, "Containerfile") + targetFile := filepath.Join(podmanTest.TempDir, "Containerfile") Expect(os.WriteFile(targetFile, []byte("FROM scratch"), 0755)).To(Succeed()) defer func() { @@ -247,11 +241,7 @@ var _ = Describe("Podman build", func() { Expect(os.Chdir(os.TempDir())).To(Succeed()) defer Expect(os.Chdir(cwd)).To(BeNil()) - targetPath, err := CreateTempDirInTempDir() - if err != nil { - os.Exit(1) - } - targetFile := filepath.Join(targetPath, "idFile") + targetFile := filepath.Join(podmanTest.TempDir, "idFile") session := podmanTest.Podman([]string{"build", "--pull-never", "build/basicalpine", "--iidfile", targetFile}) session.WaitWithDefaultTimeout() @@ -431,8 +421,7 @@ COPY /* /dir`, ALPINE) podmanTest.AddImageToRWStore(ALPINE) // Write target and fake files - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) + targetPath := podmanTest.TempDir targetSubPath := filepath.Join(targetPath, "subdir") err = os.Mkdir(targetSubPath, 0755) Expect(err).ToNot(HaveOccurred()) @@ -450,7 +439,6 @@ RUN find /test`, ALPINE) defer func() { Expect(os.Chdir(cwd)).To(Succeed()) - Expect(os.RemoveAll(targetPath)).To(Succeed()) }() // make cwd as context root path @@ -504,8 +492,7 @@ RUN find /test`, ALPINE) podmanTest.AddImageToRWStore(ALPINE) // Write target and fake files - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) + targetPath := podmanTest.TempDir targetSubPath := filepath.Join(targetPath, "subdir") err = os.Mkdir(targetSubPath, 0755) Expect(err).ToNot(HaveOccurred()) @@ -518,7 +505,6 @@ RUN find /test`, ALPINE) defer func() { Expect(os.Chdir(cwd)).To(Succeed()) - Expect(os.RemoveAll(targetPath)).To(Succeed()) }() // make cwd as context root path @@ -544,7 +530,8 @@ RUN find /test`, ALPINE) podmanTest.AddImageToRWStore(ALPINE) // Write target and fake files - targetPath, err := CreateTempDirInTempDir() + targetPath := filepath.Join(podmanTest.TempDir, "build") + err = os.Mkdir(targetPath, 0755) Expect(err).ToNot(HaveOccurred()) containerfile := fmt.Sprintf(`FROM %s @@ -616,9 +603,9 @@ subdir**` containerfile := filepath.Join(tempdir, "Containerfile") Expect(os.WriteFile(containerfile, contents.Bytes(), 0644)).ToNot(HaveOccurred()) - contextDir, err := CreateTempDirInTempDir() + contextDir := filepath.Join(podmanTest.TempDir, "context") + err = os.MkdirAll(contextDir, os.ModePerm) Expect(err).ToNot(HaveOccurred()) - defer os.RemoveAll(contextDir) Expect(os.WriteFile(filepath.Join(contextDir, "expected"), contents.Bytes(), 0644)). ToNot(HaveOccurred()) @@ -665,8 +652,7 @@ subdir**` podmanTest.AddImageToRWStore(ALPINE) // Write target and fake files - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) + targetPath := podmanTest.TempDir targetSubPath := filepath.Join(targetPath, "subdir") err = os.Mkdir(targetSubPath, 0755) Expect(err).ToNot(HaveOccurred()) @@ -691,7 +677,6 @@ RUN [[ -L /test/dummy-symlink ]] && echo SYMLNKOK || echo SYMLNKERR`, ALPINE) defer func() { Expect(os.Chdir(cwd)).To(Succeed()) - Expect(os.RemoveAll(targetPath)).To(Succeed()) }() // make cwd as context root path @@ -707,8 +692,7 @@ RUN [[ -L /test/dummy-symlink ]] && echo SYMLNKOK || echo SYMLNKERR`, ALPINE) }) It("podman build --from, --add-host, --cap-drop, --cap-add", func() { - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) + targetPath := podmanTest.TempDir containerFile := filepath.Join(targetPath, "Containerfile") content := `FROM scratch @@ -738,9 +722,7 @@ RUN grep CapEff /proc/self/status` }) It("podman build --isolation && --arch", func() { - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) - + targetPath := podmanTest.TempDir containerFile := filepath.Join(targetPath, "Containerfile") Expect(os.WriteFile(containerFile, []byte(fmt.Sprintf("FROM %s", ALPINE)), 0755)).To(Succeed()) @@ -798,8 +780,7 @@ RUN echo hello`, ALPINE) }) It("podman build --log-rusage", func() { - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) + targetPath := podmanTest.TempDir containerFile := filepath.Join(targetPath, "Containerfile") content := `FROM scratch` diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go index ad753eed37..8952a09061 100644 --- a/test/e2e/checkpoint_test.go +++ b/test/e2e/checkpoint_test.go @@ -1327,6 +1327,7 @@ var _ = Describe("Podman checkpoint", func() { Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) cid := session.OutputToString() fileName := filepath.Join(podmanTest.TempDir, "/checkpoint-"+cid+".tar.gz") + defer os.Remove(fileName) result := podmanTest.Podman([]string{ "container", @@ -1343,8 +1344,9 @@ var _ = Describe("Podman checkpoint", func() { Expect(podmanTest.NumberOfContainers()).To(Equal(0)) // Extract checkpoint archive - destinationDirectory, err := CreateTempDirInTempDir() - Expect(err).ShouldNot(HaveOccurred()) + destinationDirectory := filepath.Join(podmanTest.TempDir, "dest") + err = os.MkdirAll(destinationDirectory, os.ModePerm) + Expect(err).ToNot(HaveOccurred()) tarsession := SystemExec( "tar", @@ -1359,11 +1361,6 @@ var _ = Describe("Podman checkpoint", func() { _, err = os.Stat(filepath.Join(destinationDirectory, stats.StatsDump)) Expect(err).ShouldNot(HaveOccurred()) - - Expect(os.RemoveAll(destinationDirectory)).To(Succeed()) - - // Remove exported checkpoint - os.Remove(fileName) }) It("podman checkpoint and restore containers with --print-stats", func() { diff --git a/test/e2e/commit_test.go b/test/e2e/commit_test.go index 0ec2595e41..9034b92993 100644 --- a/test/e2e/commit_test.go +++ b/test/e2e/commit_test.go @@ -270,12 +270,8 @@ var _ = Describe("Podman commit", func() { cwd, err := os.Getwd() Expect(err).ToNot(HaveOccurred()) Expect(os.Chdir(os.TempDir())).To(Succeed()) - targetPath, err := CreateTempDirInTempDir() - if err != nil { - os.Exit(1) - } + targetPath := podmanTest.TempDir targetFile := filepath.Join(targetPath, "idFile") - defer Expect(os.RemoveAll(targetFile)).To(BeNil()) defer Expect(os.Chdir(cwd)).To(BeNil()) _, ec, _ := podmanTest.RunLsContainer("test1") diff --git a/test/e2e/containers_conf_test.go b/test/e2e/containers_conf_test.go index b45e78d0a9..74948b6637 100644 --- a/test/e2e/containers_conf_test.go +++ b/test/e2e/containers_conf_test.go @@ -110,8 +110,6 @@ var _ = Describe("Verify podman containers.conf usage", func() { // FIXME: Needs crun-1.8.2-2 to allow this with --cgroup-manager=cgroupfs, once this is available remove the skip below. SkipIfRootless("--cgroup-manager=cgoupfs and --cgroup-conf not supported in rootless mode with crun") conffile := filepath.Join(podmanTest.TempDir, "container.conf") - tempdir, err = CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) err := os.WriteFile(conffile, []byte("[containers]\ncgroup_conf = [\"pids.max=1234\",]\n"), 0755) Expect(err).ToNot(HaveOccurred()) @@ -281,17 +279,18 @@ var _ = Describe("Verify podman containers.conf usage", func() { It("add volumes", func() { conffile := filepath.Join(podmanTest.TempDir, "container.conf") - tempdir, err = CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) - err := os.WriteFile(conffile, []byte(fmt.Sprintf("[containers]\nvolumes=[\"%s:%s:Z\",]\n", tempdir, tempdir)), 0755) + volume := filepath.Join(podmanTest.TempDir, "vol") + err = os.MkdirAll(volume, os.ModePerm) + Expect(err).ToNot(HaveOccurred()) + err := os.WriteFile(conffile, []byte(fmt.Sprintf("[containers]\nvolumes=[\"%s:%s:Z\",]\n", volume, volume)), 0755) Expect(err).ToNot(HaveOccurred()) os.Setenv("CONTAINERS_CONF", conffile) if IsRemote() { podmanTest.RestartRemoteService() } - result := podmanTest.Podman([]string{"run", ALPINE, "ls", tempdir}) + result := podmanTest.Podman([]string{"run", ALPINE, "ls", volume}) result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) }) diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go index 082268a4b2..ee7339c7e9 100644 --- a/test/e2e/generate_kube_test.go +++ b/test/e2e/generate_kube_test.go @@ -1072,9 +1072,7 @@ var _ = Describe("Podman kube generate", func() { containerfile := `FROM quay.io/libpod/alpine:latest ENTRYPOINT ["sleep"]` - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) - containerfilePath := filepath.Join(targetPath, "Containerfile") + containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile") err = os.WriteFile(containerfilePath, []byte(containerfile), 0644) Expect(err).ToNot(HaveOccurred()) @@ -1126,9 +1124,7 @@ ENTRYPOINT ["sleep"]` containerfile := `FROM quay.io/libpod/alpine:latest USER 1000` - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) - containerfilePath := filepath.Join(targetPath, "Containerfile") + containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile") err = os.WriteFile(containerfilePath, []byte(containerfile), 0644) Expect(err).ToNot(HaveOccurred()) @@ -1197,9 +1193,7 @@ USER 1000` RUN adduser -u 10001 -S test1 USER test1` - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) - containerfilePath := filepath.Join(targetPath, "Containerfile") + containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile") err = os.WriteFile(containerfilePath, []byte(containerfile), 0644) Expect(err).ToNot(HaveOccurred()) diff --git a/test/e2e/healthcheck_run_test.go b/test/e2e/healthcheck_run_test.go index 8ea7edd6ca..4ad2ca8480 100644 --- a/test/e2e/healthcheck_run_test.go +++ b/test/e2e/healthcheck_run_test.go @@ -297,20 +297,17 @@ var _ = Describe("Podman healthcheck run", func() { podmanTest.AddImageToRWStore(ALPINE) // Write target and fake files - targetPath, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) containerfile := fmt.Sprintf(`FROM %s HEALTHCHECK CMD ls -l / 2>&1`, ALPINE) - containerfilePath := filepath.Join(targetPath, "Containerfile") + containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile") err = os.WriteFile(containerfilePath, []byte(containerfile), 0644) Expect(err).ToNot(HaveOccurred()) defer func() { Expect(os.Chdir(cwd)).To(Succeed()) - Expect(os.RemoveAll(targetPath)).To(Succeed()) }() // make cwd as context root path - Expect(os.Chdir(targetPath)).To(Succeed()) + Expect(os.Chdir(podmanTest.TempDir)).To(Succeed()) session := podmanTest.Podman([]string{"build", "--format", "docker", "-t", "test", "."}) session.WaitWithDefaultTimeout() diff --git a/test/e2e/network_test.go b/test/e2e/network_test.go index 4671fd3ccc..fa353786b9 100644 --- a/test/e2e/network_test.go +++ b/test/e2e/network_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "os" + "path/filepath" "time" "github.com/containers/common/libnetwork/types" @@ -39,9 +40,7 @@ var _ = Describe("Podman network", func() { It("podman --cni-config-dir backwards compat", func() { SkipIfRemote("--cni-config-dir only works locally") - netDir, err := CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) - defer os.RemoveAll(netDir) + netDir := filepath.Join(podmanTest.TempDir, "networks123") session := podmanTest.Podman([]string{"--cni-config-dir", netDir, "network", "ls", "--noheading"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 1138c29dd2..2a16d8b451 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -2933,8 +2933,6 @@ spec: Expect(c).Should(Exit(0)) conffile := filepath.Join(podmanTest.TempDir, "kube.yaml") - tempdir, err = CreateTempDirInTempDir() - Expect(err).ToNot(HaveOccurred()) err := os.WriteFile(conffile, []byte(testyaml), 0755) Expect(err).ToNot(HaveOccurred()) diff --git a/test/e2e/pod_create_test.go b/test/e2e/pod_create_test.go index 35534b5d9a..f6f10be787 100644 --- a/test/e2e/pod_create_test.go +++ b/test/e2e/pod_create_test.go @@ -304,11 +304,8 @@ var _ = Describe("Podman pod create", func() { cwd, err := os.Getwd() Expect(err).ToNot(HaveOccurred()) Expect(os.Chdir(os.TempDir())).To(Succeed()) - targetPath, err := CreateTempDirInTempDir() - if err != nil { - os.Exit(1) - } - targetFile := filepath.Join(targetPath, "idFile") + + targetFile := filepath.Join(podmanTest.TempDir, "idFile") defer Expect(os.RemoveAll(targetFile)).To(BeNil()) defer Expect(os.Chdir(cwd)).To(BeNil()) diff --git a/test/e2e/run_working_dir_test.go b/test/e2e/run_working_dir_test.go index 7bf2562354..128fed84b3 100644 --- a/test/e2e/run_working_dir_test.go +++ b/test/e2e/run_working_dir_test.go @@ -3,6 +3,7 @@ package integration import ( "fmt" "os" + "path/filepath" . "github.com/containers/podman/v4/test/utils" . "github.com/onsi/ginkgo" @@ -47,7 +48,8 @@ var _ = Describe("Podman run", func() { }) It("podman run a container using a --workdir under a bind mount", func() { - volume, err := CreateTempDirInTempDir() + volume := filepath.Join(podmanTest.TempDir, "vol") + err = os.MkdirAll(volume, os.ModePerm) Expect(err).ToNot(HaveOccurred()) session := podmanTest.Podman([]string{"run", "--volume", fmt.Sprintf("%s:/var_ovl/:O", volume), "--workdir", "/var_ovl/log", ALPINE, "true"})