Skip to content
Permalink
Browse files

E2E test for every supported images (#2402)

* E2E test for every supported images

* Rebase pr

* Added docker hub supported images

* Verify odo commands flow for supported images

* Fixing golint error

* check for registry.redhat.io

* checking particular test

* modified e2e test for supported images

* Waiting for openshift/release#6341 odo-secret to be volume mounted

* Updating review comments

* Modified the file content according to review change request

* PR rebase
  • Loading branch information
prietyc123 committed Feb 12, 2020
1 parent e21d6c6 commit 379a82a470d694fab8c736006dbf2cdef7d53772
Showing with 248 additions and 1 deletion.
  1. +4 −1 .travis.yml
  2. +5 −0 Makefile
  3. +178 −0 tests/e2escenarios/e2e_images_test.go
  4. +53 −0 tests/helper/helper_generic.go
  5. +8 −0 tests/helper/helper_oc.go
@@ -111,4 +111,7 @@ jobs:
- travis_wait make test-e2e-beta
- travis_wait make test-e2e-java
- travis_wait make test-e2e-source
- odo logout
- travis_wait make test-e2e-images
- odo logout


@@ -228,6 +228,11 @@ test-e2e-java:
test-e2e-source:
ginkgo $(GINKGO_FLAGS) -focus="odo source e2e tests" tests/e2escenarios/

# Run supported images e2e tests
.PHONY: test-e2e-images
test-e2e-images:
ginkgo $(GINKGO_FLAGS) -focus="odo supported images e2e tests" tests/e2escenarios/

# Run all e2e test scenarios
.PHONY: test-e2e-all
test-e2e-all:
@@ -0,0 +1,178 @@
package e2escenarios

import (
"os"
"path/filepath"
"strings"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper"
)

var _ = Describe("odo supported images e2e tests", func() {
//new clean project and context for each test
var project string
var context string
appName := "app"

var oc helper.OcRunner

BeforeEach(func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
oc = helper.NewOcRunner("oc")
context = helper.CreateNewContext()
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
project = helper.CreateRandProject()
})

AfterEach(func() {
helper.DeleteProject(project)
helper.DeleteDir(context)
os.Unsetenv("GLOBALODOCONFIG")
})

OdoWatch := func(srcType, routeURL, project, appName, context string) {

startSimulationCh := make(chan bool)
go func() {
startMsg := <-startSimulationCh
if startMsg {
err := os.MkdirAll(filepath.Join(context, ".abc"), 0755)
if err != nil {
panic(err)
}
err = os.MkdirAll(filepath.Join(context, "abcd"), 0755)
if err != nil {
panic(err)
}
_, err = os.Create(filepath.Join(context, "a.txt"))
if err != nil {
panic(err)
}

helper.DeleteDir(filepath.Join(context, "abcd"))

if srcType == "openjdk" {
helper.ReplaceString(filepath.Join(context, "src", "main", "java", "MessageProducer.java"), "Hello", "Hello odo")
} else {
helper.ReplaceString(filepath.Join(context, "server.js"), "Hello", "Hello odo")
}
}
}()

success, err := helper.WatchNonRetCmdStdOut(
("odo watch " + srcType + "-app" + " -v 4 " + "--context " + context),
time.Duration(5)*time.Minute,
func(output string) bool {
curlURL := helper.CmdShouldPass("curl", routeURL)
if strings.Contains(curlURL, "Hello odo") {
// Verify delete from component pod
podName := oc.GetRunningPodNameOfComp(srcType+"-app", project)
envs := oc.GetEnvs(srcType+"-app", appName, project)
dir := envs["ODO_S2I_SRC_BIN_PATH"]
stdOut := oc.ExecListDir(podName, project, filepath.Join(dir, "src"))
Expect(stdOut).To(ContainSubstring(("a.txt")))
Expect(stdOut).To(Not(ContainSubstring("abcd")))
}
return strings.Contains(curlURL, "Hello odo")
},
startSimulationCh,
func(output string) bool {
return strings.Contains(output, "Waiting for something to change")
})

Expect(success).To(Equal(true))
Expect(err).To(BeNil())

// Verify memory limits to be same as configured
getMemoryLimit := oc.MaxMemory(srcType+"-app", appName, project)
Expect(getMemoryLimit).To(ContainSubstring("700Mi"))
getMemoryRequest := oc.MinMemory(srcType+"-app", appName, project)
Expect(getMemoryRequest).To(ContainSubstring("400Mi"))
}

// verifySupportedImage takes arguments supported images, source type, image type, namespace and application name.
// Also verify the flow of odo commands with respect to supported images only.
verifySupportedImage := func(image, srcType, cmpType, project, appName string) {

// create the component
helper.CopyExample(filepath.Join("source", srcType), context)
helper.CmdShouldPass("odo", "create", cmpType, srcType+"-app", "--project", project, "--context", context, "--app", appName, "--min-memory", "400Mi", "--max-memory", "700Mi")

// push component and validate
helper.CmdShouldPass("odo", "push", "--context", context)
cmpList := helper.CmdShouldPass("odo", "list", "--context", context)
Expect(cmpList).To(ContainSubstring(srcType + "-app"))

// create a url
helper.CmdShouldPass("odo", "url", "create", "--port", "8080", "--context", context)
helper.CmdShouldPass("odo", "push", "--context", context)
routeURL := helper.DetermineRouteURL(context)

// Ping said URL
helper.HttpWaitFor(routeURL, "Hello", 90, 1)

// edit source and validate
if srcType == "openjdk" {
helper.ReplaceString(filepath.Join(context, "src", "main", "java", "MessageProducer.java"), "Hello", "Hello Java UPDATED")
helper.CmdShouldPass("odo", "push", "--context", context)
helper.HttpWaitFor(routeURL, "Hello Java UPDATED", 90, 1)
} else {
helper.ReplaceString(filepath.Join(context, "server.js"), "Hello", "Hello nodejs UPDATED")
helper.CmdShouldPass("odo", "push", "--context", context)
helper.HttpWaitFor(routeURL, "Hello nodejs UPDATED", 90, 1)
}

// odo watch and validate
OdoWatch(srcType, routeURL, project, appName, context)

// delete the component and validate
helper.CmdShouldPass("odo", "app", "delete", "app", "--project", project, "-f")
cmpLst := helper.CmdShouldPass("odo", "list", "--context", context)
Expect(cmpLst).To(ContainSubstring("Not Pushed"))
}

Context("odo supported images deployment", func() {
It("Should be able to verify the openjdk18-openshift image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("redhat-openjdk-18", "openjdk18-openshift:latest"), "java:8", project)
verifySupportedImage(filepath.Join("redhat-openjdk-18", "openjdk18-openshift:latest"), "openjdk", "java:8", project, appName)
})

It("Should be able to verify the openjdk-11-rhel7 image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("openjdk", "openjdk-11-rhel7:latest"), "java:8", project)
verifySupportedImage(filepath.Join("openjdk", "openjdk-11-rhel7:latest"), "openjdk", "java:8", project, appName)
})

It("Should be able to verify the nodejs-8-rhel7 image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("rhscl", "nodejs-8-rhel7:latest"), "nodejs:8", project)
verifySupportedImage(filepath.Join("rhscl", "nodejs-8-rhel7:latest"), "nodejs", "nodejs:8", project, appName)
})

It("Should be able to verify the nodejs-8 image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("rhoar-nodejs", "nodejs-8:latest"), "nodejs:8", project)
verifySupportedImage(filepath.Join("rhoar-nodejs", "nodejs-8:latest"), "nodejs", "nodejs:8", project, appName)
})

It("Should be able to verify the nodejs-10 image", func() {
oc.ImportImageFromRegistry("registry.access.redhat.com", filepath.Join("rhoar-nodejs", "nodejs-10:latest"), "nodejs:8", project)
verifySupportedImage(filepath.Join("rhoar-nodejs", "nodejs-10:latest"), "nodejs", "nodejs:8", project, appName)
})

It("Should be able to verify the centos7-s2i-nodejs image", func() {
oc.ImportImageFromRegistry("docker.io", filepath.Join("bucharestgold", "centos7-s2i-nodejs"), "nodejs:8", project)
verifySupportedImage(filepath.Join("bucharestgold", "centos7-s2i-nodejs"), "nodejs", "nodejs:8", project, appName)
})

It("Should be able to verify the centos7-s2i-nodejs:10.x image", func() {
oc.ImportImageFromRegistry("docker.io", filepath.Join("bucharestgold", "centos7-s2i-nodejs:10.x"), "nodejs:8", project)
verifySupportedImage(filepath.Join("bucharestgold", "centos7-s2i-nodejs:10.x"), "nodejs", "nodejs:8", project, appName)
})

It("Should be able to verify the nodejs-8-centos7 image", func() {
oc.ImportImageFromRegistry("docker.io", filepath.Join("centos", "nodejs-8-centos7:latest"), "nodejs:8", project)
verifySupportedImage(filepath.Join("centos", "nodejs-8-centos7:latest"), "nodejs", "nodejs:8", project, appName)
})
})
})
@@ -1,9 +1,11 @@
package helper

import (
"bytes"
"encoding/json"
"fmt"
"math/rand"
"os/exec"
"strings"
"time"

@@ -81,3 +83,54 @@ func Unindented(jsonStr string) (string, error) {
}
return string(obj), err
}

// WatchNonRetCmdStdOut run odo watch and get the cmdSTDOUT output into buffer.
// startIndicatorFunc sets true and startSimulationCh starts, when buffer contain "Waiting for something to change"
// check function checks for the changes into the buffer
func WatchNonRetCmdStdOut(cmdStr string, timeout time.Duration, check func(output string) bool, startSimulationCh chan bool, startIndicatorFunc func(output string) bool) (bool, error) {
var cmd *exec.Cmd
var buf bytes.Buffer

cmdStrParts := strings.Split(cmdStr, " ")
cmdName := cmdStrParts[0]
fmt.Println("Running command: ", cmdStrParts)
if len(cmdStrParts) > 1 {
cmdStrParts = cmdStrParts[1:]
cmd = exec.Command(cmdName, cmdStrParts...)
} else {
cmd = exec.Command(cmdName)
}
cmd.Stdout = &buf

ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()

timeoutCh := make(chan bool)
go func() {
time.Sleep(timeout)
timeoutCh <- true
}()

if err := cmd.Start(); err != nil {
return false, err
}

startedFileModification := false
for {
select {
case <-timeoutCh:
Fail("Timeout out after " + string(timeout) + " minutes")
case <-ticker.C:
if !startedFileModification && startIndicatorFunc(buf.String()) {
startedFileModification = true
startSimulationCh <- true
}
if check(buf.String()) {
if err := cmd.Process.Kill(); err != nil {
return true, err
}
return true, nil
}
}
}
}
@@ -3,6 +3,7 @@ package helper
import (
"bufio"
"fmt"
"path/filepath"
"regexp"
"strings"
"time"
@@ -274,6 +275,13 @@ func (oc *OcRunner) checkForImageStream(name string, tag string) bool {
return false
}

// ImportImageFromRegistry import the required image of the respective component type from the specified registry
func (oc *OcRunner) ImportImageFromRegistry(registry, image, cmpType, project string) {
CmdShouldPass(oc.path, "--request-timeout", "5m", "import-image", cmpType, "--namespace="+project, "--from="+filepath.Join(registry, image), "--confirm")
CmdShouldPass(oc.path, "annotate", filepath.Join("istag", cmpType), "--namespace="+project, "tags=builder", "--overwrite")

}

// ImportJavaIS import the openjdk image which is used for jars
func (oc *OcRunner) ImportJavaIS(project string) {
// if ImageStram already exists, no need to do anything

0 comments on commit 379a82a

Please sign in to comment.
You can’t perform that action at this time.