-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.sh
executable file
·307 lines (257 loc) · 7.97 KB
/
test.sh
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
set -Eo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
function print() {
echo -e "[$platform|$sdbms|$stest_case] $@"
}
function init_update() {
print "Prepare update tests"
MIN_VERSION=$OLD_VERSION
sed -i "s#SEAFILE_IMAGE=.*#SEAFILE_IMAGE=${IMAGE_FQN}:${OLD_VERSION}#" $TOPOLOGY_DIR/.env
launch
if [ $? -ne 0 ]; then
print "Launching previous version failed"
return 1
fi
sed -i "s#SEAFILE_IMAGE=.*#SEAFILE_IMAGE=${IMAGE_FQN}:${1}#" $TOPOLOGY_DIR/.env
}
function init_new_instance(){
print "Prepare new instance tests"
MIN_VERSION=$MAJOR_VERSION
}
function launch() {
$TOPOLOGY_DIR/compose.sh up -d &> /dev/null
if [ $? -ne 0 ]; then
$TOPOLOGY_DIR/compose.sh up -d &> $LOGS_FOLDER/launch-$(date +"%s")
return 1
fi
timeout=${timeout:=300}
c=1
while [[ "$(docker logs $CONTAINER_NAME |& grep -Pc '^Done\.$')" != "2" && $c -lt $timeout ]]
do
sleep 1
let c++
done
if [ $c -eq $timeout ]; then
docker logs $CONTAINER_NAME &> $LOGS_FOLDER/launch-$(date +"%s")
return 1
fi
}
function check_gc() {
# Depends only on current image
if [[ $failed -ne 0 || $GC_MIN_VERSION -gt $MAJOR_VERSION ]]; then
return 0
fi
echo "----------- GC TEST ----------"
echo "Check if garbage collection works"
$TOPOLOGY_DIR/compose.sh stop seafile &> /dev/null
log=$($TOPOLOGY_DIR/compose.sh run --rm seafile gc 2>&1 || echo failed_flag)
if [ "$(echo -e $log | grep 'failed_flag')" != "" ]; then
echo "Garbage collection failed"
echo $log > $LOGS_FOLDER/gc-$(date +"%s")
return 1
fi
}
function check_memcached() {
if [[ $failed -ne 0 || $MEMCACHED_MIN_VERSION -gt $MIN_VERSION ]]; then
return 0
fi
echo "------- MEMCACHED TEST -------"
echo "Check if memcached is configured correctly"
memcached_logs=$($TOPOLOGY_DIR/compose.sh logs memcached)
if [ ! "$(echo $memcached_logs | grep 'STORED')" ]
then
echo "Memcached is not set correctly"
echo $memcached_logs > $LOGS_FOLDER/memcached_logs-$(date +"%s")
return 1
fi
}
function check_notification_server() {
if [[ $dbms -eq 0 || $failed -ne 0 || $NOTIFICATION_SERVER_MIN_VERSION -gt $MIN_VERSION ]]; then
return 0
fi
echo "-- NOTIFICATION SERVER TEST --"
echo "Check if notification server is configured correctly"
log=$(curl --no-progress-meter http://$HOST:$PORT/notification/ping/ 2>&1)
pong=$(echo "$log" | jq -r '.ret' 2> /dev/null)
if [[ "$pong" != "pong" ]]
then
echo "Failed to ping notification server"
echo $log > $LOGS_FOLDER/notification_server_logs-$(date +"%s")
return 1
fi
}
function check_webdav() {
if [[ $failed -ne 0 || $WEBDAV_MIN_VERSION -gt $MIN_VERSION ]]; then
return 0
fi
echo "-------- WEBDAV TESTS --------"
flag=0
$ROOT_DIR/tests/webdav_tests.sh || flag=1
return $flag
}
function clean() {
print "Cleaning..."
$TOPOLOGY_DIR/compose.sh down -v &> /dev/null
}
function do_tests() {
lsdbms=( "SQLite" "MariaDB" "MySQL" )
stest_cases=( "New instance" "Major update" )
init_funcs=( init_new_instance init_update )
for dbms in "${!lsdbms[@]}"
do
sdbms=${lsdbms[$dbms]}
for test_case in "${!init_funcs[@]}"
do
stest_case=${stest_cases[$test_case]}
write_env "$1" "$dbms"
${init_funcs[$test_case]} "$1"
if [ $? -ne 0 ]; then
print "${RED}Initialization failed, pass${NC}"
FAILED=1
clean
continue
fi
print "Launch Seafile"
launch
if [ $? -ne 0 ]; then
print "${RED}Launch failed, pass${NC}"
FAILED=1
clean
continue
fi
print "Launch tests"
failed=0
$ROOT_DIR/tests/seahub_tests.sh || failed=1
check_webdav || failed=1
check_memcached || failed=1
check_notification_server || failed=1
# Has to be the last check since it stops the server
check_gc || failed=1
if [ $failed -ne 0 ]; then
FAILED=1
docker logs $CONTAINER_NAME &> $LOGS_FOLDER/launch-$(date +"%s")
print "${RED}Failed${NC}"
fi
clean
done
done
}
function write_env() {
print "Write .env"
echo "DBMS=$2
NOSWAG=1
NOSWAG_PORT=$PORT
SEAFILE_IMAGE=$IMAGE_FQN:$1
HOST=$HOST
PORT=$PORT
SEAFILE_ADMIN_EMAIL=$SEAFILE_ADMIN_EMAIL
SEAFILE_ADMIN_PASSWORD=$SEAFILE_ADMIN_PASSWORD
USE_HTTPS=0
MYSQL_HOST=db
MYSQL_USER_PASSWD=secret
MYSQL_ROOT_PASSWD=secret
SEAFILE_CONF_DIR=conf
SEAFILE_LOGS_DIR=logs
SEAFILE_DATA_DIR=data
SEAFILE_SEAHUB_DIR=seahub
DATABASE_DIR=db
WEBDAV=1
NOTIFICATION_SERVER=1
MEMCACHED_HOST=memcached:11211" > $TOPOLOGY_DIR/.env
}
echo "Loading environment..."
set -o allexport
[ -f .env ] && . .env
set +o allexport
[ -f ./tests/feature_table.env ] && . ./tests/feature_table.env
while getopts R:D:r:u:i:v:h:d:l:P:o:b:B flag
do
case "${flag}" in
R) export REVISION=$OPTARG;;
D) export DOCKERFILE_DIR=$OPTARG;;
r) export REGISTRY="$OPTARG/";;
u) export REPOSITORY=$OPTARG;;
i) export IMAGE=$OPTARG;;
P) export MULTIARCH_PLATFORMS=$OPTARG;;
l) export MULTIARCH_PLATFORMS="linux/$OPTARG";;
v) export SEAFILE_SERVER_VERSION=$OPTARG
export PYTHON_REQUIREMENTS_URL_SEAHUB="https://raw.githubusercontent.com/haiwen/seahub/v${SEAFILE_SERVER_VERSION}-server/requirements.txt"
export PYTHON_REQUIREMENTS_URL_SEAFDAV="https://raw.githubusercontent.com/haiwen/seafdav/v${SEAFILE_SERVER_VERSION}-server/requirements.txt"
;;
h) export PYTHON_REQUIREMENTS_URL_SEAHUB=$OPTARG;;
d) export PYTHON_REQUIREMENTS_URL_SEAFDAV=$OPTARG;;
o) OLD_VERSION=$OPTARG;;
b) BRANCH=$OPTARG;;
B) BUILD=1;;
:) exit;;
\?) exit;;
esac
done
if [ ! "$OLD_VERSION" ]; then
echo "Missing OLD_VERSION"
exit
fi
if [ "$REGISTRY" != "" ]; then REGISTRY="$REGISTRY/"; fi
if [ "$BRANCH" == "" ]; then BRANCH="master"; fi
IMAGE_FQN=$REGISTRY$REPOSITORY/$IMAGE
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $ROOT_DIR
if [ "$BUILD" = "1" ]
then
echo "Build images"
export NO_ENV=1
./build_image.sh
fi
echo "Set up test topology"
MAJOR_VERSION=${SEAFILE_SERVER_VERSION%%.*}
TOPOLOGY=test-topology
TOPOLOGY_DIR=$ROOT_DIR/$TOPOLOGY
cd $ROOT_DIR
rm -rf $TOPOLOGY_DIR
git clone https://github.com/ChatDeBlofeld/seafile-arm-docker $TOPOLOGY &> /dev/null
CONTAINER_NAME=$TOPOLOGY-seafile-1
rm -rf logs
mkdir logs
cd $TOPOLOGY_DIR
git checkout $BRANCH
# Runtime variables
export HOST=127.0.0.1
export PORT=44444
export [email protected]
export SEAFILE_ADMIN_PASSWORD=secret
export LOGS_FOLDER=$ROOT_DIR/logs
sed -i 's/#~//g' compose.seafile.common.yml
write_env latest 1 &> /dev/null
$TOPOLOGY_DIR/compose.sh down -v &> /dev/null
echo "Write nginx config"
config=$TOPOLOGY_DIR/nginx/seafile.noswag.conf
sed -i "s/your\.domain/${HOST}/" $config
sed -i 's/#~//g' $config
IFS=',' read -r -a PLATFORMS <<< "$MULTIARCH_PLATFORMS"
for platform in "${PLATFORMS[@]}"
do
platform="$(sed 's#linux/##' <<< $platform)"
tag="$(sed 's#/##' <<< $platform)"
if [ "$BUILD" = 1 ]
then
echo "Export $platform image to local images"
$ROOT_DIR/build_image.sh -t "$tag" -l "$platform"
fi
if [ "$(docker images -qf reference="${IMAGE_FQN}:${tag}")" = "" ]
then
echo -e "${RED}Can't find image for ${platform}, pass${NC}"
FAILED=1
else
do_tests "$tag"
fi
done
echo "Clean topology"
rm -rf $TOPOLOGY_DIR
if [[ FAILED -ne 0 ]]; then
echo -e "${RED}FAILED${NC}"
else
echo -e "${GREEN}SUCCESS${NC}"
fi