Skip to content

Commit

Permalink
Merge pull request #17245 from sstosh/e2e-rootless-rm
Browse files Browse the repository at this point in the history
e2e: Remove the cache with "podman unshare rm" when a rootless user
  • Loading branch information
openshift-merge-robot authored Jan 27, 2023
2 parents 356f7b6 + 21b82bb commit a3a826a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ var _ = SynchronizedAfterSuite(func() {},
}
// for localized tests, this removes the image cache dir and for remote tests
// this is a no-op
removeCache()
podmanTest.removeCache(ImageCacheDir)

// LockTmpDir can already be removed
os.RemoveAll(LockTmpDir)
Expand Down Expand Up @@ -560,9 +560,7 @@ func (p *PodmanTestIntegration) Cleanup() {

p.StopRemoteService()
// Nuke tempdir
if err := os.RemoveAll(p.TempDir); err != nil {
fmt.Printf("%q\n", err)
}
p.removeCache(p.TempDir)

// Clean up the registries configuration file ENV variable set in Create
resetRegistriesConfigEnv()
Expand Down Expand Up @@ -849,10 +847,20 @@ func populateCache(podman *PodmanTestIntegration) {
fmt.Printf("-----------------------------\n")
}

func removeCache() {
func (p *PodmanTestIntegration) removeCache(path string) {
// Remove cache dirs
if err := os.RemoveAll(ImageCacheDir); err != nil {
fmt.Printf("%q\n", err)
if isRootless() {
// If rootless, os.RemoveAll() is failed due to permission denied
cmd := exec.Command(p.PodmanBinary, "unshare", "rm", "-rf", path)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
} else {
if err := os.RemoveAll(path); err != nil {
fmt.Printf("%q\n", err)
}
}
}

Expand Down

0 comments on commit a3a826a

Please sign in to comment.