summaryrefslogtreecommitdiff
path: root/test/e2e/common_test.go
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2021-12-01 12:47:30 -0700
committerEd Santiago <santiago@redhat.com>2021-12-01 14:06:22 -0700
commit3ac1b9bc0f1d45289d0f014d667f7b45302992b6 (patch)
tree6d0f2c7821eb22ae417f6968392ce571e0d6c987 /test/e2e/common_test.go
parent5ac66e2aab68de1d40a01c6f9d00956a45ccaa4d (diff)
downloadpodman-3ac1b9bc0f1d45289d0f014d667f7b45302992b6.tar.gz
podman-3ac1b9bc0f1d45289d0f014d667f7b45302992b6.tar.bz2
podman-3ac1b9bc0f1d45289d0f014d667f7b45302992b6.zip
Image caches: allow overriding cache dir
Images were being cached in /tmp, with no option to override. Now $PODMAN_TEST_IMAGE_CACHE_DIR can be used to point to a user-preferred location. If unset, try $TMPDIR before settling on /tmp. Also: refactor the logic for determining the tarball name. Also: include registry name in tarball name. Also: clean up unused/unnecessary code Also: do not echo "Restoring..." if we're not actually restoring. Signed-off-by: Ed Santiago <santiago@redhat.com>
Diffstat (limited to 'test/e2e/common_test.go')
-rw-r--r--test/e2e/common_test.go37
1 files changed, 26 insertions, 11 deletions
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go
index 2930fac84..4137dfb0f 100644
--- a/test/e2e/common_test.go
+++ b/test/e2e/common_test.go
@@ -308,15 +308,29 @@ func (p PodmanTestIntegration) AddImageToRWStore(image string) {
}
}
-// createArtifact creates a cached image in the artifact dir
+func imageTarPath(image string) string {
+ cacheDir := os.Getenv("PODMAN_TEST_IMAGE_CACHE_DIR")
+ if cacheDir == "" {
+ cacheDir = os.Getenv("TMPDIR")
+ if cacheDir == "" {
+ cacheDir = "/tmp"
+ }
+ }
+
+ // e.g., registry.com/fubar:latest -> registry.com-fubar-latest.tar
+ imageCacheName := strings.Replace(strings.Replace(image, ":", "-", -1), "/", "-", -1) + ".tar"
+
+ return filepath.Join(cacheDir, imageCacheName)
+}
+
+// createArtifact creates a cached image tarball in a local directory
func (p *PodmanTestIntegration) createArtifact(image string) {
if os.Getenv("NO_TEST_CACHE") != "" {
return
}
- dest := strings.Split(image, "/")
- destName := fmt.Sprintf("/tmp/%s.tar", strings.Replace(strings.Join(strings.Split(dest[len(dest)-1], "/"), ""), ":", "-", -1))
- fmt.Printf("Caching %s at %s...\n", image, destName)
+ destName := imageTarPath(image)
if _, err := os.Stat(destName); os.IsNotExist(err) {
+ fmt.Printf("Caching %s at %s...\n", image, destName)
pull := p.PodmanNoCache([]string{"pull", image})
pull.Wait(440)
Expect(pull).Should(Exit(0))
@@ -326,7 +340,7 @@ func (p *PodmanTestIntegration) createArtifact(image string) {
Expect(save).Should(Exit(0))
fmt.Printf("\n")
} else {
- fmt.Printf(" already exists.\n")
+ fmt.Printf("[image already cached: %s]\n", destName)
}
}
@@ -738,12 +752,13 @@ func (p *PodmanTestIntegration) RestartRemoteService() {
// RestoreArtifactToCache populates the imagecache from tarballs that were cached earlier
func (p *PodmanTestIntegration) RestoreArtifactToCache(image string) error {
- fmt.Printf("Restoring %s...\n", image)
- dest := strings.Split(image, "/")
- destName := fmt.Sprintf("/tmp/%s.tar", strings.Replace(strings.Join(strings.Split(dest[len(dest)-1], "/"), ""), ":", "-", -1))
- p.Root = p.ImageCacheDir
- restore := p.PodmanNoEvents([]string{"load", "-q", "-i", destName})
- restore.WaitWithDefaultTimeout()
+ tarball := imageTarPath(image)
+ if _, err := os.Stat(tarball); err == nil {
+ fmt.Printf("Restoring %s...\n", image)
+ p.Root = p.ImageCacheDir
+ restore := p.PodmanNoEvents([]string{"load", "-q", "-i", tarball})
+ restore.WaitWithDefaultTimeout()
+ }
return nil
}