diff --git a/contrib/cirrus/setup_environment.sh b/contrib/cirrus/setup_environment.sh index 04442cc2a701..eb5510abee92 100755 --- a/contrib/cirrus/setup_environment.sh +++ b/contrib/cirrus/setup_environment.sh @@ -54,6 +54,10 @@ if [[ "$CI_DESIRED_STORAGE" = "composefs" ]]; then if [[ "$PRIV_NAME" == "root" ]]; then CI_DESIRED_COMPOSEFS="+composefs" + # artifacts restored from a tarball won't be stored correctly + # in composefs, so we need to disable this feature for now. + export NO_SAVE_TEST_CACHE_FILES=true + # KLUDGE ALERT! Magic options needed for testing composefs. # This option was intended for passing one arg to --storage-opt # but we're hijacking it to pass an extra option+arg. And it diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index a3c9c72df4d5..100eb27ebc0a 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "io/fs" "math/rand" "net" "net/url" @@ -401,27 +402,35 @@ func imageTarPath(image string) string { return filepath.Join(cacheDir, imageCacheName) } +func canUseArtifacts() bool { + return os.Getenv("NO_SAVE_TEST_CACHE_FILES") == "" && os.Getenv("CI_DESIRED_COMPOSEFS") == "" +} + +func (p *PodmanTestIntegration) pullImage(image string) { + for try := 0; try < 3; try++ { + pull := p.PodmanNoCache([]string{"pull", image}) + pull.Wait(440) + if pull.ExitCode() == 0 { + break + } + if try == 2 { + Expect(pull).Should(Exit(0), "Failed after many retries") + } + + GinkgoWriter.Println("Will wait and retry") + time.Sleep(time.Duration(try+1) * 5 * time.Second) + } +} + // createArtifact creates a cached image tarball in a local directory func (p *PodmanTestIntegration) createArtifact(image string) { - if os.Getenv("NO_TEST_CACHE") != "" { + if os.Getenv("NO_TEST_CACHE") != "" || !canUseArtifacts() { return } destName := imageTarPath(image) - if _, err := os.Stat(destName); os.IsNotExist(err) { + if _, err := os.Stat(destName); errors.Is(err, fs.ErrNotExist) { GinkgoWriter.Printf("Caching %s at %s...\n", image, destName) - for try := 0; try < 3; try++ { - pull := p.PodmanNoCache([]string{"pull", image}) - pull.Wait(440) - if pull.ExitCode() == 0 { - break - } - if try == 2 { - Expect(pull).Should(Exit(0), "Failed after many retries") - } - - GinkgoWriter.Println("Will wait and retry") - time.Sleep(time.Duration(try+1) * 5 * time.Second) - } + p.pullImage(image) save := p.PodmanNoCache([]string{"save", "-o", destName, image}) save.Wait(90) @@ -1024,7 +1033,12 @@ func (p *PodmanTestIntegration) RestartRemoteService() { // RestoreArtifactToCache populates the imagecache from tarballs that were cached earlier func (p *PodmanTestIntegration) RestoreArtifactToCache(image string) error { + if !canUseArtifacts() { + return nil + } + tarball := imageTarPath(image) + if _, err := os.Stat(tarball); err == nil { GinkgoWriter.Printf("Restoring %s...\n", image) p.Root = p.ImageCacheDir @@ -1037,8 +1051,12 @@ func (p *PodmanTestIntegration) RestoreArtifactToCache(image string) error { func populateCache(podman *PodmanTestIntegration) { for _, image := range CACHE_IMAGES { - err := podman.RestoreArtifactToCache(image) - Expect(err).ToNot(HaveOccurred()) + if canUseArtifacts() { + err := podman.RestoreArtifactToCache(image) + Expect(err).ToNot(HaveOccurred()) + } else { + podman.pullImage(image) + } } // logformatter uses this to recognize the first test GinkgoWriter.Printf("-----------------------------\n")