diff options
Diffstat (limited to 'test/e2e/common_test.go')
-rw-r--r-- | test/e2e/common_test.go | 121 |
1 files changed, 119 insertions, 2 deletions
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index b22ead3fa..b20b3b37e 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -3,12 +3,17 @@ package integration import ( "encoding/json" "fmt" + "github.com/containers/libpod/pkg/rootless" + "io/ioutil" "os" "os/exec" "path/filepath" + "sort" "strings" "testing" + "github.com/containers/storage" + "github.com/containers/libpod/pkg/inspect" . "github.com/containers/libpod/test/utils" "github.com/containers/storage/pkg/reexec" @@ -40,13 +45,33 @@ type PodmanTestIntegration struct { SignaturePolicyPath string CgroupManager string Host HostOS + Timings []string + TmpDir string } +var LockTmpDir string + // PodmanSessionIntegration sturct for command line session type PodmanSessionIntegration struct { *PodmanSession } +type testResult struct { + name string + length float64 +} + +type testResultsSorted []testResult + +func (a testResultsSorted) Len() int { return len(a) } +func (a testResultsSorted) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + +type testResultsSortedLength struct{ testResultsSorted } + +func (a testResultsSorted) Less(i, j int) bool { return a[i].length < a[j].length } + +var testResults []testResult + // TestLibpod ginkgo master function func TestLibpod(t *testing.T) { if reexec.Init() { @@ -60,7 +85,7 @@ func TestLibpod(t *testing.T) { RunSpecs(t, "Libpod Suite") } -var _ = BeforeSuite(func() { +var _ = SynchronizedBeforeSuite(func() []byte { //Cache images cwd, _ := os.Getwd() INTEGRATION_ROOT = filepath.Join(cwd, "../../") @@ -72,6 +97,7 @@ var _ = BeforeSuite(func() { os.Exit(1) } } + for _, image := range CACHE_IMAGES { if err := podman.CreateArtifact(image); err != nil { fmt.Printf("%q\n", err) @@ -92,6 +118,68 @@ var _ = BeforeSuite(func() { } f.Close() } + path, err := ioutil.TempDir("", "libpodlock") + if err != nil { + fmt.Println(err) + os.Exit(1) + } + return []byte(path) +}, func(data []byte) { + LockTmpDir = string(data) +}) + +func (p *PodmanTestIntegration) Setup() { + cwd, _ := os.Getwd() + INTEGRATION_ROOT = filepath.Join(cwd, "../../") + 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) + } }) // PodmanTestCreate creates a PodmanTestIntegration instance for the tests @@ -126,7 +214,11 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { if os.Getenv("STORAGE_OPTIONS") != "" { storageOptions = os.Getenv("STORAGE_OPTIONS") } + cgroupManager := CGROUP_MANAGER + if rootless.IsRootless() { + cgroupManager = "cgroupfs" + } if os.Getenv("CGROUP_MANAGER") != "" { cgroupManager = os.Getenv("CGROUP_MANAGER") } @@ -147,7 +239,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { ociRuntime = "/usr/bin/runc" } } - + os.Setenv("DISABLE_HC_SYSTEMD", "true") CNIConfigDir := "/etc/cni/net.d" p := &PodmanTestIntegration{ @@ -159,6 +251,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { }, ConmonBinary: conmonBinary, CrioRoot: filepath.Join(tempDir, "crio"), + TmpDir: tempDir, CNIConfigDir: CNIConfigDir, OCIRuntime: ociRuntime, RunRoot: filepath.Join(tempDir, "crio-run"), @@ -220,3 +313,27 @@ func (s *PodmanSessionIntegration) InspectImageJSON() []inspect.ImageData { Expect(err).To(BeNil()) return i } + +// InspectContainer returns a container's inspect data in JSON format +func (p *PodmanTestIntegration) InspectContainer(name string) []inspect.ContainerData { + cmd := []string{"inspect", name} + session := p.Podman(cmd) + session.WaitWithDefaultTimeout() + return session.InspectContainerToJSON() +} + +func processTestResult(f GinkgoTestDescription) { + tr := testResult{length: f.Duration.Seconds(), name: f.TestText} + testResults = append(testResults, tr) +} + +func GetPortLock(port string) storage.Locker { + lockFile := filepath.Join(LockTmpDir, port) + lock, err := storage.GetLockfile(lockFile) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + lock.Lock() + return lock +} |