summaryrefslogtreecommitdiff
path: root/test/e2e/common_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'test/e2e/common_test.go')
-rw-r--r--test/e2e/common_test.go162
1 files changed, 98 insertions, 64 deletions
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go
index 3c7675b35..7e14f9e06 100644
--- a/test/e2e/common_test.go
+++ b/test/e2e/common_test.go
@@ -10,6 +10,7 @@ import (
"sort"
"strings"
"testing"
+ "time"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/inspect"
@@ -21,6 +22,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
+ "github.com/pkg/errors"
)
var (
@@ -100,12 +102,23 @@ var _ = SynchronizedBeforeSuite(func() []byte {
}
}
+ // make cache dir
+ if err := os.MkdirAll(ImageCacheDir, 0777); err != nil {
+ fmt.Printf("%q\n", err)
+ os.Exit(1)
+ }
+
for _, image := range CACHE_IMAGES {
if err := podman.CreateArtifact(image); err != nil {
fmt.Printf("%q\n", err)
os.Exit(1)
}
}
+
+ // If running localized tests, the cache dir is created and populated. if the
+ // tests are remote, this is a no-op
+ populateCache(podman)
+
host := GetHostDistributionInfo()
if host.Distribution == "rhel" && strings.HasPrefix(host.Version, "7") {
f, err := os.OpenFile("/proc/sys/user/max_user_namespaces", os.O_WRONLY, 0644)
@@ -136,53 +149,29 @@ func (p *PodmanTestIntegration) Setup() {
p.ArtifactPath = ARTIFACT_DIR
}
-// var _ = BeforeSuite(func() {
-// cwd, _ := os.Getwd()
-// INTEGRATION_ROOT = filepath.Join(cwd, "../../")
-// podman := PodmanTestCreate("/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)
-// }
-// }
-// })
-// for _, image := range CACHE_IMAGES {
-// if err := podman.CreateArtifact(image); err != nil {
-// fmt.Printf("%q\n", err)
-// os.Exit(1)
-// }
-// }
-// host := GetHostDistributionInfo()
-// if host.Distribution == "rhel" && strings.HasPrefix(host.Version, "7") {
-// f, err := os.OpenFile("/proc/sys/user/max_user_namespaces", os.O_WRONLY, 0644)
-// if err != nil {
-// fmt.Println("Unable to enable userspace on RHEL 7")
-// os.Exit(1)
-// }
-// _, err = f.WriteString("15000")
-// if err != nil {
-// fmt.Println("Unable to enable userspace on RHEL 7")
-// os.Exit(1)
-// }
-// f.Close()
-// }
-// path, err := ioutil.TempDir("", "libpodlock")
-// if err != nil {
-// fmt.Println(err)
-// os.Exit(1)
-// }
-// LockTmpDir = path
-// })
-
-var _ = AfterSuite(func() {
- sort.Sort(testResultsSortedLength{testResults})
- fmt.Println("integration timing results")
- for _, result := range testResults {
- fmt.Printf("%s\t\t%f\n", result.name, result.length)
- }
-})
+var _ = SynchronizedAfterSuite(func() {},
+ func() {
+ sort.Sort(testResultsSortedLength{testResults})
+ fmt.Println("integration timing results")
+ for _, result := range testResults {
+ fmt.Printf("%s\t\t%f\n", result.name, result.length)
+ }
+
+ // previous crio-run
+ tempdir, err := CreateTempDirInTempDir()
+ if err != nil {
+ os.Exit(1)
+ }
+ podmanTest := PodmanTestCreate(tempdir)
+
+ if err := os.RemoveAll(podmanTest.CrioRoot); err != nil {
+ fmt.Printf("%q\n", err)
+ }
+
+ // for localized tests, this removes the image cache dir and for remote tests
+ // this is a no-op
+ removeCache()
+ })
// PodmanTestCreate creates a PodmanTestIntegration instance for the tests
func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
@@ -205,7 +194,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
}
}
conmonBinary := filepath.Join("/usr/libexec/podman/conmon")
- altConmonBinary := "/usr/libexec/crio/conmon"
+ altConmonBinary := "/usr/bin/conmon"
if _, err := os.Stat(conmonBinary); os.IsNotExist(err) {
conmonBinary = altConmonBinary
}
@@ -225,11 +214,6 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
cgroupManager = os.Getenv("CGROUP_MANAGER")
}
- // Ubuntu doesn't use systemd cgroups
- if host.Distribution == "ubuntu" {
- cgroupManager = "cgroupfs"
- }
-
ociRuntime := os.Getenv("OCI_RUNTIME")
if ociRuntime == "" {
var err error
@@ -244,12 +228,18 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
os.Setenv("DISABLE_HC_SYSTEMD", "true")
CNIConfigDir := "/etc/cni/net.d"
+ storageFs := STORAGE_FS
+ if rootless.IsRootless() {
+ storageFs = ROOTLESS_STORAGE_FS
+ }
p := &PodmanTestIntegration{
PodmanTest: PodmanTest{
- PodmanBinary: podmanBinary,
- ArtifactPath: ARTIFACT_DIR,
- TempDir: tempDir,
- RemoteTest: remote,
+ PodmanBinary: podmanBinary,
+ ArtifactPath: ARTIFACT_DIR,
+ TempDir: tempDir,
+ RemoteTest: remote,
+ ImageCacheFS: storageFs,
+ ImageCacheDir: ImageCacheDir,
},
ConmonBinary: conmonBinary,
CrioRoot: filepath.Join(tempDir, "crio"),
@@ -304,10 +294,10 @@ func (p *PodmanTestIntegration) CreateArtifact(image string) error {
dest := strings.Split(image, "/")
destName := fmt.Sprintf("/tmp/%s.tar", strings.Replace(strings.Join(strings.Split(dest[len(dest)-1], "/"), ""), ":", "-", -1))
if _, err := os.Stat(destName); os.IsNotExist(err) {
- pull := p.Podman([]string{"pull", image})
+ pull := p.PodmanNoCache([]string{"pull", image})
pull.Wait(90)
- save := p.Podman([]string{"save", "-o", destName, image})
+ save := p.PodmanNoCache([]string{"save", "-o", destName, image})
save.Wait(90)
fmt.Printf("\n")
} else {
@@ -326,7 +316,7 @@ func (s *PodmanSessionIntegration) InspectImageJSON() []inspect.ImageData {
}
// InspectContainer returns a container's inspect data in JSON format
-func (p *PodmanTestIntegration) InspectContainer(name string) []inspect.ContainerData {
+func (p *PodmanTestIntegration) InspectContainer(name string) []libpod.InspectContainerData {
cmd := []string{"inspect", name}
session := p.Podman(cmd)
session.WaitWithDefaultTimeout()
@@ -373,6 +363,18 @@ func (p *PodmanTestIntegration) RunLsContainer(name string) (*PodmanSessionInteg
return session, session.ExitCode(), session.OutputToString()
}
+// RunNginxWithHealthCheck runs the alpine nginx container with an optional name and adds a healthcheck into it
+func (p *PodmanTestIntegration) RunNginxWithHealthCheck(name string) (*PodmanSessionIntegration, string) {
+ var podmanArgs = []string{"run"}
+ if name != "" {
+ podmanArgs = append(podmanArgs, "--name", name)
+ }
+ podmanArgs = append(podmanArgs, "-dt", "-P", "--health-cmd", "curl http://localhost/", nginx)
+ session := p.Podman(podmanArgs)
+ session.WaitWithDefaultTimeout()
+ return session, session.OutputToString()
+}
+
func (p *PodmanTestIntegration) RunLsContainerInPod(name, pod string) (*PodmanSessionIntegration, int, string) {
var podmanArgs = []string{"run", "--pod", pod}
if name != "" {
@@ -390,7 +392,7 @@ func (p *PodmanTestIntegration) BuildImage(dockerfile, imageName string, layers
dockerfilePath := filepath.Join(p.TempDir, "Dockerfile")
err := ioutil.WriteFile(dockerfilePath, []byte(dockerfile), 0755)
Expect(err).To(BeNil())
- session := p.Podman([]string{"build", "--layers=" + layers, "-t", imageName, "--file", dockerfilePath, p.TempDir})
+ session := p.PodmanNoCache([]string{"build", "--layers=" + layers, "-t", imageName, "--file", dockerfilePath, p.TempDir})
session.Wait(120)
Expect(session.ExitCode()).To(Equal(0))
}
@@ -465,7 +467,7 @@ func (p *PodmanTestIntegration) PullImages(images []string) error {
// PullImage pulls a single image
// TODO should the timeout be configurable?
func (p *PodmanTestIntegration) PullImage(image string) error {
- session := p.Podman([]string{"pull", image})
+ session := p.PodmanNoCache([]string{"pull", image})
session.Wait(60)
Expect(session.ExitCode()).To(Equal(0))
return nil
@@ -473,8 +475,8 @@ func (p *PodmanTestIntegration) PullImage(image string) error {
// InspectContainerToJSON takes the session output of an inspect
// container and returns json
-func (s *PodmanSessionIntegration) InspectContainerToJSON() []inspect.ContainerData {
- var i []inspect.ContainerData
+func (s *PodmanSessionIntegration) InspectContainerToJSON() []libpod.InspectContainerData {
+ var i []libpod.InspectContainerData
err := json.Unmarshal(s.Out.Contents(), &i)
Expect(err).To(BeNil())
return i
@@ -508,3 +510,35 @@ func (p *PodmanTestIntegration) RunTopContainerInPod(name, pod string) *PodmanSe
podmanArgs = append(podmanArgs, "-d", ALPINE, "top")
return p.Podman(podmanArgs)
}
+
+func (p *PodmanTestIntegration) ImageExistsInMainStore(idOrName string) bool {
+ results := p.PodmanNoCache([]string{"image", "exists", idOrName})
+ results.WaitWithDefaultTimeout()
+ return Expect(results.ExitCode()).To(Equal(0))
+}
+
+func (p *PodmanTestIntegration) RunHealthCheck(cid string) error {
+ for i := 0; i < 10; i++ {
+ hc := p.Podman([]string{"healthcheck", "run", cid})
+ hc.WaitWithDefaultTimeout()
+ if hc.ExitCode() == 0 {
+ return nil
+ }
+ // Restart container if it's not running
+ ps := p.Podman([]string{"ps", "--no-trunc", "--q", "--filter", fmt.Sprintf("id=%s", cid)})
+ ps.WaitWithDefaultTimeout()
+ if ps.ExitCode() == 0 {
+ if !strings.Contains(ps.OutputToString(), cid) {
+ fmt.Printf("Container %s is not running, restarting", cid)
+ restart := p.Podman([]string{"restart", cid})
+ restart.WaitWithDefaultTimeout()
+ if restart.ExitCode() != 0 {
+ return errors.Errorf("unable to restart %s", cid)
+ }
+ }
+ }
+ fmt.Printf("Waiting for %s to pass healthcheck\n", cid)
+ time.Sleep(1 * time.Second)
+ }
+ return errors.Errorf("unable to detect %s as running", cid)
+}