From d6d7edb841a8c3044c81386fdb4113dd895a26f3 Mon Sep 17 00:00:00 2001 From: Yiqiao Pu Date: Tue, 10 Apr 2018 18:48:22 +0800 Subject: Add WaitContainerReady for wait for docker registry ready Sometime podman push local registry still failed caused by the docker registry is not start yet after sleep 5s in the test. So add this function to check the container status by its output and skip the test when the docker registry can not start normally instead of failed the case. Signed-off-by: Yiqiao Pu --- test/e2e/libpod_suite_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/e2e/libpod_suite_test.go') diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go index 8e3b4254a..8887fd96e 100644 --- a/test/e2e/libpod_suite_test.go +++ b/test/e2e/libpod_suite_test.go @@ -593,3 +593,22 @@ func IsKernelNewThan(version string) (bool, error) { return false, nil } + +//Wait process or service inside container start, and ready to be used. +func WaitContainerReady(p *PodmanTest, id string, expStr string, timeout int, step int) bool { + startTime := time.Now() + s := p.Podman([]string{"logs", id}) + s.WaitWithDefaultTimeout() + fmt.Println(startTime) + for { + if time.Since(startTime) >= time.Duration(timeout)*time.Second { + return false + } + if strings.Contains(s.OutputToString(), expStr) { + return true + } + time.Sleep(time.Duration(step) * time.Second) + s = p.Podman([]string{"logs", id}) + s.WaitWithDefaultTimeout() + } +} -- cgit v1.2.3-54-g00ecf From f1a4867bcd4db4e5299225c0e7a35451ec0de7db Mon Sep 17 00:00:00 2001 From: Yiqiao Pu Date: Wed, 11 Apr 2018 15:04:25 +0800 Subject: Add a function for check if command exist Use this function to check if command exist before execute it in our test. Signed-off-by: Yiqiao Pu --- test/e2e/libpod_suite_test.go | 10 ++++++++++ test/e2e/push_test.go | 26 ++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'test/e2e/libpod_suite_test.go') diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go index 8887fd96e..fa48334a3 100644 --- a/test/e2e/libpod_suite_test.go +++ b/test/e2e/libpod_suite_test.go @@ -612,3 +612,13 @@ func WaitContainerReady(p *PodmanTest, id string, expStr string, timeout int, st s.WaitWithDefaultTimeout() } } + +//IsCommandAvaible check if command exist +func IsCommandAvailable(command string) bool { + check := exec.Command("bash", "-c", strings.Join([]string{"command -v", command}, " ")) + err := check.Run() + if err != nil { + return false + } + return true +} diff --git a/test/e2e/push_test.go b/test/e2e/push_test.go index f5bfc0c53..5267a66a4 100644 --- a/test/e2e/push_test.go +++ b/test/e2e/push_test.go @@ -78,14 +78,15 @@ var _ = Describe("Podman push", func() { cwd, _ := os.Getwd() certPath := filepath.Join(cwd, "../", "certs") - setup := podmanTest.SystemExec("getenforce", []string{}) - setup.WaitWithDefaultTimeout() - if setup.OutputToString() == "Enforcing" { - - setup = podmanTest.SystemExec("setenforce", []string{"0"}) - setup.WaitWithDefaultTimeout() - - defer podmanTest.SystemExec("setenforce", []string{"1"}) + if IsCommandAvailable("getenforce") { + ge := podmanTest.SystemExec("getenforce", []string{}) + ge.WaitWithDefaultTimeout() + if ge.OutputToString() == "Enforcing" { + se := podmanTest.SystemExec("setenforce", []string{"0"}) + se.WaitWithDefaultTimeout() + + defer podmanTest.SystemExec("setenforce", []string{"1"}) + } } session := podmanTest.Podman([]string{"run", "--entrypoint", "htpasswd", "registry:2", "-Bbn", "podmantest", "test"}) @@ -123,7 +124,7 @@ var _ = Describe("Podman push", func() { push.WaitWithDefaultTimeout() Expect(push.ExitCode()).To(Equal(0)) - setup = podmanTest.SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), "/etc/containers/certs.d/localhost:5000/ca.crt"}) + setup := podmanTest.SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), "/etc/containers/certs.d/localhost:5000/ca.crt"}) setup.WaitWithDefaultTimeout() defer os.RemoveAll("/etc/containers/certs.d/localhost:5000") @@ -186,17 +187,14 @@ var _ = Describe("Podman push", func() { }) It("podman push to local ostree", func() { - setup := podmanTest.SystemExec("which", []string{"ostree"}) - setup.WaitWithDefaultTimeout() - - if setup.ExitCode() != 0 { + if !IsCommandAvailable("ostree") { Skip("ostree is not installed") } ostreePath := filepath.Join(podmanTest.TempDir, "ostree/repo") os.MkdirAll(ostreePath, os.ModePerm) - setup = podmanTest.SystemExec("ostree", []string{strings.Join([]string{"--repo=", ostreePath}, ""), "init"}) + setup := podmanTest.SystemExec("ostree", []string{strings.Join([]string{"--repo=", ostreePath}, ""), "init"}) setup.WaitWithDefaultTimeout() session := podmanTest.Podman([]string{"push", ALPINE, strings.Join([]string{"ostree:alp@", ostreePath}, "")}) -- cgit v1.2.3-54-g00ecf