diff options
Diffstat (limited to 'test/e2e/common_test.go')
-rw-r--r-- | test/e2e/common_test.go | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 7e14f9e06..b6dd1ecd1 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -4,10 +4,12 @@ import ( "encoding/json" "fmt" "io/ioutil" + "math/rand" "os" "os/exec" "path/filepath" "sort" + "strconv" "strings" "testing" "time" @@ -109,10 +111,7 @@ var _ = SynchronizedBeforeSuite(func() []byte { } for _, image := range CACHE_IMAGES { - if err := podman.CreateArtifact(image); err != nil { - fmt.Printf("%q\n", err) - os.Exit(1) - } + podman.createArtifact(image) } // If running localized tests, the cache dir is created and populated. if the @@ -285,25 +284,26 @@ func (p *PodmanTestIntegration) RestoreAllArtifacts() error { return nil } -// CreateArtifact creates a cached image in the artifact dir -func (p *PodmanTestIntegration) CreateArtifact(image string) error { +// createArtifact creates a cached image in the artifact dir +func (p *PodmanTestIntegration) createArtifact(image string) { if os.Getenv("NO_TEST_CACHE") != "" { - return nil + return } - fmt.Printf("Caching %s...", image) 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...", image, destName) if _, err := os.Stat(destName); os.IsNotExist(err) { pull := p.PodmanNoCache([]string{"pull", image}) pull.Wait(90) + Expect(pull.ExitCode()).To(Equal(0)) save := p.PodmanNoCache([]string{"save", "-o", destName, image}) save.Wait(90) + Expect(save.ExitCode()).To(Equal(0)) fmt.Printf("\n") } else { fmt.Printf(" already exists.\n") } - return nil } // InspectImageJSON takes the session output of an inspect @@ -320,6 +320,7 @@ func (p *PodmanTestIntegration) InspectContainer(name string) []libpod.InspectCo cmd := []string{"inspect", name} session := p.Podman(cmd) session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) return session.InspectContainerToJSON() } @@ -339,6 +340,18 @@ func GetPortLock(port string) storage.Locker { return lock } +// GetRandomIPAddress returns a random IP address to avoid IP +// collisions during parallel tests +func GetRandomIPAddress() string { + // To avoid IP collisions of initialize random seed for random IP addresses + rand.Seed(time.Now().UnixNano()) + // Add GinkgoParallelNode() on top of the IP address + // in case of the same random seed + ip3 := strconv.Itoa(rand.Intn(230) + GinkgoParallelNode()) + ip4 := strconv.Itoa(rand.Intn(230) + GinkgoParallelNode()) + return "10.88." + ip3 + "." + ip4 +} + // RunTopContainer runs a simple container in the background that // runs top. If the name passed != "", it will have a name func (p *PodmanTestIntegration) RunTopContainer(name string) *PodmanSessionIntegration { @@ -399,7 +412,7 @@ func (p *PodmanTestIntegration) BuildImage(dockerfile, imageName string, layers // PodmanPID execs podman and returns its PID func (p *PodmanTestIntegration) PodmanPID(args []string) (*PodmanSessionIntegration, int) { - podmanOptions := p.MakeOptions(args) + podmanOptions := p.MakeOptions(args, false) fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " ")) command := exec.Command(p.PodmanBinary, podmanOptions...) session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) |