From 88a625d3193d756f05b7a4361ab1576317f5e8a0 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 26 Apr 2024 17:58:57 +0200 Subject: [PATCH 1/3] test/e2e: "persistentVolumeClaim with source" do not leak file Using /tmp means this file will be leaked and no deleted, switch to using the per test tempdir which is removed after the test. Signed-off-by: Paul Holzinger --- test/e2e/play_kube_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index e3426dbe03..ac58db8368 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -4093,7 +4093,7 @@ o: {{ .Options.o }}`}) It("persistentVolumeClaim with source", func() { fileName := "data" expectedFileContent := "Test" - tarFilePath := filepath.Join(os.TempDir(), "podmanVolumeSource.tgz") + tarFilePath := filepath.Join(podmanTest.TempDir, "podmanVolumeSource.tgz") err := createSourceTarFile(fileName, expectedFileContent, tarFilePath) Expect(err).ToNot(HaveOccurred()) From 0faded53b8a8fb65b2c049cf06e743de4e1a3482 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 26 Apr 2024 18:05:31 +0200 Subject: [PATCH 2/3] test/e2e: do not leak /tmp/private_file This should use the proper per test tempdir which works just as well for the purpose. Signed-off-by: Paul Holzinger --- test/e2e/build_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index 8042dfcb0a..4e52f38fe4 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -441,7 +441,7 @@ RUN find /test`, CITEST_IMAGE) It("podman remote build must not allow symlink for ignore files", func() { // Create a random file where symlink must be resolved // but build should not be able to access it. - privateFile := filepath.Join("/tmp", "private_file") + privateFile := filepath.Join(podmanTest.TempDir, "private_file") f, err := os.Create(privateFile) Expect(err).ToNot(HaveOccurred()) // Mark hello to be ignored in outerfile, but it should not be ignored. @@ -449,16 +449,14 @@ RUN find /test`, CITEST_IMAGE) Expect(err).ToNot(HaveOccurred()) defer f.Close() - // Create .dockerignore which is a symlink to /tmp/private_file. + // Create .dockerignore which is a symlink to /tmp/.../private_file outside of the context dir. currentDir, err := os.Getwd() Expect(err).ToNot(HaveOccurred()) ignoreFile := filepath.Join(currentDir, "build/containerignore-symlink/.dockerignore") err = os.Symlink(privateFile, ignoreFile) Expect(err).ToNot(HaveOccurred()) // Remove created .dockerignore for this test when test ends. - defer func() { - os.Remove(ignoreFile) - }() + defer os.Remove(ignoreFile) if IsRemote() { podmanTest.StopRemoteService() From 88b80c1df62b88e22737e016865bc88b042d788e Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 26 Apr 2024 18:16:27 +0200 Subject: [PATCH 3/3] test/e2e: podman unshare image mount fix tmpdir leak Because the test left the image mounted the cleanup failed to remove the tmpdir as it contained an active mount point. Thus ensure we unmount the image again to prevent this leak. Signed-off-by: Paul Holzinger --- test/e2e/mount_rootless_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/e2e/mount_rootless_test.go b/test/e2e/mount_rootless_test.go index 7b2a5badfa..7e4af2eb68 100644 --- a/test/e2e/mount_rootless_test.go +++ b/test/e2e/mount_rootless_test.go @@ -1,6 +1,8 @@ package integration import ( + "slices" + . "github.com/containers/podman/v5/test/utils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -63,5 +65,14 @@ var _ = Describe("Podman mount", func() { session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) Expect(session.OutputToString()).To(ContainSubstring(podmanTest.TempDir)) + + // We have to unmount the image again otherwise we leak the tmpdir + // as active mount points cannot be removed. + index := slices.Index(args, "mount") + Expect(index).To(BeNumerically(">", 0), "index should be found") + args[index] = "unmount" + session = podmanTest.Podman(args) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) }) })