test/e2e: remove unnecessary code in SynchronizedAfterSuite

This code does not do anything useful beside removing the cache dir.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2023-07-04 16:06:28 +02:00
parent ff77900387
commit bc22aefce6

View File

@ -181,7 +181,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
} }
// remove temporary podman files, images are now cached in ImageCacheDir // remove temporary podman files, images are now cached in ImageCacheDir
podman.removeCache(podman.TempDir) rmAll(podman.PodmanBinary, podman.TempDir)
return []byte(path) return []byte(path)
}, func(data []byte) { }, func(data []byte) {
@ -230,30 +230,21 @@ var _ = SynchronizedAfterSuite(func() {
GinkgoWriter.Printf("%s\t\t%f\n", result.name, result.length) GinkgoWriter.Printf("%s\t\t%f\n", result.name, result.length)
} }
// previous runroot cwd, _ := os.Getwd()
tempdir, err := CreateTempDirInTempDir() rmAll(getPodmanBinary(cwd), ImageCacheDir)
if err != nil {
os.Exit(1)
}
podmanTest := PodmanTestCreate(tempdir)
defer os.RemoveAll(tempdir)
if err := os.RemoveAll(podmanTest.Root); err != nil {
GinkgoWriter.Printf("%q\n", err)
}
// If running remote, we need to stop the associated podman system service
if podmanTest.RemoteTest {
podmanTest.StopRemoteService()
}
// for localized tests, this removes the image cache dir and for remote tests
// this is a no-op
podmanTest.removeCache(podmanTest.ImageCacheDir)
// LockTmpDir can already be removed // LockTmpDir can already be removed
os.RemoveAll(LockTmpDir) os.RemoveAll(LockTmpDir)
}) })
func getPodmanBinary(cwd string) string {
podmanBinary := filepath.Join(cwd, "../../bin/podman")
if os.Getenv("PODMAN_BINARY") != "" {
podmanBinary = os.Getenv("PODMAN_BINARY")
}
return podmanBinary
}
// PodmanTestCreate creates a PodmanTestIntegration instance for the tests // PodmanTestCreate creates a PodmanTestIntegration instance for the tests
func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
var podmanRemoteBinary string var podmanRemoteBinary string
@ -262,10 +253,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
cwd, _ := os.Getwd() cwd, _ := os.Getwd()
root := filepath.Join(tempDir, "root") root := filepath.Join(tempDir, "root")
podmanBinary := filepath.Join(cwd, "../../bin/podman") podmanBinary := getPodmanBinary(cwd)
if os.Getenv("PODMAN_BINARY") != "" {
podmanBinary = os.Getenv("PODMAN_BINARY")
}
podmanRemoteBinary = filepath.Join(cwd, "../../bin/podman-remote") podmanRemoteBinary = filepath.Join(cwd, "../../bin/podman-remote")
if os.Getenv("PODMAN_REMOTE_BINARY") != "" { if os.Getenv("PODMAN_REMOTE_BINARY") != "" {
@ -654,7 +642,7 @@ func (p *PodmanTestIntegration) Cleanup() {
p.StopRemoteService() p.StopRemoteService()
// Nuke tempdir // Nuke tempdir
p.removeCache(p.TempDir) rmAll(p.PodmanBinary, p.TempDir)
// Clean up the registries configuration file ENV variable set in Create // Clean up the registries configuration file ENV variable set in Create
resetRegistriesConfigEnv() resetRegistriesConfigEnv()
@ -990,11 +978,13 @@ func populateCache(podman *PodmanTestIntegration) {
GinkgoWriter.Printf("-----------------------------\n") GinkgoWriter.Printf("-----------------------------\n")
} }
func (p *PodmanTestIntegration) removeCache(path string) { // rmAll removes the direcory and its content,, when running rootless we use
// podman unshare to prevent any subuid/gid problems
func rmAll(podmanBin string, path string) {
// Remove cache dirs // Remove cache dirs
if isRootless() { if isRootless() {
// If rootless, os.RemoveAll() is failed due to permission denied // If rootless, os.RemoveAll() is failed due to permission denied
cmd := exec.Command(p.PodmanBinary, "unshare", "rm", "-rf", path) cmd := exec.Command(podmanBin, "unshare", "rm", "-rf", path)
cmd.Stdout = GinkgoWriter cmd.Stdout = GinkgoWriter
cmd.Stderr = GinkgoWriter cmd.Stderr = GinkgoWriter
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {