Skip to content

Commit

Permalink
test: disable artifacts cache with composefs
Browse files Browse the repository at this point in the history
layers restored from a tarball won't be converted to composefs (for
now at least), so disable the cache when using composefs.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Jul 15, 2024
1 parent 42fa78b commit 11d155c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
4 changes: 4 additions & 0 deletions contrib/cirrus/setup_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 35 additions & 17 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"math/rand"
"net"
"net/url"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 11d155c

Please sign in to comment.