Skip to content

Commit 036810a

Browse files
authored
tests: add run-openshift template tests (#209)
* tests: add run-openshift template tests Resolves: #204
1 parent 4321c9e commit 036810a

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

Diff for: common

Diff for: test/postgresql-ephemeral-template.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../examples/postgresql-ephemeral-template.json

Diff for: test/run-openshift

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
#
3+
# Test the Postgresql image in OpenShift.
4+
#
5+
# IMAGE_NAME specifies a name of the candidate image used for testing.
6+
# The image has to be available before this script is executed.
7+
#
8+
9+
THISDIR=$(dirname ${BASH_SOURCE[0]})
10+
11+
source "$THISDIR"/test-lib-openshift.sh
12+
13+
set -exo nounset
14+
15+
function check_postgresql_os_service_connection() {
16+
local util_image_name=$1 ; shift
17+
local service_name=$1 ; shift
18+
local user=$1 ; shift
19+
local pass=$1 ; shift
20+
local database=$1 ; shift
21+
local timeout=${1:-60} ; shift || :
22+
local pod_ip=$(ct_os_get_service_ip ${service_name})
23+
24+
: " Service ${service_name} check ..."
25+
26+
local cmd="PGPASSWORD=${pass} pg_isready -t 15 -h ${pod_ip} -U ${user} -d ${database}"
27+
local expected_value='accepting connections'
28+
local output
29+
local ret
30+
SECONDS=0
31+
32+
echo -n "Waiting for ${service_name} service becoming ready ..."
33+
while true ; do
34+
output=$(docker run --rm ${util_image_name} bash -c "${cmd}" || :)
35+
echo "${output}" | grep -qe "${expected_value}" && ret=0 || ret=1
36+
if [ ${ret} -eq 0 ] ; then
37+
echo " PASS"
38+
return 0
39+
fi
40+
echo -n "."
41+
[ ${SECONDS} -gt ${timeout} ] && break
42+
sleep 3
43+
done
44+
echo " FAIL"
45+
return 1
46+
}
47+
48+
function test_postgresql_pure_image() {
49+
local image_name=$1
50+
local image_name_no_namespace=${image_name##*/}
51+
local service_name=${image_name_no_namespace}
52+
53+
ct_os_new_project
54+
ct_os_upload_image "${image_name}"
55+
56+
ct_os_deploy_pure_image "${image_name}" \
57+
--name "${service_name}" \
58+
--env POSTGRESQL_ADMIN_PASSWORD=test
59+
60+
ct_os_wait_pod_ready "${service_name}" 60
61+
check_postgresql_os_service_connection "${image_name}" "${service_name}" postgres test postgres
62+
63+
ct_os_delete_project
64+
}
65+
66+
function test_postgresql_template() {
67+
local image_name=${1:-centos/postgresql-96-centos7}
68+
local image_name_no_namespace=${image_name##*/}
69+
local service_name=${image_name_no_namespace}
70+
71+
ct_os_new_project
72+
ct_os_upload_image "${image_name}"
73+
74+
ct_os_deploy_template_image ${THISDIR}/postgresql-ephemeral-template.json \
75+
DATABASE_SERVICE_NAME="${service_name}" \
76+
POSTGRESQL_USER=testu \
77+
POSTGRESQL_PASSWORD=testp \
78+
POSTGRESQL_DATABASE=testdb
79+
80+
ct_os_wait_pod_ready "${service_name}" 60
81+
check_postgresql_os_service_connection "${image_name}" "${service_name}" testu testp testdb
82+
83+
ct_os_delete_project
84+
}
85+
86+
ct_os_cluster_up
87+
test_postgresql_pure_image ${IMAGE_NAME}
88+
test_postgresql_template ${IMAGE_NAME}

0 commit comments

Comments
 (0)