Skip to content

Commit

Permalink
Support to run tests against 4.0.0 on CI (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Fernandes committed Feb 7, 2019
1 parent 5ad2544 commit 6120bbf
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 15 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ cache:

before_script:
- go get -u github.com/golang/dep/cmd/dep
- sudo mount --make-shared /
- sudo sed 's/DOCKER_OPTS="/DOCKER_OPTS="--insecure-registry 172.30.0.0\/16 / ' -i /etc/default/docker
- sudo service docker restart
- ci/start-okd-3.11.sh
- ci/start-okd-4.0.0.sh

after_failure:
- docker ps -a
- for log in $(docker ps -qa | xargs); do docker logs --tail 500 $log; done

script:
- make test
- make test KUBECONFIG=/tmp/openshift-dind-cluster/openshift/openshift.local.config/master/admin.kubeconfig

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ run:
run-local: build
build/run-local.sh ${KUBECONFIG}

## test: Run e2e tests
## test: Run e2e tests. A KUBECONFIG can be specified with cmd line arg 'KUBECONFIG=/path/to/config'
test: build
GOCACHE=off go test -v ./test/e2e
build/run-tests.sh ${KUBECONFIG}

help : Makefile
@sed -n 's/^##//p' $<
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,21 @@ To create a cluster, apply
oc apply -f deploy/crds/infinispan_v1_infinispan_cr.yaml
```

### Running tests

The Makefile has a target for testing that can target a particular external running cluster. E.g:

To run tests against 3.11 clusters started with ``` oc cluster up```:

```make test```

or

``` make test KUBECONFIG=/path/to/openshift.local.clusterup/openshift-apiserver/admin.kubeconfig```

in case the cluster was started in a different directory than the Makefile.

To run against 4.0.0 cluster:


``` make test KUBECONFIG=/tmp/openshift-dind-cluster/openshift/openshift.local.config/master/admin.kubeconfig```
7 changes: 7 additions & 0 deletions build/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

KUBECONFIG=${1-openshift.local.clusterup/openshift-apiserver/admin.kubeconfig}

echo "Using KUBECONFIG '$KUBECONFIG'"

GOCACHE=off go test -v ./test/e2e
19 changes: 19 additions & 0 deletions ci/start-okd-4.0.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

docker run --name oc-cluster-up -d -v /etc/docker/certs.d/:/certs/ -v /tmp/:/tmp/ -v /var/run/docker.sock:/var/run/docker.sock gustavonalle/oc-cluster-up

function get_master {
echo $(docker exec openshift-master oc describe node/openshift-master-node | grep InternalIP | awk '{print $2}')
}

SLEEP=3
MAX_WAIT=100

echo "Waiting for OKD to be ready..."

while ! curl -k -s "https://$(get_master):8443/healthz/ready"
do
echo "Still waiting..."
((c++)) && ((c==$MAX_WAIT)) && exit 1
sleep $SLEEP
done
12 changes: 11 additions & 1 deletion test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ import (
"github.com/jboss-dockerfiles/infinispan-server-operator/pkg/apis/infinispan/v1"
"github.com/jboss-dockerfiles/infinispan-server-operator/test/e2e/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"testing"
"time"
)

const ConfigLocation = "../../openshift.local.clusterup/kube-apiserver/admin.kubeconfig"
func getConfigLocation() string {
kubeConfig := os.Getenv("KUBECONFIG")
if kubeConfig != "" {
return kubeConfig
} else {
return "../../openshift.local.clusterup/kube-apiserver/admin.kubeconfig"
}
}

var ConfigLocation = getConfigLocation()

// Simple smoke test to check if the OKD is alive
func TestSimple(t *testing.T) {
Expand Down
25 changes: 23 additions & 2 deletions test/e2e/util/okd_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var timeout = 120 * time.Second
// constructs a new ExternalOKD client providing the path of kubeconfig file.
func NewOKDClient(kubeConfigLocation string) *ExternalOKD {
c := new(ExternalOKD)
dir := GetRelativeDir(kubeConfigLocation)
dir := GetAbsolutePath(kubeConfigLocation)
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: dir},
&clientcmd.ConfigOverrides{})
Expand Down Expand Up @@ -138,6 +138,27 @@ func (c ExternalOKD) CreateInfinispan(infinispan *api.Infinispan, namespace stri
}
}

// Deletes an Infinispan resource in the given namespace
func (c ExternalOKD) DeleteInfinispan(name string, namespace string) {
ispnSvc := c.ispnClient.Infinispans(namespace)
e := ispnSvc.Delete(name, &deleteOpts)
if e != nil {
panic(e)
}
// Wait until deleted
err := wait.Poll(period, timeout, func() (done bool, err error) {
ispn, err := ispnSvc.Get(name, metaV1.GetOptions{})

if reflect.DeepEqual(api.Infinispan{}, *ispn) { // Non existent
return true, nil
}
return false, nil
})
if err != nil {
panic(err)
}
}

// Creates or updates a config map based on a file
func (c ExternalOKD) CreateOrUpdateConfigMap(name string, filePath string, namespace string) {
bytes, e := ioutil.ReadFile(filePath)
Expand Down Expand Up @@ -329,7 +350,7 @@ func (c ExternalOKD) WaitForPods(ns, label string, required int, timeout time.Du
podReady := false
conditions := pod.Status.Conditions
for _, cond := range conditions {
if (cond.Type) == v1.ContainersReady {
if (cond.Type) == v1.ContainersReady && cond.Status == "True" {
podReady = true
}
}
Expand Down
14 changes: 9 additions & 5 deletions test/e2e/util/operator_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func Cleanup(client ExternalOKD, namespace string) {
}

func installConfigMap(ns string, okd *ExternalOKD) {
dir := GetRelativeDir("../../config/cloud-ephemeral.xml")
dir := GetAbsolutePath("../../config/cloud-ephemeral.xml")
okd.CreateOrUpdateConfigMap("infinispan-app-configuration", dir, ns)
}

// Install resources from rbac.yaml required by the Infinispan operator
func installRBAC(ns string, okd *ExternalOKD) {
filename := GetRelativeDir("../../deploy/rbac.yaml")
filename := GetAbsolutePath("../../deploy/rbac.yaml")
f, err := os.Open(filename)
if err != nil {
panic(err)
Expand All @@ -58,7 +58,7 @@ func installRBAC(ns string, okd *ExternalOKD) {
}

func installCRD(okd *ExternalOKD) {
filename := GetRelativeDir("../../deploy/crd.yaml")
filename := GetAbsolutePath("../../deploy/crd.yaml")
f, err := os.Open(filename)
if err != nil {
panic(err)
Expand All @@ -82,8 +82,12 @@ func StopOperator() {
_ = syscall.Kill(syscall.Getpid(), syscall.SIGINT)
}

func GetRelativeDir(path string) string {
// Obtain the file absolute path given a relative path
func GetAbsolutePath(relativeFilePath string) string {
if !strings.HasPrefix(relativeFilePath, ".") {
return relativeFilePath
}
dir, _ := os.Getwd()
absPath, _ := filepath.Abs(dir + "/" + path)
absPath, _ := filepath.Abs(dir + "/" + relativeFilePath)
return absPath
}

0 comments on commit 6120bbf

Please sign in to comment.