Skip to content

Commit

Permalink
Add support for remote cluster tests
Browse files Browse the repository at this point in the history
Also share BASE_IMAGE_NAME variable so it can be used in tests.
  • Loading branch information
hhorak authored and praiskup committed Feb 5, 2019
1 parent a7759b9 commit f7fbbb3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
7 changes: 6 additions & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ endif

build = $(SHELL) $(common_dir)/build.sh
test = $(SHELL) $(common_dir)/test.sh
testr = $(SHELL) $(common_dir)/test-remote-cluster.sh
tag = $(SHELL) $(common_dir)/tag.sh
clean = $(SHELL) $(common_dir)/clean.sh

Expand Down Expand Up @@ -92,10 +93,14 @@ test-with-conu: script_env += TEST_CONU_MODE=true
test-with-conu: tag
VERSIONS="$(VERSIONS)" $(script_env) $(test)

.PHONY: test-openshift-remote-cluster
test-openshift-remote-cluster:
VERSIONS="$(VERSIONS)" BASE_IMAGE_NAME="$(BASE_IMAGE_NAME)" $(script_env) $(testr)

.PHONY: test-openshift
test-openshift: script_env += TEST_OPENSHIFT_MODE=true
test-openshift: tag
VERSIONS="$(VERSIONS)" $(script_env) $(test)
VERSIONS="$(VERSIONS)" BASE_IMAGE_NAME="$(BASE_IMAGE_NAME)" $(script_env) $(test)

.PHONY: tag
tag: build
Expand Down
21 changes: 19 additions & 2 deletions test-lib-openshift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ source $(dirname ${BASH_SOURCE[0]})/test-lib.sh
# And the following trap must be set, in the beginning of the test script:
# trap ct_os_cleanup EXIT SIGINT
OS_TESTSUITE_RESULT=1
OS_CLUSTER_STARTED_BY_TEST=0

function ct_os_cleanup() {
if [ $OS_TESTSUITE_RESULT -eq 0 ] ; then
Expand Down Expand Up @@ -347,6 +348,15 @@ function ct_os_is_tag_exists() {
oc get is "${is_name}" -n openshift -o=jsonpath='{.spec.tags[*].name}' | grep -qw "${tag}"
}
# ct_os_template_exists T_NAME
# --------------------
# Checks whether the specified template exists for an image stream
# Arguments: t_name - template name of the image stream
function ct_os_template_exists() {
local t_name=$1 ; shift
oc get templates -n openshift | grep -q "^${t_name}\s"
}
# ct_os_install_in_centos
# --------------------
# Installs os cluster in CentOS
Expand Down Expand Up @@ -412,6 +422,7 @@ function ct_os_cluster_up() {
ct_os_wait_rc_ready docker-registry 180
ct_os_wait_rc_ready router 30
oc login -u developer -p developer
OS_CLUSTER_STARTED_BY_TEST=1
# let openshift cluster to sync to avoid some race condition errors
sleep 3
}
Expand All @@ -420,7 +431,12 @@ function ct_os_cluster_up() {
# --------------------
# Shuts down the local OpenShift cluster using 'oc cluster down'
function ct_os_cluster_down() {
oc cluster down
if [ ${OS_CLUSTER_STARTED_BY_TEST:-0} -eq 1 ] ; then
echo "Cluster started by the test, shutting down."
oc cluster down
else
echo "Cluster not started by the test, shutting down skipped."
fi
}
# ct_os_cluster_running
Expand Down Expand Up @@ -701,7 +717,7 @@ function ct_os_test_template_app_func() {
# get the template file from remote or local location; if not found, it is
# considered an internal template name, like 'mysql', so use the name
# explicitly
local local_template=$(ct_obtain_input "${template}" || echo "${template}")
local local_template=$(ct_obtain_input "${template}" 2>/dev/null || echo "--template=${template}")
local namespace=${CT_NAMESPACE:-$(oc project -q)}
oc new-app ${local_template} \
--name "${name_in_template}" \
Expand Down Expand Up @@ -969,3 +985,4 @@ function ct_os_check_cmd_internal() {
return 1
}

# vim: set tabstop=2:shiftwidth=2:expandtab:
2 changes: 2 additions & 0 deletions test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,5 @@ EOF
docker build -f "$df_name" -t "$dst_image" .
popd
}

# vim: set tabstop=2:shiftwidth=2:expandtab:
33 changes: 33 additions & 0 deletions test-remote-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# This script is used to test container images integrated in the OpenShift.
#
# VERSIONS - Must be set to a list with possible versions (subdirectories)
#
# This script expects oc command to exist and logged in to a working cluster.

set -e

export OS=${OS:-rhel7}

if [ "${OS}" == "rhel7" ] ; then
NAMESPACE=${NAMESPACE:-rhscl/}
REGISTRY=${REGISTRY:-registry.access.redhat.com/}
else
NAMESPACE=${NAMESPACE:-centos/}
fi

export NAMESPACE
export REGISTRY

for dir in ${VERSIONS}; do
pushd ${dir} > /dev/null

export IMAGE_NAME="${REGISTRY}${NAMESPACE}${BASE_IMAGE_NAME}-${dir//./}-${OS}"

VERSION=$dir test/run-openshift-remote-cluster

popd > /dev/null
done

# vim: set tabstop=2:shiftwidth=2:expandtab:

0 comments on commit f7fbbb3

Please sign in to comment.