-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.sh
executable file
·331 lines (284 loc) · 9.25 KB
/
run.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/bash
# Main user controlled variables
# Report type to provide
REPORT_TYPE='table_full'
# First argument is the name of the scenario to run. (Optional)
# Log level on console. Can be overrided as 2nd argument passing to the script.
LOG_LEVEL=0
# Timezone
TIMEZONE=`timedatectl | grep 'Time zone' | cut -d ':' -f 2 | awk '{ print $1 }'`
# Maximum time single test is allowed to run in seconds. (2 min)
MAX_SINGLE_TEST_TIME=120
# TLS-WSS proxy port parameters, change them only if you know what you are doing
OPENSIPS_TLS_PORT=6051
OPENSIPS_WSS_PORT=9443
# HEP Source port
OPENSIPS_HEPS_PORT=8887
# HEP Destination port
OPENSIPS_HEPD_PORT=8888
print_running_char() {
case "${rc}" in
"-"|".-")
rc="\\"
;;
"\\")
rc="|"
;;
"|")
rc="/"
;;
"/")
rc=".-"
;;
esac
echo -en "\b \b${rc}"
}
wait_background_container() {
# Declare counter(i), process_counter(pc) and running_character(rc)
i=0
pc=`docker ps | grep ${1} | wc -l`
rc='-'
echo -n "Running ${CURRENT_SCENARIO} ${2} ${rc}"
TIME_TEST_START=`date +%s`
ERROR_STRING=""
MAX_CYCLES=$(( ${MAX_SINGLE_TEST_TIME} * 2 ))
# Limit with maximum time
while [ $i -le ${MAX_CYCLES} ] && [ $pc -ge 1 ]; do
((i++))
sleep 0.5
pc=`docker ps | grep ${1} | wc -l`
print_running_char
done
if [ $pc -ge 1 ]; then
docker stop ${1} >> /dev/null
ERROR_STRING="\n[WARNING] Container ${1} was forcefully stopped"
fi
TIME_TEST_END=`date +%s`
echo -e "\b\b \b\b. Done in $((${TIME_TEST_END} - ${TIME_TEST_START}))s${ERROR_STRING}"
}
control_opensips() {
if [ "${1}" = "start" ]; then
echo "Websocket proxy starting... "
docker run --name=${PROXY_CONTAINER_NAME} \
--env OPENSIPS_TLS_PORT=`echo ${OPENSIPS_TLS_PORT}` \
--env OPENSIPS_WSS_PORT=`echo ${OPENSIPS_WSS_PORT}` \
--env OPENSIPS_HEPS_PORT=`echo ${OPENSIPS_HEPS_PORT}` \
--env OPENSIPS_HEPD_PORT=`echo ${OPENSIPS_HEPD_PORT}` \
--env VP_TLS_PORT=`echo $[${VP_PORT} + 1]` \
--net=host \
--rm \
-d \
${PROXY_IMAGE} >> /dev/null
# Give a time to start the container
sleep 0.5
else
echo "Websocket proxy stopping..."
docker stop ${PROXY_CONTAINER_NAME} >> /dev/null 2>&1
fi
}
run_voip_patrol() {
if [ ! -f "${DIR_PREFIX}/tmp/input/${CURRENT_SCENARIO}/voip_patrol.xml" ]; then
return
fi
BG_RUN=""
OUT_REDIRECT=""
if [ ${LOG_LEVEL} -eq 0 ]; then
BG_RUN="-d"
OUT_REDIRECT=">> /dev/null"
fi
docker rm ${VP_CONTAINER_NAME} >> /dev/null 2>&1
eval docker run --name=${VP_CONTAINER_NAME} \
--env XML_CONF=`echo ${CURRENT_SCENARIO}` \
--env PORT=`echo ${VP_PORT}` \
--env RESULT_FILE=`echo ${VP_RESULT_FILE}` \
--env LOG_LEVEL=`echo ${LOG_LEVEL}` \
--env LOG_LEVEL_FILE=`echo ${LOG_LEVEL_FILE}` \
--env TZ=`echo ${TIMEZONE}` \
--volume ${DIR_PREFIX}/tmp/input/${CURRENT_SCENARIO}/voip_patrol.xml:/xml/${CURRENT_SCENARIO}.xml \
--volume ${DIR_PREFIX}/tmp/output:/output \
--volume ${DIR_PREFIX}/voice_ref_files:/voice_ref_files \
--net=host \
--rm \
${BG_RUN} \
${VP_IMAGE} ${OUT_REDIRECT}
if [ ${LOG_LEVEL} -eq 0 ]; then
wait_background_container ${VP_CONTAINER_NAME} voip_patrol
fi
}
run_prepare() {
docker run --name=${P_CONTAINER_NAME} \
--env SCENARIO_NAME=`echo ${SCENARIO}` \
--env OPENSIPS_TLS_PORT=`echo ${OPENSIPS_TLS_PORT}` \
--env LOG_LEVEL=`echo ${LOG_LEVEL}` \
--env TZ=`echo ${TIMEZONE}` \
--volume ${DIR_PREFIX}/scenarios:/opt/input/ \
--volume ${DIR_PREFIX}/tmp/input:/opt/output \
--net=none \
--rm \
${P_IMAGE}
}
run_report() {
docker run --name=${R_CONTAINER_NAME} \
--env VP_RESULT_FILE=`echo ${VP_RESULT_FILE}` \
--env D_RESULT_FILE=`echo ${D_RESULT_FILE}` \
--env M_RESULT_FILE=`echo ${M_RESULT_FILE}` \
--env SIPP_RESULT_FILE=`echo ${SIPP_RESULT_FILE}` \
--env REPORT_TYPE=`echo ${REPORT_TYPE}` \
--env TZ=`echo ${TIMEZONE}` \
--volume ${DIR_PREFIX}/tmp/input:/opt/scenarios/ \
--volume ${DIR_PREFIX}/tmp/output:/opt/report \
--net=none \
--rm \
${R_IMAGE}
}
run_database() {
if [ ! -f "${DIR_PREFIX}/tmp/input/${CURRENT_SCENARIO}/database.xml" ]; then
return
fi
eval docker run --name=${D_CONTAINER_NAME} \
--env SCENARIO=`echo ${CURRENT_SCENARIO}` \
--env RESULT_FILE=`echo ${D_RESULT_FILE}` \
--env LOG_LEVEL=`echo ${LOG_LEVEL}` \
--env STAGE=`echo ${1}` \
--env TZ=`echo ${TIMEZONE}` \
--volume ${DIR_PREFIX}/tmp/input/${CURRENT_SCENARIO}/database.xml:/xml/${CURRENT_SCENARIO}.xml \
--volume ${DIR_PREFIX}/tmp/output:/output \
--rm \
${D_IMAGE}
}
run_sipp() {
if [ ! -f "${DIR_PREFIX}/tmp/input/${CURRENT_SCENARIO}/sipp.xml" ]; then
return
fi
BG_RUN=""
OUT_REDIRECT=""
if [ ${LOG_LEVEL} -eq 0 ]; then
BG_RUN="-d"
OUT_REDIRECT=">> /dev/null"
fi
eval docker run --name=${SIPP_CONTAINER_NAME} \
--env SCENARIO=`echo ${CURRENT_SCENARIO}` \
--env RESULT_FILE=`echo ${SIPP_RESULT_FILE}` \
--env LOG_LEVEL=`echo ${LOG_LEVEL}` \
--volume ${DIR_PREFIX}/tmp/input/${CURRENT_SCENARIO}/sipp.xml:/xml/${CURRENT_SCENARIO}.xml \
--volume ${DIR_PREFIX}/tmp/output:/output \
--rm \
${BG_RUN} \
${SIPP_IMAGE} ${OUT_REDIRECT}
if [ ${LOG_LEVEL} -eq 0 ]; then
wait_background_container ${SIPP_CONTAINER_NAME} sipp
fi
}
run_media() {
if [ ! -f "${DIR_PREFIX}/tmp/input/${CURRENT_SCENARIO}/media_check.xml" ]; then
return
fi
docker run --name=${M_CONTAINER_NAME} \
--env SCENARIO=`echo ${CURRENT_SCENARIO}` \
--env RESULT_FILE=`echo ${M_RESULT_FILE}` \
--env LOG_LEVEL=`echo ${LOG_LEVEL}` \
--volume ${DIR_PREFIX}/tmp/input/${CURRENT_SCENARIO}/media_check.xml:/xml/${CURRENT_SCENARIO}.xml \
--volume ${DIR_PREFIX}/tmp/output:/output \
--net=none \
--rm \
${M_IMAGE}
}
cleanup_opensips_cache() {
docker exec ${PROXY_CONTAINER_NAME} /usr/bin/opensips-cli -x mi cache_remove_chunk "*" >> /dev/null 2>&1
}
delete_containers() {
docker stop ${M_CONTAINER_NAME} >> /dev/null 2>&1
docker stop ${SIPP_CONTAINER_NAME} >> /dev/null 2>&1
docker stop ${D_CONTAINER_NAME} >> /dev/null 2>&1
docker stop ${R_CONTAINER_NAME} >> /dev/null 2>&1
docker stop ${P_CONTAINER_NAME} >> /dev/null 2>&1
docker stop ${VP_CONTAINER_NAME} >> /dev/null 2>&1
docker stop ${PROXY_CONTAINER_NAME} >> /dev/null 2>&1
docker rm ${M_CONTAINER_NAME} >> /dev/null 2>&1
docker rm ${SIPP_CONTAINER_NAME} >> /dev/null 2>&1
docker rm ${D_CONTAINER_NAME} >> /dev/null 2>&1
docker rm ${R_CONTAINER_NAME} >> /dev/null 2>&1
docker rm ${P_CONTAINER_NAME} >> /dev/null 2>&1
docker rm ${VP_CONTAINER_NAME} >> /dev/null 2>&1
docker rm ${PROXY_CONTAINER_NAME} >> /dev/null 2>&1
}
run_scenario() {
run_database pre
run_voip_patrol
run_sipp
run_database post
run_media
cleanup_opensips_cache
}
# Script controlled variables
DIR_PREFIX=`pwd`
# First arument - single test to run
SCENARIO="$1"
# Second argument - default log level
LOG_LEVEL="${2:-${LOG_LEVEL}}"
mkdir -p tmp/input
mkdir -p tmp/output
if [ "x${SCENARIO}" != "x" ]; then
SCENARIO=`basename ${SCENARIO} | cut -f 1 -d .`
fi
# prepare
P_IMAGE=volts_prepare:latest
P_CONTAINER_NAME=volts_prepare
rm -f tmp/input/scenarios.done
run_prepare
if [ ! -f ${DIR_PREFIX}/tmp/input/scenarios.done ]; then
echo "Scenarios are not prepared, please check for the errors"
exit 1
fi
# database
D_IMAGE=volts_database:latest
D_CONTAINER_NAME=volts_database
D_RESULT_FILE="database.jsonl"
# voip_patrol
VP_IMAGE=volts_vp:latest
VP_CONTAINER_NAME=volts_vp
#VP_IMAGE=voip_patrol_local:latest
#VP_CONTAINER_NAME=voip_patrol_local
VP_PORT=5060
VP_RESULT_FILE="voip_patrol.jsonl"
LOG_LEVEL_FILE=${LOG_LEVEL}
# media
M_IMAGE=volts_media:latest
M_CONTAINER_NAME=volts_media
M_RESULT_FILE="media_check.jsonl"
# sipp
SIPP_CONTAINER_NAME=volts_sipp
SIPP_IMAGE=volts_sipp:latest
SIPP_RESULT_FILE="sipp.jsonl"
# opensips
PROXY_CONTAINER_NAME=volts_opensips
PROXY_IMAGE=volts_opensips:latest
TIME_TOTAL_START=`date +%s`
rm -f ${DIR_PREFIX}/tmp/output/${D_RESULT_FILE}
rm -f ${DIR_PREFIX}/tmp/output/${M_RESULT_FILE}
rm -f ${DIR_PREFIX}/tmp/output/${VP_RESULT_FILE}
rm -f ${DIR_PREFIX}/tmp/output/${SIPP_RESULT_FILE}
delete_containers
# Start WSS-TLS proxy
control_opensips start
if [ -z ${SCENARIO} ]; then
for D in ${DIR_PREFIX}/tmp/input/*; do
CURRENT_SCENARIO=`basename ${D}`
run_scenario
done
else
CURRENT_SCENARIO=${SCENARIO}
run_scenario
fi
# Stop WSS-TLS proxy
control_opensips stop
# report
R_IMAGE=volts_report:latest
R_CONTAINER_NAME=volts_report
run_report
delete_containers
TIME_TOTAL_END=`date +%s`
TIME_TOTAL_RUN=$((${TIME_TOTAL_END} - ${TIME_TOTAL_START}))
HMS_TOTAL_RUN=`date -d@${TIME_TOTAL_RUN} -u +%H:%M:%S`
echo "Total time taken: ${HMS_TOTAL_RUN}"
exit 0