-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-tests
executable file
·248 lines (220 loc) · 6.84 KB
/
run-tests
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
#!/bin/bash
set -e
function print_usage() {
echo "$(basename $0)"
echo ""
echo "usage:"
echo ""
echo "$(basename $0) [options]"
echo ""
echo "Options:"
echo " -h print this help text"
echo " -d enable ansible debug (-vvv)"
echo " -i [basename],[numnodes] generate/update inventory file"
echo " -s skip host update/upgrade and reboot"
echo " -w wipe all src/build dirs and start fresh"
echo " -l [src options see below] libqb"
echo " -k [src options see below] kronosnet"
echo " -c [src options see below] corosync"
echo " Source options: (default git, github repos, master branch)"
echo " git[,repo[,branch]] use git. Optionally provide an alternative repo and branch"
echo " brach accepts the same values as defined by:"
echo " http://docs.ansible.com/ansible/git_module.html version option"
echo " with force = yes"
echo " local,path path to the code. Code must be initializied"
echo " and directory should already contain ./configure"
echo " system install system provided rpms"
echo " skip do nothing. code is installed already. don't touch it"
echo " -z [compiler] specify compiler to use (default: gcc). CI will install both gcc and clang by default"
echo " -a [prj,confi opts]:[prj.. add extra configure options."
echo " prj: libqb kronosnet corosync"
echo " configure opts are passed pristine to './configure \$conf_opts"
echo " example: -a corosync,\"--enable-debug --enable-foo\":kronosnet,\"--enable-kronosnetd --enable-debug\""
echo " note: shell escaping is important to identify options"
echo " -b [prj,build opts]:[prj.. add extra build options."
echo " prj: libqb kronosnet corosync"
echo " build opts are passed pristine to 'make \$build_opts all install'"
echo " note: shell escaping is important to identify options"
echo " -e [networks],... list of networks to use for testing (max 8)"
echo " -e 192.168.1.0/24,192.168.3.0/24,172.16.1.0/16"
echo " udpu will only use the first network. knet will use all"
echo " -p path_to_testresults location where to store test results."
echo " Default: \$PWD/testresults/\$(date +%Y%m%d-%H%M%S)/"
echo " -t [testlist] comma separated list of tests to skip. Default: none"
echo " Example: -t kronosnet (will only run corosync tests)"
echo " -t corosync (will only run kronosnet tests)"
echo " -t kronosnet,corosync (will skip both tests)"
}
function generate_ansible_cfg {
echo "[defaults]" > ansible.cfg
echo "callback_plugins = plugins/" >> ansible.cfg
echo "inventory = ansible-inventory" >> ansible.cfg
echo "forks = 70" >> ansible.cfg
echo "generated ansible config:"
echo "========================="
cat ansible.cfg
echo "========================="
echo ""
}
function generate_inventory_file() {
echo "[test-nodes]" > ansible-inventory
echo "$knethosts" | sed -e 's/,/[1:/g' -e 's/$/]/g' >> ansible-inventory
echo "generated ansible inventory:"
echo "============================"
cat ansible-inventory
echo "============================"
echo ""
}
function parse_src_opts {
project="$1"
shift
args="$@"
src="$(echo $args | awk -F ',' '{print $1}')"
case "$src" in
system)
extravars="${project}src=system $extravars"
;;
skip)
extravars="skip$project=yes $extravars"
;;
git)
extravars="${project}src=git $extravars"
repo="$(echo $args | awk -F ',' '{print $2}')"
if [ -n "$repo" ]; then
extravars="${project}gitrepo=$repo $extravars"
version="$(echo $args | awk -F ',' '{print $3}')"
if [ -n "$version" ]; then
extravars="${project}gitver=$version $extravars"
fi
fi
;;
local)
extravars="${project}src=local $extravars"
localpath="$(echo $args | awk -F ',' '{print $2}')"
if [ -z "$localpath" ]; then
echo "Error: $project local option requires a path to the src code"
exit 1
fi
extravars="${project}localpath=$localpath $extravars"
;;
*)
echo "Unknown $src option for $project"
exit 1
;;
esac
return 0
}
function parse_build_opts {
target=$1
shift
bopts=$@
while [ -n "$bopts" ]; do
curopt="$(echo "$bopts" | awk -F ":" '{print $1}')"
project="$(echo "$curopt" | awk -F ',' '{print $1}')"
opts="$(echo "$curopt" | awk -F ',' '{print $2}')"
extravars="${project}${target}opt=\"${opts}\" $extravars"
if echo "$bopts" | grep -q ":"; then
bopts="$(echo "$bopts" | sed -e 's/.*://')"
else
bopts=""
fi
done
return 0
}
function parse_test_opts {
opts="$(echo $1 | sed -e 's/,/ /g')"
for i in $opts; do
extravars="skip${i}tests=yes $extravars"
done
}
# parse command line options
testresdir="$PWD/testresults"
extravars=""
hasnetworks=0
while getopts "hdi:swl:k:c:a:b:e:p:t:z:" optflag; do
case "$optflag" in
d)
ansibledebug="-vvv"
;;
i)
knethosts="$OPTARG"
;;
s)
extravars="skipupdate=yes $extravars"
;;
w)
extravars="wipecode=yes $extravars"
;;
l)
parse_src_opts libqb "$OPTARG"
;;
k)
parse_src_opts kronosnet "$OPTARG"
;;
c)
parse_src_opts corosync "$OPTARG"
;;
a)
parse_build_opts conf "$OPTARG"
;;
b)
parse_build_opts build "$OPTARG"
;;
e)
extravars="networks=$OPTARG $extravars"
hasnetworks=1
;;
p)
testresdir="$OPTARG"
;;
t)
parse_test_opts "$OPTARG"
;;
z)
extravars="compiler=$OPTARG $extravars"
;;
h)
print_usage
exit 0
;;
\?|:)
print_usage
exit 1
;;
esac
done
if ! which ansible >/dev/null 2>&1; then
echo "ERROR: missing ansible binary from PATH"
exit 1
fi
if ! which ansible-playbook >/dev/null 2>&1; then
echo "ERROR: missing ansible-playbook binary from PATH"
exit 1
fi
# automatic update ansible-config
if [ -f ansible.cfg.manual ]; then
cp ansible.cfg.manual ansible.cfg
else
generate_ansible_cfg
fi
# generate and check ansible inventory file
if [ -n "$knethosts" ]; then
generate_inventory_file
fi
if [ ! -f ansible-inventory ]; then
echo "ERROR: missing ansible-inventory file"
exit 1
fi
if [ "$hasnetworks" = "0" ]; then
echo "ERROR: -e must be specified"
exit 1
fi
echo "Checking connectivity to nodes"
echo ""
ansible all -f 500 -m ping || exit 1
echo ""
testresdir="${testresdir}/$(date +%Y%m%d-%H%M%S)"
mkdir -p "${testresdir}/corosync"
mkdir -p "${testresdir}/kronosnet"
ansible-playbook ${ansibledebug} site.yml --extra-vars "$extravars testresdir=\"${testresdir}\""
exit 0