Report: data
[csit.git] / bootstrap.sh
1 #!/bin/bash
2 # Copyright (c) 2016 Cisco and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 set -x
16
17 cat /etc/hostname
18 cat /etc/hosts
19
20 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
21 export PYTHONPATH=${SCRIPT_DIR}
22
23 if [ -f "/etc/redhat-release" ]; then
24     DISTRO="CENTOS"
25     sudo yum install -y python-devel python-virtualenv
26     VPP_ARTIFACTS="vpp vpp-devel vpp-lib vpp-plugins"
27     DPDK_ARTIFACTS=""
28     PACKAGE="rpm"
29     VPP_CLASSIFIER=""
30     DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER).x86_64
31     VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_CENTOS)
32     VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_CENTOS)
33     VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_CENTOS)
34     VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_CENTOS)
35     SHARED_MEMORY_PATH="/dev/shm"
36 else
37     DISTRO="UBUNTU"
38     export DEBIAN_FRONTEND=noninteractive
39     sudo apt-get -y update
40     sudo apt-get -y install libpython2.7-dev python-virtualenv
41     VPP_ARTIFACTS="vpp vpp-dbg vpp-dev vpp-lib vpp-plugins"
42     DPDK_ARTIFACTS="vpp-dpdk-dkms"
43     PACKAGE="deb"
44     VPP_CLASSIFIER="-deb"
45     DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)_amd64
46     VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_UBUNTU)
47     VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_UBUNTU)
48     VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_UBUNTU)
49     VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_UBUNTU)
50     SHARED_MEMORY_PATH="/run/shm"
51 fi
52
53 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
54 IPS_PER_VIRL=( "10.30.51.28:252"
55                "10.30.51.29:74"
56                "10.30.51.30:74" )
57 SIMS_PER_VIRL=( "10.30.51.28:13"
58                "10.30.51.29:13"
59                "10.30.51.30:13" )
60 IPS_PER_SIMULATION=5
61
62 function get_max_ip_nr() {
63     virl_server=$1
64     IP_VALUE="0"
65     for item in "${IPS_PER_VIRL[@]}" ; do
66         if [ "${item%%:*}" == "${virl_server}" ]
67         then
68             IP_VALUE=${item#*:}
69             break
70         fi
71     done
72     echo "$IP_VALUE"
73 }
74
75 function get_max_sim_nr() {
76     virl_server=$1
77     SIM_VALUE="0"
78     for item in "${SIMS_PER_VIRL[@]}" ; do
79         if [ "${item%%:*}" == "${virl_server}" ]
80         then
81             SIM_VALUE=${item#*:}
82             break
83         fi
84     done
85     echo "$SIM_VALUE"
86 }
87
88 VIRL_USERNAME=jenkins-in
89 VIRL_PKEY=priv_key
90 VIRL_SERVER_STATUS_FILE="status"
91 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
92
93 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
94
95 TEST_GROUPS=("crypto,ip4_tunnels.softwire,ip4_tunnels.vxlan,telemetry" "ip4,ip4_tunnels.gre,ip4_tunnels.lisp,ip6_tunnels.vxlan,vm_vhost.ip4,vm_vhost.ip6" "interfaces,ip6,ip6_tunnels.lisp,l2bd,l2xc,vm_vhost.l2bd,vm_vhost.l2xc")
96 SUITE_PATH="tests.vpp.func"
97 SKIP_PATCH="SKIP_PATCH"
98
99 # Create tmp dir
100 mkdir ${SCRIPT_DIR}/tmp
101
102 # Use tmp dir to store log files
103 LOG_PATH="${SCRIPT_DIR}/tmp"
104
105 # Use tmp dir for tarballs
106 export TMPDIR="${SCRIPT_DIR}/tmp"
107
108 function ssh_do() {
109     echo
110     echo "### "  ssh $@
111     ssh ${SSH_OPTIONS} $@
112 }
113
114 rm -f ${VIRL_PKEY}
115 cat > ${VIRL_PKEY} <<EOF
116 -----BEGIN RSA PRIVATE KEY-----
117 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
118 GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX
119 VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9
120 asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz
121 L3dM3iSmlmQlzv9bThjo+nI4KFYh6m5wrZmAo5r/4q9CIJc21HVnTqkGOWJIZz6J
122 73lePJVSq5gYqaoGw3swFEA/MDkOx7baWKSoLQIDAQABAoIBAQCNBeolNp+JWJ76
123 gQ4fwLsknyXSV6sxYyhkDW4PEwwcTU06uqce0AAzXVffxne0fMe48x47+zqBgPbb
124 4huM+Pu8B9nfojUMr5TaYtl9Zbgpk3F8H7dT7LKOa6XrxvZTZrADSRc30+Z26zPN
125 e9zTaf42Gvt0/l0Zs1BHwbaOXqO+XuwJ3/F9Sf3PQYWXD3EOWjpHDP/X/1vAs6lV
126 SLkm6J/9KKE1m6I6LTYjIXuYt4SXybW6N2TSy54hhQtYcDUnIU2hR/PHVWKrGA0J
127 kELgrtTNTdbML27O5gFWU4PLUEYTZ9fN11D6qUZKxLcPOiPPHXkiILMRCCnG5DYI
128 ksBAU/YlAoGBAPxZO9VO18TYc8THV1nLKcvT2+1oSs1UcA2wNQMU55t910ZYinRa
129 MRwUhMOf8Mv5wOeiZaRICQB1PnVWtDVmGECgPpK6jUxqAwn8rgJcnoafLGL5YKMY
130 RVafTe6N5LXgCaOcJrk21wxs6v7ninEbUxxc575urOvZMBkymDw91dwbAoGBAPwa
131 YRhKhrzFKZzdK0RadVjnxKvolUllpoqqg3XuvmeAJHAOAnaOgVWq68NAcp5FZJv0
132 2D2Up7TX8pjf9MofP1SJbcraKBpK4NzfNkA0dSdEi+FhVofAJ9umB2o5LW1n7sab
133 UIrjsdzSJK/9Zb9yTTHPyibYzNEgaJV1HsbxfEFXAoGAYO2RmvRm0phll18OQVJV
134 IpKk9kLKAKZ/R/K32hAsikBC8SVPQTPniyaifFWx81diblalff2hX4ipTf7Yx24I
135 wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS
136 NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
137 xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
138 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
139 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
140 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
141 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
142 -----END RSA PRIVATE KEY-----
143 EOF
144 chmod 600 ${VIRL_PKEY}
145
146 #
147 # The server must be reachable and have a "status" file with
148 # the content "PRODUCTION" to be selected.
149 #
150 # If the server is not reachable or does not have the correct
151 # status remove it from the array and start again.
152 #
153 # Abort if there are no more servers left in the array.
154 #
155 VIRL_PROD_SERVERS=()
156 for index in "${!VIRL_SERVERS[@]}"; do
157     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVERS[$index]} cat $VIRL_SERVER_STATUS_FILE 2>&1)
158     echo VIRL HOST ${VIRL_SERVERS[$index]} status is \"$virl_server_status\"
159     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
160     then
161         # Candidate is in good status. Add to array.
162         VIRL_PROD_SERVERS+=(${VIRL_SERVERS[$index]})
163     fi
164 done
165
166 VIRL_SERVERS=("${VIRL_PROD_SERVERS[@]}")
167 echo "VIRL servers in production: ${VIRL_SERVERS[@]}"
168 num_hosts=${#VIRL_SERVERS[@]}
169 if [ $num_hosts == 0 ]
170 then
171     echo "No more VIRL candidate hosts available, failing."
172     exit 127
173 fi
174
175 # Get the LOAD of each server based on number of active simulations (testcases)
176 VIRL_SERVER_LOAD=()
177 for index in "${!VIRL_SERVERS[@]}"; do
178     VIRL_SERVER_LOAD[${index}]=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVERS[$index]} "list-testcases | grep session | wc -l")
179 done
180
181 # Pick for each TEST_GROUP least loaded server
182 VIRL_SERVER=()
183 for index in "${!TEST_GROUPS[@]}"; do
184     least_load_server_idx=$(echo "${VIRL_SERVER_LOAD[*]}" | tr -s ' ' '\n' | awk '{print($0" "NR)}' | sort -g -k1,1 | head -1 | cut -f2 -d' ')
185     least_load_server=${VIRL_SERVERS[$least_load_server_idx-1]}
186     VIRL_SERVER+=($least_load_server)
187     # Adjusting load as we are not going run simulation immediately
188     VIRL_SERVER_LOAD[$least_load_server_idx-1]=$((VIRL_SERVER_LOAD[$least_load_server_idx-1]+1))
189 done
190
191 echo "Selected VIRL servers: ${VIRL_SERVER[@]}"
192
193 # Temporarily download VPP and DPDK packages from nexus.fd.io
194 if [ "${#}" -ne "0" ]; then
195     arr=(${@})
196     echo ${arr[0]}
197     SKIP_PATCH="skip_patchORskip_vpp_patch"
198 else
199     rm -f *.${PACKAGE}
200     for ARTIFACT in ${DPDK_ARTIFACTS}; do
201         wget -q "${VPP_REPO_URL}/${ARTIFACT}/${DPDK_STABLE_VER}/${ARTIFACT}-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.${PACKAGE}" || exit
202     done
203     for ARTIFACT in ${VPP_ARTIFACTS}; do
204         wget -q "${VPP_REPO_URL}/${ARTIFACT}/${VPP_STABLE_VER}/${ARTIFACT}-${VPP_STABLE_VER}${VPP_CLASSIFIER}.${PACKAGE}" || exit
205     done
206 fi
207
208 VPP_PKGS=(*.$PACKAGE)
209 echo ${VPP_PKGS[@]}
210 VIRL_DIR_LOC="/tmp"
211 VPP_PKGS_FULL=(${VPP_PKGS[@]})
212
213 # Prepend directory location at remote host to package file list
214 for index in "${!VPP_PKGS_FULL[@]}"; do
215     VPP_PKGS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_PKGS_FULL[${index}]}
216 done
217
218 echo "Updated file names: " ${VPP_PKGS_FULL[@]}
219
220 cat ${VIRL_PKEY}
221
222 # Copy the files to VIRL hosts
223 DONE=""
224 for index in "${!VIRL_SERVER[@]}"; do
225     # Do not copy files in case they have already been copied to the VIRL host
226     [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1
227
228     if [ "${copy}" -eq "0" ]; then
229         echo "VPP packages have already been copied to the VIRL host ${VIRL_SERVER[${index}]}"
230     else
231         scp ${SSH_OPTIONS} *.${PACKAGE} \
232         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
233
234         result=$?
235         if [ "${result}" -ne "0" ]; then
236             echo "Failed to copy VPP packages to VIRL host ${VIRL_SERVER[${index}]}"
237             echo ${result}
238             exit ${result}
239         else
240             echo "VPP packages successfully copied to the VIRL host ${VIRL_SERVER[${index}]}"
241         fi
242         DONE+=(${VIRL_SERVER[${index}]})
243     fi
244 done
245
246 # Start a simulation on VIRL server
247
248 function stop_virl_simulation {
249     for index in "${!VIRL_SERVER[@]}"; do
250         ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\
251             "stop-testcase ${VIRL_SID[${index}]}"
252     done
253 }
254
255 # Upon script exit, cleanup the simulation execution
256 trap stop_virl_simulation EXIT
257
258 for index in "${!VIRL_SERVER[@]}"; do
259     echo "Starting simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}"
260     # Get given VIRL server limits for max. number of VMs and IPs
261     max_ips=$(get_max_ip_nr ${VIRL_SERVER[${index}]})
262     max_ips_from_sims=$(($(get_max_sim_nr ${VIRL_SERVER[${index}]})*IPS_PER_SIMULATION))
263     # Set quota to lower value
264     IP_QUOTA=$([ $max_ips -le $max_ips_from_sims ] && echo "$max_ips" || echo "$max_ips_from_sims")
265     # Start the simulation
266     VIRL_SID[${index}]=$(ssh ${SSH_OPTIONS} \
267         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]} \
268         "start-testcase -vv --quota ${IP_QUOTA} --copy ${VIRL_TOPOLOGY} \
269         --release ${VIRL_RELEASE} ${VPP_PKGS_FULL[@]}")
270     retval=$?
271     if [ ${retval} -ne "0" ]; then
272         echo "VIRL simulation start failed on ${VIRL_SERVER[${index}]}"
273         exit ${retval}
274     fi
275     if [[ ! "${VIRL_SID[${index}]}" =~ session-[a-zA-Z0-9_]{6} ]]; then
276         echo "No VIRL session ID reported."
277         exit 127
278     fi
279     echo "VIRL simulation nr. ${index} started on ${VIRL_SERVER[${index}]}"
280
281     ssh_do ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\
282      cat /scratch/${VIRL_SID[${index}]}/topology.yaml
283
284     # Download the topology file from VIRL session and rename it
285     scp ${SSH_OPTIONS} \
286         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:/scratch/${VIRL_SID[${index}]}/topology.yaml \
287         topologies/enabled/topology${index}.yaml
288
289     retval=$?
290     if [ ${retval} -ne "0" ]; then
291         echo "Failed to copy topology file from VIRL simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}"
292         exit ${retval}
293     fi
294 done
295
296 echo ${VIRL_SID[@]}
297
298 virtualenv --system-site-packages env
299 . env/bin/activate
300
301 echo pip install
302 pip install -r ${SCRIPT_DIR}/requirements.txt
303
304 for index in "${!VIRL_SERVER[@]}"; do
305     pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
306               -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
307               -d ${SCRIPT_DIR}/topologies/enabled/topology${index}.yaml \
308               -vvv
309     if [ "$?" -ne "0" ]; then
310         echo "Topology${index} schema validation failed."
311         echo "However, the tests will start."
312     fi
313 done
314
315 function run_test_set() {
316     set +x
317     OLDIFS=$IFS
318     IFS=","
319     nr=$(echo $1)
320     rm -f ${LOG_PATH}/test_run${nr}.log
321     exec &> >(while read line; do echo "$(date +'%H:%M:%S') $line" \
322      >> ${LOG_PATH}/test_run${nr}.log; done;)
323     suite_str=""
324     for suite in ${TEST_GROUPS[${nr}]}; do
325         suite_str="${suite_str} --suite ${SUITE_PATH}.${suite}"
326     done
327     IFS=$OLDIFS
328
329     echo "PYTHONPATH=`pwd` pybot -L TRACE -W 136\
330         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \
331         ${suite_str} \
332         --include vm_envAND3_node_single_link_topo \
333         --include vm_envAND3_node_double_link_topo \
334         --exclude PERFTEST \
335         --exclude ${SKIP_PATCH} \
336         --noncritical EXPECTED_FAILING \
337         --output ${LOG_PATH}/log_test_set_run${nr} \
338         tests/"
339
340     PYTHONPATH=`pwd` pybot -L TRACE -W 136\
341         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \
342         ${suite_str} \
343         --include vm_envAND3_node_single_link_topo \
344         --include vm_envAND3_node_double_link_topo \
345         --exclude PERFTEST \
346         --exclude ${SKIP_PATCH} \
347         --noncritical EXPECTED_FAILING \
348         --output ${LOG_PATH}/log_test_set_run${nr} \
349         tests/
350
351     local_run_rc=$?
352     echo ${local_run_rc} > ${SHARED_MEMORY_PATH}/rc_test_run${nr}
353     set -x
354 }
355
356 set +x
357 # Send to background an instance of the run_test_set() function for each number,
358 # record the pid.
359 for index in "${!VIRL_SERVER[@]}"; do
360     run_test_set ${index} &
361     pid=$!
362     echo "Sent to background: Test_set${index} (pid=$pid)"
363     pids[$pid]=$index
364 done
365
366 echo
367 echo -n "Waiting..."
368
369 # Watch the stable of background processes.
370 # If a pid goes away, remove it from the array.
371 while [ -n "${pids[*]}" ]; do
372     for i in $(seq 0 9); do
373         sleep 1
374         echo -n "."
375     done
376     for pid in "${!pids[@]}"; do
377         if ! ps "$pid" >/dev/null; then
378             echo -e "\n"
379             echo "Test_set${pids[$pid]} with PID $pid finished."
380             unset pids[$pid]
381         fi
382     done
383     if [ -z "${!pids[*]}" ]; then
384         break
385     fi
386     echo -n -e "\nStill waiting for test set(s): ${pids[*]} ..."
387 done
388
389 echo
390 echo "All test set runs finished."
391 echo
392
393 set -x
394
395 RC=0
396 for index in "${!VIRL_SERVER[@]}"; do
397     echo "Test_set${index} log:"
398     cat ${LOG_PATH}/test_run${index}.log
399     RC_PARTIAL_RUN=$(cat ${SHARED_MEMORY_PATH}/rc_test_run${index})
400     RC=$((RC+RC_PARTIAL_RUN))
401     rm -f ${SHARED_MEMORY_PATH}/rc_test_run${index}
402     rm -f ${LOG_PATH}/test_run${index}.log
403     echo
404 done
405
406 # Log the final result
407 if [ "${RC}" -eq "0" ]; then
408     set +x
409     echo
410     echo "========================================================================================================================================"
411     echo "Final result of all test loops:                                                                                                 | PASS |"
412     echo "All critical tests have passed."
413     echo "========================================================================================================================================"
414     echo
415     set -x
416 else
417     if [ "${RC}" -eq "1" ]; then
418         HLP_STR="test has"
419     else
420         HLP_STR="tests have"
421     fi
422     set +x
423     echo
424     echo "========================================================================================================================================"
425     echo "Final result of all test loops:                                                                                                 | FAIL |"
426     echo "${RC} critical ${HLP_STR} failed."
427     echo "========================================================================================================================================"
428     echo
429     set -x
430 fi
431
432 echo Post-processing test data...
433
434 partial_logs=""
435 for index in "${!VIRL_SERVER[@]}"; do
436     partial_logs="${partial_logs} ${LOG_PATH}/log_test_set_run${index}.xml"
437 done
438
439 # Rebot output post-processing
440 rebot --noncritical EXPECTED_FAILING \
441       --output output.xml ${partial_logs}
442
443 # Remove unnecessary log files
444 rm -f ${partial_logs}
445
446 echo Post-processing finished.
447
448 if [ ${RC} -eq 0 ]; then
449     RETURN_STATUS=0
450 else
451     RETURN_STATUS=1
452 fi
453
454 exit ${RETURN_STATUS}

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.