4e8daa58c2e1c67141773b0883689b375c4be827
[csit.git] / bootstrap-vpp-verify-semiweekly.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 ght (c) 2016 Cisco and/or its affiliates.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not usecopy of the License at:
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 set -x
18
19 RETURN_STATUS=0
20
21 cat /etc/hostname
22 cat /etc/hosts
23
24 export DEBIAN_FRONTEND=noninteractive
25 sudo apt-get -y update
26 sudo apt-get -y install libpython2.7-dev python-virtualenv
27
28 PYBOT_ARGS="--noncritical MULTI_THREAD"
29
30 ARCHIVE_ARTIFACTS=(log.html output.xml report.html output_perf_data.xml)
31
32 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33 export PYTHONPATH=${SCRIPT_DIR}
34
35
36 # 1st step: Download and prepare VPP packages
37
38 # Temporarily download VPP packages from nexus.fd.io
39 rm -f *.deb
40 if [ "${#}" -ne "0" ]; then
41     arr=(${@})
42     echo ${arr[0]}
43 else
44     # Download the latest VPP build .deb install packages
45     echo Downloading VPP packages...
46     bash ${SCRIPT_DIR}/resources/tools/download_install_vpp_pkgs.sh --skip-install
47 fi
48
49 VPP_DEBS=(*.deb)
50 echo ${VPP_DEBS[@]}
51
52 VPP_VER=$(echo ${VPP_DEBS#vpp-})
53 VPP_VER=$(echo ${VPP_VER%.deb})
54 echo VPP version to be tested: ${VPP_VER}
55
56 set +x
57 echo "******************************************************************************"
58 echo "1st step: Download VPP packages                                       FINISHED"
59 echo "******************************************************************************"
60 set -x
61
62
63 # 2nd step: Start virtual env and install requirements
64
65 echo Starting virtual env...
66 virtualenv --system-site-packages env
67 . env/bin/activate
68
69 echo Installing requirements...
70 pip install -r ${SCRIPT_DIR}/requirements.txt
71
72 set +x
73 echo "******************************************************************************"
74 echo "2nd step: Start virtual env and install requirements                  FINISHED"
75 echo "******************************************************************************"
76 set -x
77
78
79 # 3rd step: Prepare VIRL system
80 echo Preparing VIRL system...
81
82 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
83 VIRL_SERVER=""
84
85 VIRL_USERNAME=jenkins-in
86 VIRL_PKEY=priv_key
87 VIRL_SERVER_STATUS_FILE="status"
88 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
89
90 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
91
92 function ssh_do() {
93     echo
94     echo "### "  ssh $@
95     ssh ${SSH_OPTIONS} $@
96 }
97
98 rm -f ${VIRL_PKEY}
99 cat > ${VIRL_PKEY} <<EOF
100 -----BEGIN RSA PRIVATE KEY-----
101 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
102 GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX
103 VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9
104 asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz
105 L3dM3iSmlmQlzv9bThjo+nI4KFYh6m5wrZmAo5r/4q9CIJc21HVnTqkGOWJIZz6J
106 73lePJVSq5gYqaoGw3swFEA/MDkOx7baWKSoLQIDAQABAoIBAQCNBeolNp+JWJ76
107 gQ4fwLsknyXSV6sxYyhkDW4PEwwcTU06uqce0AAzXVffxne0fMe48x47+zqBgPbb
108 4huM+P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Bp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
125 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
126 -----END RSA PRIVATE KEY-----
127 EOF
128 chmod 600 ${VIRL_PKEY}
129
130 #
131 # Pick a random host from the array of VIRL servers, and attempt
132 # to reach it and verify it's status.
133 #
134 # The server must be reachable, and have a "status" file with
135 # the content "PRODUCTION", to be selected.
136 #
137 # If the server is not reachable, or does not have the correct
138 # status, remove it from the array and start again.
139 #
140 # Abort if there are no more servers left in the array.
141 #
142 while [[ ! "$VIRL_SERVER" ]]
143 do
144     num_hosts=${#VIRL_SERVERS[@]}
145     if [ $num_hosts == 0 ]
146     then
147         echo "No more VIRL candidate hosts available, failing."
148         exit 127
149     fi
150     element=$[ $RANDOM % $num_hosts ]
151     virl_server_candidate=${VIRL_SERVERS[$element]}
152     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1)
153     echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\"
154     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
155     then
156         # Candidate is in good status. Select this server.
157         VIRL_SERVER="$virl_server_candidate"
158     else
159         # Candidate is in bad status. Remove from array.
160         VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}")
161     fi
162 done
163
164
165 VIRL_DIR_LOC="/tmp"
166 VPP_DEBS_VIRL=(${VPP_DEBS[@]})
167
168 # Prepend directory location at remote host to deb file list
169 for index in "${!VPP_DEBS_VIRL[@]}"; do
170     VPP_DEBS_VIRL[${index}]=${VIRL_DIR_LOC}/${VPP_DEBS_VIRL[${index}]}
171 done
172
173 echo "Updated file names: " ${VPP_DEBS_VIRL[@]}
174
175 cat ${VIRL_PKEY}
176 # Copy the files to VIRL host
177 scp ${SSH_OPTIONS} *.deb \
178     ${VIRL_USERNAME}@${VIRL_SERVER}:${VIRL_DIR_LOC}/
179
180 result=$?
181 if [ "${result}" -ne "0" ]; then
182     echo "Failed to copy vpp deb files to virl host"
183     echo ${result}
184     exit ${result}
185 fi
186
187 # Start a simulation on VIRL server
188 echo "Starting simulation on VIRL server"
189
190 function stop_virl_simulation {
191     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
192         "stop-testcase ${VIRL_SID}"
193 }
194
195 VIRL_SID=$(ssh ${SSH_OPTIONS} \
196     ${VIRL_USERNAME}@${VIRL_SERVER} \
197     "start-testcase -c double-ring-nested ${VPP_DEBS_VIRL[@]}")
198 retval=$?
199 if [ "$?" -ne "0" ]; then
200     echo "VIRL simulation start failed"
201     exit ${retval}
202 fi
203
204 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
205     echo "No VIRL session ID reported."
206     exit 127
207 fi
208
209 # Upon script exit, cleanup the VIRL simulation execution
210 trap stop_virl_simulation EXIT
211 echo ${VIRL_SID}
212
213 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
214
215 # Download the topology file from VIRL session
216 scp ${SSH_OPTIONS} \
217     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
218     topologies/enabled/topology_VIRL.yaml
219
220 retval=$?
221 if [ "$?" -ne "0" ]; then
222     echo "Failed to copy topology file from VIRL simulation"
223     exit ${retval}
224 fi
225
226 set +x
227 echo "******************************************************************************"
228 echo "3rd step: Start the simulation on the VIRL server                     FINISHED"
229 echo "******************************************************************************"
230 set -x
231
232
233 # 4th step: Run functional test suites
234
235 RC=0
236 MORE_FAILS=0
237
238 echo Running functional tests on the VIRL system...
239
240 # There are used three iterations of functional tests there
241 # to check the stability and reliability of the results.
242 for test_set in 1 2 3
243 do
244     echo
245     echo Functional test loop: ${test_set}
246     echo
247
248     pybot -L TRACE \
249         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology_VIRL.yaml \
250         --suite "tests.func" \
251         --include vm_envAND3_node_single_link_topo \
252         --include vm_envAND3_node_double_link_topo \
253         --exclude PERFTEST \
254         --noncritical EXPECTED_FAILING \
255         --output log_func_test_set${test_set} \
256         tests/
257     PARTIAL_RC=$(echo $?)
258     if [ ${PARTIAL_RC} -eq 250 ]; then
259         MORE_FAILS=1
260     fi
261     RC=$((RC+PARTIAL_RC))
262 done
263
264 set +x
265 echo "******************************************************************************"
266 echo "4th step: Run functional tests                                        FINISHED"
267 echo "******************************************************************************"
268 set -x
269
270
271 # 5th step: Reserve and prepare HW system
272
273 echo Making a reservation for the HW system...
274
275 # Space separated list of available testbeds, described by topology files
276 TOPOLOGIES="topologies/available/lf_testbed1-X710-X520.yaml \
277             topologies/available/lf_testbed2-X710-X520.yaml \
278             topologies/available/lf_testbed3-X710-X520.yaml"
279
280 # Reservation dir
281 RESERVATION_DIR="/tmp/reservation_dir"
282 INSTALLATION_DIR="/tmp/install_dir"
283
284 WORKING_TOPOLOGY=""
285
286 # We iterate over available topologies and wait until we reserve topology
287 while :; do
288     for TOPOLOGY in ${TOPOLOGIES};
289     do
290         python ${SCRIPT_DIR}/resources/tools/topo_reservation.py -t ${TOPOLOGY}
291         if [ $? -eq 0 ]; then
292             WORKING_TOPOLOGY=${TOPOLOGY}
293             echo "Reserved: ${WORKING_TOPOLOGY}"
294             break
295         fi
296     done
297
298     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
299         # Exit the infinite while loop if we made a reservation
300         break
301     fi
302
303     # Wait ~3minutes before next try
304     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
305     echo "Sleeping ${SLEEP_TIME}"
306     sleep ${SLEEP_TIME}
307 done
308
309 function cancel_all {
310     python ${SCRIPT_DIR}/resources/tools/topo_installation.py -c -d ${INSTALLATION_DIR} -t $1
311     python ${SCRIPT_DIR}/resources/tools/topo_reservation.py -c -t $1
312 }
313
314 # Upon script exit, cleanup the VIRL simulation execution
315 # and cancel the reservation and installation of HW system
316 # and delete all vpp packages.
317 trap "stop_virl_simulation; cancel_all ${WORKING_TOPOLOGY}" EXIT
318
319 python ${SCRIPT_DIR}/resources/tools/topo_installation.py -t ${WORKING_TOPOLOGY} \
320                                                        -d ${INSTALLATION_DIR} \
321                                                        -p ${VPP_DEBS[@]}
322
323 if [ $? -eq 0 ]; then
324     echo "VPP Installed on hosts from: ${WORKING_TOPOLOGY}"
325 else
326     echo "Failed to copy vpp deb files to DUTs"
327     exit 1
328 fi
329
330 set +x
331 echo "******************************************************************************"
332 echo "5th step: Making a reservation for HW system                          FINISHED"
333 echo "******************************************************************************"
334 set -x
335
336 # 6th step: Run performance tests
337
338 # Performance tests on HW system
339 echo Performance tests on HW system
340
341 pybot ${PYBOT_ARGS} \
342     -L TRACE \
343     -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
344     --suite "tests.perf" \
345     --include perftest_long \
346     --output log_perf_test_set \
347     tests/
348
349 PARTIAL_RC=$(echo $?)
350 if [ ${PARTIAL_RC} -eq 250 ]; then
351     MORE_FAILS=1
352 fi
353 RC=$((RC+PARTIAL_RC))
354
355 set +x
356 echo "******************************************************************************"
357 echo "6th step: Run performance tests                                       FINISHED"
358 echo "******************************************************************************"
359 set -x
360
361
362 # Set RETURN_STATUS=1 if some critical test failed
363 if [ ! ${RC} -eq 0 ]; then
364         RETURN_STATUS=1
365 fi
366
367 # Log the final result
368 if [ ${RC} -eq 0 ]; then
369     set +x
370     echo
371     echo "=============================================================================="
372     echo "Final result of all test loops:                                       | PASS |"
373     echo "All critical tests have passed."
374     echo "=============================================================================="
375     echo
376     set -x
377 elif [ ${MORE_FAILS} -eq 0 ]; then
378     if [ ${RC} -eq 1 ]; then
379         HLP_STR="test has"
380     else
381         HLP_STR="tests have"
382     fi
383     set +x
384     echo
385     echo "=============================================================================="
386     echo "Final result of all test loops:                                       | FAIL |"
387     echo "${RC} critical ${HLP_STR} failed."
388     echo "=============================================================================="
389     echo
390     set -x
391 else
392     set +x
393     echo
394     echo "=============================================================================="
395     echo "Final result of all test loops:                                       | FAIL |"
396     echo "More then 250 critical tests have failed in one test loop."
397     echo "=============================================================================="
398     echo
399     set -x
400 fi
401
402
403 # 7th step: Post-processing test data
404 echo Post-processing test data...
405
406 # Getting JSON perf data output
407 python ${SCRIPT_DIR}/resources/tools/robot_output_parser.py \
408        -i ${SCRIPT_DIR}/log_perf_test_set.xml \
409        -o ${SCRIPT_DIR}/output_perf_data.xml \
410        -v ${VPP_VER}
411 if [ ! $? -eq 0 ]; then
412     echo "Parsing ${SCRIPT_DIR}/log_perf_test_set.xml failed"
413 fi
414
415 # Rebot output post-processing
416 rebot --output output.xml ./log_func_test_set1.xml ./log_func_test_set2.xml \
417     ./log_func_test_set3.xml ./log_perf_test_set.xml
418
419 # Remove unnecessary files
420 rm -f ./log_test_set1.xml ./log_test_set2.xml ./log_test_set3.xml \
421     ./log_perf_test_set.xml
422
423 # Archive artifacts
424 mkdir archive
425 for i in ${ARCHIVE_ARTIFACTS[@]}; do
426     cp $( readlink -f ${i} | tr '\n' ' ' ) archive/
427 done
428
429 echo Post-processing finished.
430
431 exit ${RETURN_STATUS}