Skip to content

Commit f7fbbb3

Browse files
hhorakpraiskup
authored andcommitted
Add support for remote cluster tests
Also share BASE_IMAGE_NAME variable so it can be used in tests.
1 parent a7759b9 commit f7fbbb3

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

common.mk

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ endif
1111

1212
build = $(SHELL) $(common_dir)/build.sh
1313
test = $(SHELL) $(common_dir)/test.sh
14+
testr = $(SHELL) $(common_dir)/test-remote-cluster.sh
1415
tag = $(SHELL) $(common_dir)/tag.sh
1516
clean = $(SHELL) $(common_dir)/clean.sh
1617

@@ -92,10 +93,14 @@ test-with-conu: script_env += TEST_CONU_MODE=true
9293
test-with-conu: tag
9394
VERSIONS="$(VERSIONS)" $(script_env) $(test)
9495

96+
.PHONY: test-openshift-remote-cluster
97+
test-openshift-remote-cluster:
98+
VERSIONS="$(VERSIONS)" BASE_IMAGE_NAME="$(BASE_IMAGE_NAME)" $(script_env) $(testr)
99+
95100
.PHONY: test-openshift
96101
test-openshift: script_env += TEST_OPENSHIFT_MODE=true
97102
test-openshift: tag
98-
VERSIONS="$(VERSIONS)" $(script_env) $(test)
103+
VERSIONS="$(VERSIONS)" BASE_IMAGE_NAME="$(BASE_IMAGE_NAME)" $(script_env) $(test)
99104

100105
.PHONY: tag
101106
tag: build

test-lib-openshift.sh

+19-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ source $(dirname ${BASH_SOURCE[0]})/test-lib.sh
99
# And the following trap must be set, in the beginning of the test script:
1010
# trap ct_os_cleanup EXIT SIGINT
1111
OS_TESTSUITE_RESULT=1
12+
OS_CLUSTER_STARTED_BY_TEST=0
1213

1314
function ct_os_cleanup() {
1415
if [ $OS_TESTSUITE_RESULT -eq 0 ] ; then
@@ -347,6 +348,15 @@ function ct_os_is_tag_exists() {
347348
oc get is "${is_name}" -n openshift -o=jsonpath='{.spec.tags[*].name}' | grep -qw "${tag}"
348349
}
349350
351+
# ct_os_template_exists T_NAME
352+
# --------------------
353+
# Checks whether the specified template exists for an image stream
354+
# Arguments: t_name - template name of the image stream
355+
function ct_os_template_exists() {
356+
local t_name=$1 ; shift
357+
oc get templates -n openshift | grep -q "^${t_name}\s"
358+
}
359+
350360
# ct_os_install_in_centos
351361
# --------------------
352362
# Installs os cluster in CentOS
@@ -412,6 +422,7 @@ function ct_os_cluster_up() {
412422
ct_os_wait_rc_ready docker-registry 180
413423
ct_os_wait_rc_ready router 30
414424
oc login -u developer -p developer
425+
OS_CLUSTER_STARTED_BY_TEST=1
415426
# let openshift cluster to sync to avoid some race condition errors
416427
sleep 3
417428
}
@@ -420,7 +431,12 @@ function ct_os_cluster_up() {
420431
# --------------------
421432
# Shuts down the local OpenShift cluster using 'oc cluster down'
422433
function ct_os_cluster_down() {
423-
oc cluster down
434+
if [ ${OS_CLUSTER_STARTED_BY_TEST:-0} -eq 1 ] ; then
435+
echo "Cluster started by the test, shutting down."
436+
oc cluster down
437+
else
438+
echo "Cluster not started by the test, shutting down skipped."
439+
fi
424440
}
425441
426442
# ct_os_cluster_running
@@ -701,7 +717,7 @@ function ct_os_test_template_app_func() {
701717
# get the template file from remote or local location; if not found, it is
702718
# considered an internal template name, like 'mysql', so use the name
703719
# explicitly
704-
local local_template=$(ct_obtain_input "${template}" || echo "${template}")
720+
local local_template=$(ct_obtain_input "${template}" 2>/dev/null || echo "--template=${template}")
705721
local namespace=${CT_NAMESPACE:-$(oc project -q)}
706722
oc new-app ${local_template} \
707723
--name "${name_in_template}" \
@@ -969,3 +985,4 @@ function ct_os_check_cmd_internal() {
969985
return 1
970986
}
971987

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

test-lib.sh

+2
Original file line numberDiff line numberDiff line change
@@ -505,3 +505,5 @@ EOF
505505
docker build -f "$df_name" -t "$dst_image" .
506506
popd
507507
}
508+
509+
# vim: set tabstop=2:shiftwidth=2:expandtab:

test-remote-cluster.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# This script is used to test container images integrated in the OpenShift.
4+
#
5+
# VERSIONS - Must be set to a list with possible versions (subdirectories)
6+
#
7+
# This script expects oc command to exist and logged in to a working cluster.
8+
9+
set -e
10+
11+
export OS=${OS:-rhel7}
12+
13+
if [ "${OS}" == "rhel7" ] ; then
14+
NAMESPACE=${NAMESPACE:-rhscl/}
15+
REGISTRY=${REGISTRY:-registry.access.redhat.com/}
16+
else
17+
NAMESPACE=${NAMESPACE:-centos/}
18+
fi
19+
20+
export NAMESPACE
21+
export REGISTRY
22+
23+
for dir in ${VERSIONS}; do
24+
pushd ${dir} > /dev/null
25+
26+
export IMAGE_NAME="${REGISTRY}${NAMESPACE}${BASE_IMAGE_NAME}-${dir//./}-${OS}"
27+
28+
VERSION=$dir test/run-openshift-remote-cluster
29+
30+
popd > /dev/null
31+
done
32+
33+
# vim: set tabstop=2:shiftwidth=2:expandtab:

0 commit comments

Comments
 (0)