diff options
author | baude <bbaude@redhat.com> | 2019-05-14 14:28:50 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-05-29 15:12:05 -0500 |
commit | f610a485c1bca7a78d3b2f70e2005b79668fab2f (patch) | |
tree | 1a3650add2aff9b57ea005c543a29a39ff5b4976 /test/utils | |
parent | 8422503f4311555ecb799449b371ad1600a8020f (diff) | |
download | podman-f610a485c1bca7a78d3b2f70e2005b79668fab2f.tar.gz podman-f610a485c1bca7a78d3b2f70e2005b79668fab2f.tar.bz2 podman-f610a485c1bca7a78d3b2f70e2005b79668fab2f.zip |
use imagecaches for local tests
when doing localized tests (not varlink), we can use secondary image
stores as read-only image caches. this cuts down on test time
significantly because each test does not need to restore the images from
a tarball anymore.
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'test/utils')
-rw-r--r-- | test/utils/podmantest_test.go | 2 | ||||
-rw-r--r-- | test/utils/utils.go | 24 |
2 files changed, 16 insertions, 10 deletions
diff --git a/test/utils/podmantest_test.go b/test/utils/podmantest_test.go index 28f294a94..cb31d5548 100644 --- a/test/utils/podmantest_test.go +++ b/test/utils/podmantest_test.go @@ -23,7 +23,7 @@ var _ = Describe("PodmanTest test", func() { FakeOutputs["check"] = []string{"check"} os.Setenv("HOOK_OPTION", "hook_option") env := os.Environ() - session := podmanTest.PodmanAsUserBase([]string{"check"}, 1000, 1000, "", env) + session := podmanTest.PodmanAsUserBase([]string{"check"}, 1000, 1000, "", env, true) os.Unsetenv("HOOK_OPTION") session.WaitWithDefaultTimeout() Expect(session.Command.Process).ShouldNot(BeNil()) diff --git a/test/utils/utils.go b/test/utils/utils.go index beadab549..98031385d 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -42,6 +42,8 @@ type PodmanTest struct { VarlinkSession *os.Process VarlinkEndpoint string VarlinkCommand *exec.Cmd + ImageCacheDir string + ImageCacheFS string } // PodmanSession wraps the gexec.session so we can extend it @@ -63,7 +65,7 @@ func (p *PodmanTest) MakeOptions(args []string) []string { // PodmanAsUserBase exec podman as user. uid and gid is set for credentials useage. env is used // to record the env for debugging -func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string, env []string) *PodmanSession { +func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string, env []string, nocache bool) *PodmanSession { var command *exec.Cmd podmanOptions := p.MakeOptions(args) podmanBinary := p.PodmanBinary @@ -71,6 +73,10 @@ func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string podmanBinary = p.RemotePodmanBinary env = append(env, fmt.Sprintf("PODMAN_VARLINK_ADDRESS=%s", p.VarlinkEndpoint)) } + if !nocache && !p.RemoteTest { + cacheOptions := []string{"--storage-opt", fmt.Sprintf("%s.imagestore=%s", p.ImageCacheFS, p.ImageCacheDir)} + podmanOptions = append(cacheOptions, podmanOptions...) + } if env == nil { fmt.Printf("Running: %s %s\n", podmanBinary, strings.Join(podmanOptions, " ")) @@ -99,8 +105,8 @@ func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string } // PodmanBase exec podman with default env. -func (p *PodmanTest) PodmanBase(args []string) *PodmanSession { - return p.PodmanAsUserBase(args, 0, 0, "", nil) +func (p *PodmanTest) PodmanBase(args []string, nocache bool) *PodmanSession { + return p.PodmanAsUserBase(args, 0, 0, "", nil, nocache) } // WaitForContainer waits on a started container @@ -118,7 +124,7 @@ func (p *PodmanTest) WaitForContainer() bool { // containers are currently running. func (p *PodmanTest) NumberOfContainersRunning() int { var containers []string - ps := p.PodmanBase([]string{"ps", "-q"}) + ps := p.PodmanBase([]string{"ps", "-q"}, true) ps.WaitWithDefaultTimeout() Expect(ps.ExitCode()).To(Equal(0)) for _, i := range ps.OutputToStringArray() { @@ -133,7 +139,7 @@ func (p *PodmanTest) NumberOfContainersRunning() int { // containers are currently defined. func (p *PodmanTest) NumberOfContainers() int { var containers []string - ps := p.PodmanBase([]string{"ps", "-aq"}) + ps := p.PodmanBase([]string{"ps", "-aq"}, true) ps.WaitWithDefaultTimeout() Expect(ps.ExitCode()).To(Equal(0)) for _, i := range ps.OutputToStringArray() { @@ -148,7 +154,7 @@ func (p *PodmanTest) NumberOfContainers() int { // pods are currently defined. func (p *PodmanTest) NumberOfPods() int { var pods []string - ps := p.PodmanBase([]string{"pod", "ps", "-q"}) + ps := p.PodmanBase([]string{"pod", "ps", "-q"}, true) ps.WaitWithDefaultTimeout() Expect(ps.ExitCode()).To(Equal(0)) for _, i := range ps.OutputToStringArray() { @@ -164,7 +170,7 @@ func (p *PodmanTest) NumberOfPods() int { func (p *PodmanTest) GetContainerStatus() string { var podmanArgs = []string{"ps"} podmanArgs = append(podmanArgs, "--all", "--format={{.Status}}") - session := p.PodmanBase(podmanArgs) + session := p.PodmanBase(podmanArgs, true) session.WaitWithDefaultTimeout() return session.OutputToString() } @@ -172,7 +178,7 @@ func (p *PodmanTest) GetContainerStatus() string { // WaitContainerReady waits process or service inside container start, and ready to be used. func (p *PodmanTest) WaitContainerReady(id string, expStr string, timeout int, step int) bool { startTime := time.Now() - s := p.PodmanBase([]string{"logs", id}) + s := p.PodmanBase([]string{"logs", id}, true) s.WaitWithDefaultTimeout() for { @@ -185,7 +191,7 @@ func (p *PodmanTest) WaitContainerReady(id string, expStr string, timeout int, s return true } time.Sleep(time.Duration(step) * time.Second) - s = p.PodmanBase([]string{"logs", id}) + s = p.PodmanBase([]string{"logs", id}, true) s.WaitWithDefaultTimeout() } } |