From 0fe0c79dc9f7074e30466c81e0fbc157faa00db2 Mon Sep 17 00:00:00 2001 From: Yiqiao Pu Date: Thu, 29 Mar 2018 16:50:27 +0800 Subject: Add several podman push tests Add five tests for podman push tests: - push to docker with authorization - push to docker-archive - push to docker-daemon - push to oci-archive - push to ostree Signed-off-by: Yiqiao Pu --- test/certs/domain.crt | 18 +++++++ test/certs/domain.key | 6 +++ test/e2e/push_test.go | 143 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 test/certs/domain.crt create mode 100644 test/certs/domain.key (limited to 'test') diff --git a/test/certs/domain.crt b/test/certs/domain.crt new file mode 100644 index 000000000..881fc124d --- /dev/null +++ b/test/certs/domain.crt @@ -0,0 +1,18 @@ +-----BEGIN CERTIFICATE----- +MIIC3zCCAmSgAwIBAgIUdbnvx7lLf8OANP37QTKoxfNAl5EwCgYIKoZIzj0EAwMw +gawxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T +YW4gRnJhbmNpc2NvMSowKAYDVQQKEyFIb25lc3QgQWNobWVkJ3MgVXNlZCBDZXJ0 +aWZpY2F0ZXMxKTAnBgNVBAsTIEhhc3RpbHktR2VuZXJhdGVkIFZhbHVlcyBEaXZp +c29uMRkwFwYDVQQDExBBdXRvZ2VuZXJhdGVkIENBMB4XDTE4MDMyMDExMDUwMFoX +DTE5MDMyMDExMDUwMFowWzEVMBMGA1UEBxMMdGhlIGludGVybmV0MRYwFAYDVQQK +Ew1hdXRvZ2VuZXJhdGVkMRQwEgYDVQQLEwtwb2RtYW4gdGVzdDEUMBIGA1UEAxML +cG9kbWFuLXRlc3QwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAATA65F+T8sreSnTm+I2 +IjeKN8rb5W2j3QKXz8n9JkPWiWX16HGIWso1JWPhhjvpmVkfSzD91niQwrsm6PhP +ypZUzkX5iL7JE8jVjflEiUbflSzc+fgT/scqRUUQ3evmqUCjgZYwgZMwDgYDVR0P +AQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAMBgNVHRMB +Af8EAjAAMB0GA1UdDgQWBBQCgkUh4aBOTl5KHettBluuE7rccDAfBgNVHSMEGDAW +gBTPyUqMxUVdwC4K+kh9jHtnf7GrETAUBgNVHREEDTALgglsb2NhbGhvc3QwCgYI +KoZIzj0EAwMDaQAwZgIxAKsrYLbXSJs473tlfX3OF/BmfTvDwBO5TfPoZ1yNDhVk +UvoYn2szSEVMwR7uX1gKWgIxALz00G6umVkSh0MgIwSaYpJU/N1eVNgbIXRFV+5+ +lK/0jLWm4aAFkVhqUkkueTzG2g== +-----END CERTIFICATE----- diff --git a/test/certs/domain.key b/test/certs/domain.key new file mode 100644 index 000000000..b0f15eb75 --- /dev/null +++ b/test/certs/domain.key @@ -0,0 +1,6 @@ +-----BEGIN EC PRIVATE KEY----- +MIGkAgEBBDB7ZI5Q6dOSwOqpJ2FVlFuDJN/sJB3epR2S+rOvCPua+rQ8uv6lpZDx +CQ4ioUMFo6agBwYFK4EEACKhZANiAATA65F+T8sreSnTm+I2IjeKN8rb5W2j3QKX +z8n9JkPWiWX16HGIWso1JWPhhjvpmVkfSzD91niQwrsm6PhPypZUzkX5iL7JE8jV +jflEiUbflSzc+fgT/scqRUUQ3evmqUA= +-----END EC PRIVATE KEY----- diff --git a/test/e2e/push_test.go b/test/e2e/push_test.go index b2c55607f..8593c3e99 100644 --- a/test/e2e/push_test.go +++ b/test/e2e/push_test.go @@ -2,6 +2,8 @@ package integration import ( "os" + "path/filepath" + "strings" "time" . "github.com/onsi/ginkgo" @@ -43,8 +45,6 @@ var _ = Describe("Podman push", func() { Expect(session.ExitCode()).To(Equal(0)) }) - // push to oci-archive, docker-archive, and dir are tested in pull_test.go - It("podman push to dir", func() { session := podmanTest.Podman([]string{"push", "--remove-signatures", ALPINE, "dir:/tmp/busybox"}) session.WaitWithDefaultTimeout() @@ -67,4 +67,143 @@ var _ = Describe("Podman push", func() { push.WaitWithDefaultTimeout() Expect(push.ExitCode()).To(Equal(0)) }) + + It("podman push to local registry with authorization", func() { + authPath := filepath.Join(podmanTest.TempDir, "auth") + os.Mkdir(authPath, os.ModePerm) + os.MkdirAll("/etc/containers/certs.d/localhost:5000", os.ModePerm) + debug := podmanTest.SystemExec("ls", []string{"-l", podmanTest.TempDir}) + debug.WaitWithDefaultTimeout() + + 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"}) + } + + session := podmanTest.Podman([]string{"run", "--entrypoint", "htpasswd", "registry:2", "-Bbn", "podmantest", "test"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + f, _ := os.Create(filepath.Join(authPath, "htpasswd")) + defer f.Close() + + f.WriteString(session.OutputToString()) + f.Sync() + debug = podmanTest.SystemExec("cat", []string{filepath.Join(authPath, "htpasswd")}) + debug.WaitWithDefaultTimeout() + + session = podmanTest.Podman([]string{"run", "-d", "-p", "5000:5000", "--name", "registry", "-v", + strings.Join([]string{authPath, "/auth"}, ":"), "-e", "REGISTRY_AUTH=htpasswd", "-e", + "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm", "-e", "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd", + "-v", strings.Join([]string{certPath, "/certs"}, ":"), "-e", "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt", + "-e", "REGISTRY_HTTP_TLS_KEY=/certs/domain.key", "registry:2"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + time.Sleep(5 * time.Second) + + session = podmanTest.Podman([]string{"logs", "registry"}) + session.WaitWithDefaultTimeout() + + push := podmanTest.Podman([]string{"push", "--creds=podmantest:test", ALPINE, "localhost:5000/tlstest"}) + push.WaitWithDefaultTimeout() + Expect(push.ExitCode()).To(Not(Equal(0))) + + push = podmanTest.Podman([]string{"push", "--creds=podmantest:test", "--tls-verify=false", ALPINE, "localhost:5000/tlstest"}) + 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.WaitWithDefaultTimeout() + defer os.RemoveAll("/etc/containers/certs.d/localhost:5000") + + push = podmanTest.Podman([]string{"push", "--creds=podmantest:wrongpasswd", ALPINE, "localhost:5000/credstest"}) + push.WaitWithDefaultTimeout() + Expect(push.ExitCode()).To(Not(Equal(0))) + + push = podmanTest.Podman([]string{"push", "--creds=podmantest:test", "--cert-dir=fakedir", ALPINE, "localhost:5000/certdirtest"}) + push.WaitWithDefaultTimeout() + Expect(push.ExitCode()).To(Not(Equal(0))) + + push = podmanTest.Podman([]string{"push", "--creds=podmantest:test", ALPINE, "localhost:5000/defaultflags"}) + push.WaitWithDefaultTimeout() + Expect(push.ExitCode()).To(Equal(0)) + }) + + It("podman push to docker-archive", func() { + session := podmanTest.Podman([]string{"push", ALPINE, "docker-archive:/tmp/alp:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + clean := podmanTest.SystemExec("rm", []string{"/tmp/alp"}) + clean.WaitWithDefaultTimeout() + Expect(clean.ExitCode()).To(Equal(0)) + }) + + It("podman push to docker daemon", func() { + setup := podmanTest.SystemExec("bash", []string{"-c", "systemctl status docker 2>&1"}) + setup.WaitWithDefaultTimeout() + + if setup.LineInOuputContains("Active: inactive") { + setup = podmanTest.SystemExec("systemctl", []string{"start", "docker"}) + setup.WaitWithDefaultTimeout() + + defer podmanTest.SystemExec("systemctl", []string{"stop", "docker"}) + } else if setup.ExitCode() != 0 { + Skip("Docker is not avaiable") + } + + session := podmanTest.Podman([]string{"push", ALPINE, "docker-daemon:alpine:podmantest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + check := podmanTest.SystemExec("docker", []string{"images", "--format", "{{.Repository}}:{{.Tag}}"}) + check.WaitWithDefaultTimeout() + Expect(check.ExitCode()).To(Equal(0)) + Expect(check.OutputToString()).To(ContainSubstring("alpine:podmantest")) + + clean := podmanTest.SystemExec("docker", []string{"rmi", "alpine:podmantest"}) + clean.WaitWithDefaultTimeout() + Expect(clean.ExitCode()).To(Equal(0)) + }) + + It("podman push to oci-archive", func() { + session := podmanTest.Podman([]string{"push", ALPINE, "oci-archive:/tmp/alp.tar:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + clean := podmanTest.SystemExec("rm", []string{"/tmp/alp.tar"}) + clean.WaitWithDefaultTimeout() + Expect(clean.ExitCode()).To(Equal(0)) + }) + + It("podman push to local ostree", func() { + setup := podmanTest.SystemExec("which", []string{"ostree"}) + setup.WaitWithDefaultTimeout() + + if setup.ExitCode() != 0 { + 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.WaitWithDefaultTimeout() + + session := podmanTest.Podman([]string{"push", ALPINE, strings.Join([]string{"ostree:alp@", ostreePath}, "")}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + clean := podmanTest.SystemExec("rm", []string{"-rf", ostreePath}) + clean.WaitWithDefaultTimeout() + Expect(clean.ExitCode()).To(Equal(0)) + }) + }) -- cgit v1.2.3-54-g00ecf 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 +++++++++++++++++++ test/e2e/push_test.go | 12 +++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'test') 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() + } +} diff --git a/test/e2e/push_test.go b/test/e2e/push_test.go index 8593c3e99..f5bfc0c53 100644 --- a/test/e2e/push_test.go +++ b/test/e2e/push_test.go @@ -4,7 +4,6 @@ import ( "os" "path/filepath" "strings" - "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -56,12 +55,13 @@ var _ = Describe("Podman push", func() { }) It("podman push to local registry", func() { - session := podmanTest.Podman([]string{"run", "-d", "-p", "5000:5000", "docker.io/library/registry:2", "/entrypoint.sh", "/etc/docker/registry/config.yml"}) + session := podmanTest.Podman([]string{"run", "-d", "--name", "registry", "-p", "5000:5000", "docker.io/library/registry:2", "/entrypoint.sh", "/etc/docker/registry/config.yml"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - // Give the registry 5 seconds to warm up before pushing - time.Sleep(5 * time.Second) + if !WaitContainerReady(&podmanTest, "registry", "listening on", 20, 1) { + Skip("Can not start docker registry.") + } push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, "localhost:5000/my-alpine"}) push.WaitWithDefaultTimeout() @@ -108,7 +108,9 @@ var _ = Describe("Podman push", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - time.Sleep(5 * time.Second) + if !WaitContainerReady(&podmanTest, "registry", "listening on", 20, 1) { + Skip("Can not start docker registry.") + } session = podmanTest.Podman([]string{"logs", "registry"}) session.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') 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