9
9
set -exo nounset
10
10
shopt -s nullglob
11
11
12
- . test/test_lib
12
+ # library from container-common-scripts
13
+ . test/test-lib.sh
14
+
15
+ # local library
16
+ . test/pg-test-lib.sh
13
17
14
18
TEST_LIST=" \
15
19
run_upgrade_test
@@ -29,6 +33,7 @@ test -n "${OS-}" || false 'make sure $OS is defined'
29
33
30
34
CIDFILE_DIR=$( mktemp --suffix=postgresql_test_cidfiles -d)
31
35
36
+ volumes_to_clean=
32
37
33
38
function cleanup() {
34
39
for cidfile in $CIDFILE_DIR /* ; do
@@ -46,18 +51,22 @@ function cleanup() {
46
51
echo " Done."
47
52
done
48
53
rmdir $CIDFILE_DIR
54
+
55
+ ct_path_foreach " $volumes_to_clean " cleanup_volume_dir
49
56
}
50
57
trap cleanup EXIT
51
58
52
- function cleanup_volume() {
53
- local volume_dir=" $1 " ; shift
54
- local cid=" $1 " ; shift
55
- local volume_args=" -v ${volume_dir} :/var/lib/pgsql/data:Z"
56
-
57
- docker stop $cid
58
- local rm_cmd=' /bin/rm -rf /var/lib/pgsql/data/userdata'
59
- docker run $volume_args --rm $IMAGE_NAME /bin/sh -c " $rm_cmd "
60
- rmdir ${volume_dir}
59
+ cleanup_volume_dir ()
60
+ {
61
+ test ! -d " $1 " && : " WARN: cleaned $1 for some reason" && return 0
62
+ # When we run this test script as non-root (we should?), the PostgreSQL server
63
+ # within container is still run under 'postgres' user. It means that, taking
64
+ # into account 0077 umask of PostgreSQL server, we are unable to remove files
65
+ # created by server. That's why we need to let docker escalate the privileges
66
+ # again.
67
+ local datadir=/var/lib/pgsql/data
68
+ docker run -v " $1 :$datadir :Z" --rm " $IMAGE_NAME " /bin/sh -c " /bin/rm -rf $datadir /userdata"
69
+ rmdir " $1 "
61
70
}
62
71
63
72
function get_cid() {
@@ -127,13 +136,15 @@ function create_container() {
127
136
echo " Created container $( cat $cidfile ) "
128
137
}
129
138
130
- function create_volume() {
131
- local volume_dir
139
+
140
+ create_volume_dir ()
141
+ {
132
142
volume_dir=` mktemp -d --tmpdir pg-testdata.XXXXX`
133
143
setfacl -m u:26:-wx " $volume_dir "
134
- echo " $volume_dir "
144
+ ct_path_append volumes_to_clean " $volume_dir "
135
145
}
136
146
147
+
137
148
function assert_login_access() {
138
149
local PGUSER=$1 ; shift
139
150
local PASS=$1 ; shift
@@ -385,7 +396,7 @@ function run_master_restart_test() {
385
396
local master_ip=
386
397
local slave_cids=
387
398
388
- local volume_dir= $( create_volume )
399
+ create_volume_dir
389
400
local master_args=" -v ${volume_dir} :/var/lib/pgsql/data:Z"
390
401
391
402
# Setup the cluster
@@ -409,9 +420,6 @@ function run_master_restart_test() {
409
420
410
421
# Check if the replication works
411
422
table_name=" t1" test_value_replication
412
-
413
- # Cleanup the volume
414
- cleanup_volume $volume_dir $( cat $cidfile )
415
423
}
416
424
417
425
function run_replication_test() {
@@ -445,7 +453,7 @@ function run_change_password_test() {
445
453
local password=' password'
446
454
local admin_password=' adminPassword'
447
455
448
- local volume_dir= $( create_volume )
456
+ create_volume_dir
449
457
local volume_options=" -v ${volume_dir} :/var/lib/pgsql/data:Z"
450
458
451
459
DOCKER_ARGS="
@@ -495,13 +503,6 @@ $volume_options
495
503
assert_login_access ' postgres' " NEW_${admin_password} " true
496
504
assert_login_access ' postgres' ${admin_password} false
497
505
498
- # When we run this test script as non-root (we should?), the PostgreSQL server
499
- # within container is still run under 'postgres' user. It means that, taking
500
- # into account 0077 umask of PostgreSQL server, we are unable to remove files
501
- # created by server. That's why we need to let docker escalate the privileges
502
- # again.
503
- cleanup_volume $volume_dir $( get_cid ${name} )
504
-
505
506
echo " Success!"
506
507
}
507
508
0 commit comments