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