From 5ac66e2aab68de1d40a01c6f9d00956a45ccaa4d Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 1 Dec 2021 11:44:02 -0700 Subject: Rename CrioRoot as just Root ...and remove other uses of "crio". They're confusing and misleading. (I'm sure it made sense at one time) Signed-off-by: Ed Santiago --- test/e2e/common_test.go | 16 ++++++++-------- test/e2e/libpod_suite_remote_test.go | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 63cb4f091..2930fac84 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -46,7 +46,7 @@ var ( type PodmanTestIntegration struct { PodmanTest ConmonBinary string - CrioRoot string + Root string CNIConfigDir string OCIRuntime string RunRoot string @@ -130,7 +130,7 @@ var _ = SynchronizedBeforeSuite(func() []byte { fmt.Printf("%q\n", err) os.Exit(1) } - podman.CrioRoot = ImageCacheDir + podman.Root = ImageCacheDir // If running localized tests, the cache dir is created and populated. if the // tests are remote, this is a no-op populateCache(podman) @@ -181,14 +181,14 @@ var _ = SynchronizedAfterSuite(func() {}, fmt.Printf("%s\t\t%f\n", result.name, result.length) } - // previous crio-run + // previous runroot tempdir, err := CreateTempDirInTempDir() if err != nil { os.Exit(1) } podmanTest := PodmanTestCreate(tempdir) - if err := os.RemoveAll(podmanTest.CrioRoot); err != nil { + if err := os.RemoveAll(podmanTest.Root); err != nil { fmt.Printf("%q\n", err) } @@ -272,11 +272,11 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { ImageCacheDir: ImageCacheDir, }, ConmonBinary: conmonBinary, - CrioRoot: filepath.Join(tempDir, "crio"), + Root: filepath.Join(tempDir, "root"), TmpDir: tempDir, CNIConfigDir: CNIConfigDir, OCIRuntime: ociRuntime, - RunRoot: filepath.Join(tempDir, "crio-run"), + RunRoot: filepath.Join(tempDir, "runroot"), StorageOptions: storageOptions, SignaturePolicyPath: filepath.Join(INTEGRATION_ROOT, "test/policy.json"), CgroupManager: cgroupManager, @@ -741,7 +741,7 @@ 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.CrioRoot = p.ImageCacheDir + p.Root = p.ImageCacheDir restore := p.PodmanNoEvents([]string{"load", "-q", "-i", destName}) restore.WaitWithDefaultTimeout() return nil @@ -795,7 +795,7 @@ func (p *PodmanTestIntegration) makeOptions(args []string, noEvents, noCache boo } podmanOptions := strings.Split(fmt.Sprintf("%s--root %s --runroot %s --runtime %s --conmon %s --cni-config-dir %s --cgroup-manager %s --tmpdir %s --events-backend %s", - debug, p.CrioRoot, p.RunRoot, p.OCIRuntime, p.ConmonBinary, p.CNIConfigDir, p.CgroupManager, p.TmpDir, eventsType), " ") + debug, p.Root, p.RunRoot, p.OCIRuntime, p.ConmonBinary, p.CNIConfigDir, p.CgroupManager, p.TmpDir, eventsType), " ") if os.Getenv("HOOK_OPTION") != "" { podmanOptions = append(podmanOptions, os.Getenv("HOOK_OPTION")) } diff --git a/test/e2e/libpod_suite_remote_test.go b/test/e2e/libpod_suite_remote_test.go index 2ecbd0eab..58ffe8c75 100644 --- a/test/e2e/libpod_suite_remote_test.go +++ b/test/e2e/libpod_suite_remote_test.go @@ -148,7 +148,7 @@ func (p *PodmanTestIntegration) StopRemoteService() { //MakeOptions assembles all the podman main options func getRemoteOptions(p *PodmanTestIntegration, args []string) []string { podmanOptions := strings.Split(fmt.Sprintf("--root %s --runroot %s --runtime %s --conmon %s --cni-config-dir %s --cgroup-manager %s", - p.CrioRoot, p.RunRoot, p.OCIRuntime, p.ConmonBinary, p.CNIConfigDir, p.CgroupManager), " ") + p.Root, p.RunRoot, p.OCIRuntime, p.ConmonBinary, p.CNIConfigDir, p.CgroupManager), " ") if os.Getenv("HOOK_OPTION") != "" { podmanOptions = append(podmanOptions, os.Getenv("HOOK_OPTION")) } -- cgit v1.2.3-54-g00ecf From 3ac1b9bc0f1d45289d0f014d667f7b45302992b6 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 1 Dec 2021 12:47:30 -0700 Subject: 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 --- test/e2e/common_test.go | 37 +++++++++++++++++++++++++----------- test/e2e/libpod_suite_remote_test.go | 19 +++++++++--------- test/e2e/libpod_suite_test.go | 12 ++++++------ 3 files changed, 42 insertions(+), 26 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 } diff --git a/test/e2e/libpod_suite_remote_test.go b/test/e2e/libpod_suite_remote_test.go index 58ffe8c75..d60383029 100644 --- a/test/e2e/libpod_suite_remote_test.go +++ b/test/e2e/libpod_suite_remote_test.go @@ -164,15 +164,16 @@ func (p *PodmanTestIntegration) SeedImages() error { // RestoreArtifact puts the cached image into our test store func (p *PodmanTestIntegration) RestoreArtifact(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)) - args := []string{"load", "-q", "-i", destName} - podmanOptions := getRemoteOptions(p, args) - command := exec.Command(p.PodmanBinary, podmanOptions...) - fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " ")) - command.Start() - command.Wait() + tarball := imageTarPath(image) + if _, err := os.Stat(tarball); err == nil { + fmt.Printf("Restoring %s...\n", image) + args := []string{"load", "-q", "-i", tarball} + podmanOptions := getRemoteOptions(p, args) + command := exec.Command(p.PodmanBinary, podmanOptions...) + fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " ")) + command.Start() + command.Wait() + } return nil } diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go index 001a869b1..4147ba2c3 100644 --- a/test/e2e/libpod_suite_test.go +++ b/test/e2e/libpod_suite_test.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "os" "path/filepath" - "strings" "github.com/containers/podman/v3/pkg/rootless" ) @@ -59,11 +58,12 @@ func PodmanTestCreate(tempDir string) *PodmanTestIntegration { // RestoreArtifact puts the cached image into our test store func (p *PodmanTestIntegration) RestoreArtifact(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)) - restore := p.PodmanNoEvents([]string{"load", "-q", "-i", destName}) - restore.Wait(90) + tarball := imageTarPath(image) + if _, err := os.Stat(tarball); err == nil { + fmt.Printf("Restoring %s...\n", image) + restore := p.PodmanNoEvents([]string{"load", "-q", "-i", tarball}) + restore.Wait(90) + } return nil } -- cgit v1.2.3-54-g00ecf From 65109494bca511fbcfd36c8d5b2f70e33c210409 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 1 Dec 2021 12:56:07 -0700 Subject: remove ARTIFACT_DIR and ArtifactPath ...they're not actually used for anything Signed-off-by: Ed Santiago --- test/e2e/common_test.go | 10 ---------- test/utils/utils.go | 1 - 2 files changed, 11 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 4137dfb0f..a411a860b 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -36,7 +36,6 @@ var ( PODMAN_BINARY string //nolint:golint,stylecheck INTEGRATION_ROOT string //nolint:golint,stylecheck CGROUP_MANAGER = "systemd" //nolint:golint,stylecheck - ARTIFACT_DIR = "/tmp/.artifacts" //nolint:golint,stylecheck RESTORE_IMAGES = []string{ALPINE, BB, nginx} //nolint:golint,stylecheck defaultWaitTimeout = 90 CGROUPSV2, _ = cgroups.IsCgroup2UnifiedMode() //nolint:golint,stylecheck @@ -111,13 +110,6 @@ var _ = SynchronizedBeforeSuite(func() []byte { cwd, _ := os.Getwd() INTEGRATION_ROOT = filepath.Join(cwd, "../../") podman := PodmanTestSetup("/tmp") - podman.ArtifactPath = ARTIFACT_DIR - if _, err := os.Stat(ARTIFACT_DIR); os.IsNotExist(err) { - if err = os.Mkdir(ARTIFACT_DIR, 0777); err != nil { - fmt.Printf("%q\n", err) - os.Exit(1) - } - } // Pull cirros but don't put it into the cache pullImages := []string{cirros, fedoraToolbox, volumeTest} @@ -170,7 +162,6 @@ var _ = SynchronizedBeforeSuite(func() []byte { func (p *PodmanTestIntegration) Setup() { cwd, _ := os.Getwd() INTEGRATION_ROOT = filepath.Join(cwd, "../../") - p.ArtifactPath = ARTIFACT_DIR } var _ = SynchronizedAfterSuite(func() {}, @@ -265,7 +256,6 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { PodmanTest: PodmanTest{ PodmanBinary: podmanBinary, RemotePodmanBinary: podmanRemoteBinary, - ArtifactPath: ARTIFACT_DIR, TempDir: tempDir, RemoteTest: remote, ImageCacheFS: storageFs, diff --git a/test/utils/utils.go b/test/utils/utils.go index 944c1ac3c..f41024072 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -36,7 +36,6 @@ type PodmanTestCommon interface { type PodmanTest struct { PodmanMakeOptions func(args []string, noEvents, noCache bool) []string PodmanBinary string - ArtifactPath string TempDir string RemoteTest bool RemotePodmanBinary string -- cgit v1.2.3-54-g00ecf