-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqata
executable file
·175 lines (151 loc) · 4.27 KB
/
qata
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
#!/usr/bin/env bash
# The QA Test Automation (QATA) framework service
# - Server serves request on port 8421 (by default)
# - Dashboard listens on port 3000 (by default) and can be accessed
# at http://localhost:3000
if [ $( id | sed -e 's/(.*//' ) != "uid=0" ]; then
echo "Please rerun with super user privileges. "
exit 1
fi
project_dir=$(dirname $(readlink -f "$0"))
: ${SIS_TEST_DIR:=${project_dir}/test}
: ${SIS_LOGS_DIR:=${project_dir}/logs}
: ${SIS_TEST_WEBDRIVER:=selenium}
: ${DOCKER_NAMESPACE:=ucberkeley}
cid_dir=/var/run/qata
mkdir -p ${cid_dir}
server_cid_file=/var/run/qata/server.cid
: ${SIS_SERVER_PORT:=8421}
server_docker_image=${DOCKER_NAMESPACE}/sis-qa-test-auto-server
dashboard_cid_file=/var/run/qata/dashboard.cid
: ${SIS_DASHBOARD_PORT:=3000}
dashboard_docker_image=${DOCKER_NAMESPACE}/sis-qa-test-auto-dashboard
check_container() {
local cid_file=$1
local port=$2
if [ -f ${cid_file} ]; then
cid=$(cat ${cid_file})
if [[ $(docker ps -a -q -f Id=${cid}) ]]; then
if [[ $(netstat -tulnp | grep ${port}) ]]; then
return 0
fi
docker stop ${cid} && docker rm ${cid}
fi
rm -f ${cid_file}
fi
return 1
}
stop_container() {
local cid_file=$1
local cid
cid=$(cat ${cid_file})
if [[ $(docker ps -q -f Id=${cid}) ]]; then
docker stop ${cid} && docker rm ${cid}
fi
rm -f ${cid_file}
}
get_image() {
local image=$1
docker inspect ${image} &> /dev/null; if [ $? -ne 0 ]; then
docker pull ${image}
fi
}
start() {
local server_up=1
local dashboard_up=1
# Start server and dashboard
if check_container ${server_cid_file} ${SIS_SERVER_PORT}; then
server_up=0
echo "QATA Server already running."
else
echo "Starting QATA Server..."
get_image ${server_docker_image}
local server_cid
server_cid=$(docker run \
--net=host \
-t \
-d \
-e DISPLAY=${DISPLAY} \
-e SIS_SERVER_PORT=${SIS_SERVER_PORT} \
-e SIS_TEST_WEBDRIVER=${SIS_TEST_WEBDRIVER} \
-e SIS_SERVER_EXTRA_ARGS="${SIS_SERVER_EXTRA_ARGS}" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v ${SIS_TEST_DIR}:/test \
-v ${SIS_LOGS_DIR}:/logs \
${server_docker_image})
fi
if check_container ${dashboard_cid_file} ${SIS_DASHBOARD_PORT}; then
dashboard_up=0
echo "QATA Dashboard already running."
else
echo "Starting QATA Dashboard..."
get_image ${dashboard_docker_image}
local dashboard_cid
dashboard_cid=$(docker run \
--net=host \
-t \
-d \
-e SIS_SERVER_PORT=${SIS_SERVER_PORT} \
-e SIS_DASHBOARD_PORT=${SIS_DASHBOARD_PORT} \
-e SIS_DASHBOARD_EXTRA_ARGS="${SIS_DASHBOARD_EXTRA_ARGS}" \
${dashboard_docker_image})
fi
# Ensure server and dashboard have started up successfully, and save state
while [[ ${server_up} -ne 0 ]] || [[ ${dashboard_up} -ne 0 ]]; do
if [[ ${server_up} -ne 0 ]] && [[ $(netstat -tulnp | grep ${SIS_SERVER_PORT}) ]]; then
server_up=0
echo ${server_cid} > ${server_cid_file}
echo "QATA Server started on port ${SIS_SERVER_PORT}."
fi
if [[ ${dashboard_up} -ne 0 ]] && [[ $(netstat -tulnp | grep ${SIS_DASHBOARD_PORT}) ]]; then
dashboard_up=0
echo ${dashboard_cid} > ${dashboard_cid_file}
echo "QATA Dashboard started on port ${SIS_DASHBOARD_PORT}."
fi
done
}
stop() {
if [ ! -f ${server_cid_file} ]; then
echo "QATA Server already not running."
else
echo "Stopping QATA Server..."
stop_container ${server_cid_file}
echo "QATA Server stopped."
fi
if [ ! -f ${dashboard_cid_file} ]; then
echo "QATA Dashboard already not running."
else
echo "Stopping QATA Dashboard..."
stop_container ${dashboard_cid_file}
echo "QATA Dashboard stopped."
fi
}
attach_to_server() {
if [ ! -f ${server_cid_file} ]; then
echo "QATA Server not running. Not doing anything."
return 1
fi
local cid
cid=$(cat ${server_cid_file})
if ! [[ $(docker ps -a -q -f Id=${cid}) ]] || ! [[ $(netstat -tulnp | grep ${SIS_SERVER_PORT}) ]]; then
echo "QATA Server not running. Cleaning up."
stop
return 1
fi
docker attach --no-stdin ${cid}
}
case "$1" in
start)
start
;;
stop)
stop
;;
attach_to_server)
attach_to_server
;;
restart)
stop
start
;;
esac