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