-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathrun_upgrade_test
executable file
·100 lines (83 loc) · 2.37 KB
/
run_upgrade_test
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
96
97
98
99
100
#! /bin/bash
set -e
. test/pg-test-lib.sh
ADMIN_PASSWORD=redhat
STEPS=( "$@" )
quote_args ()
{
quote_args_result=
local space=
for arg; do
quote_args_result+="$space$(printf "%q" "$arg")"
space=' '
done
}
quote_args_print ()
{
quote_args "$@"
echo "$quote_args_result"
}
# background_container IMAGE DOCKER_ARGS CMD
background_container ()
{
CID=$(eval "docker run -d $2 $1 $3")
test -n "$CID"
info "Started container $CID" >&2
}
# run_server DATADIR IMAGE_ID DOCKER_ARGS
run_server ()
{
local datadir=$1
local image_id=$2
local docker_args=$(quote_args_print -e POSTGRESQL_ADMIN_PASSWORD="$ADMIN_PASSWORD")
docker_args+=' '$(quote_args_print -v "$datadir:/var/lib/pgsql/data:Z")
docker_args+=" $3"
background_container "$image_id" "$docker_args"
}
# init_datadir IMAGE_ID dataspec
# ------------------------------
init_datadir ()
{
local image_id=$1
DATADIR=$(mktemp -d)
setfacl -m u:26:rwx "$DATADIR"
run_server "$DATADIR" "$image_id"
wait_for_postgres "$CID"
eval "data_$2_create"
eval "data_$2_check"
docker stop "$CID" >/dev/null
docker rm -f "$CID" >/dev/null
}
# check_upgrade_path {hardlink|copy} dataspec
assert_upgrade_succeeds ()
{
info "Initializing datadir with $VERSION_FROM PostgreSQL"
local INIT_IMAGE=$(get_image_id "$VERSION_FROM")
local dataspec=$2
init_datadir "$INIT_IMAGE" "$dataspec"
info "Running upgrade '$1/$dataspec'"
for upgrade_to in "${UPGRADE_PATH[@]}"; do
info "Upgrading to $upgrade_to"
UPGRADE_IMAGE=$(get_image_id "$upgrade_to")
run_server "$DATADIR" "$UPGRADE_IMAGE" "-e POSTGRESQL_UPGRADE=$1"
docker logs "$CID"
wait_for_postgres "$CID"
eval "data_${dataspec}_check"
debug "the upgrading container of version '$upgrade_to' responded"
docker stop "$CID" >/dev/null
docker rm -f "$CID" >/dev/null
run_server "$DATADIR" "$UPGRADE_IMAGE"
docker logs "$CID"
wait_for_postgres "$CID"
eval "data_${dataspec}_check"
debug "restarted server of version '$upgrade_to' responded"
docker stop "$CID" >/dev/null
docker rm -f "$CID" >/dev/null
done
}
VERSION_FROM=$1 ; shift
UPGRADE_PATH=( "$@" )
for data in empty pagila; do
assert_upgrade_succeeds hardlink "$data"
assert_upgrade_succeeds copy "$data"
done