ci: Plot graphs from CI results
[vswitchperf.git] / ci / build-vsperf.sh
1 #!/bin/bash
2 #
3 # Copyright 2015-2017 Intel Corporation.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy 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 # VSPERF nightly build execution script
18
19 # Usage:
20 #       build-vsperf.sh job_type
21 #   where job_type is one of "verify", "merge", "daily"
22
23 #
24 # exit codes
25 #
26
27 EXIT=0
28 EXIT_TC_FAILED=1
29 EXIT_SANITY_TC_FAILED=2
30 EXIT_PYLINT_FAILED=4
31 EXIT_NO_RESULTS=128
32 EXIT_NO_TEST_REPORT_LOG_DIR=256
33
34 #
35 # configuration
36 #
37
38 VSPERF_BIN='./vsperf'
39 LOG_FILE_PREFIX="/tmp/vsperf_build"
40 DATE=$(date -u +"%Y-%m-%d_%H-%M-%S")
41 BRANCH=${GIT_BRANCH##*/}
42 VSPERFENV_DIR="$HOME/vsperfenv"
43 RESULTS_ARCHIVE="$HOME/ci_results_archive"
44
45 # CI job specific configuration
46 # VERIFY - run basic set of TCs with default settings
47 TESTCASES_VERIFY="vswitch_add_del_bridge vswitch_add_del_bridges vswitch_add_del_vport vswitch_add_del_vports vswitch_vports_add_del_flow"
48 TESTPARAM_VERIFY="--integration"
49 TESTCASES_VERIFY_VPP="vswitch_add_del_bridge vswitch_add_del_bridges vswitch_add_del_vport vswitch_add_del_vports vswitch_vports_add_del_connection_vpp"
50 TESTPARAM_VERIFY_VPP=$TESTPARAM_VERIFY
51 # MERGE - run selected TCs with default settings
52 TESTCASES_MERGE=$TESTCASES_VERIFY
53 TESTPARAM_MERGE=$TESTPARAM_VERIFY
54 TESTCASES_MERGE_VPP=$TESTCASES_VERIFY_VPP
55 TESTPARAM_MERGE_VPP=$TESTPARAM_VERIFY_VPP
56 # DAILY - run selected TCs for defined packet sizes
57 TESTCASES_DAILY='phy2phy_tput back2back phy2phy_tput_mod_vlan phy2phy_scalability pvp_tput pvp_back2back pvvp_tput pvvp_back2back'
58 TESTCASES_DAILY_VPP='phy2phy_tput_vpp phy2phy_back2back_vpp pvp_tput_vpp pvp_back2back_vpp pvvp_tput_vpp pvvp_back2back_vpp'
59 TESTPARAM_DAILY='--test-params TRAFFICGEN_PKT_SIZES=(64,128,512,1024,1518)'
60 TESTPARAM_DAILY_VPP=$TESTPARAM_DAILY
61 TESTCASES_SRIOV='pvp_tput'
62 TESTPARAM_SRIOV='--test-params TRAFFICGEN_PKT_SIZES=(64,128,512,1024,1518)'
63 # check if user config file exists if not then we will use default settings
64 if [ -f $HOME/vsperf-${BRANCH}.conf ] ; then
65     # branch specific config was found
66     CONF_FILE="--conf-file ${HOME}/vsperf-${BRANCH}.conf"
67 else
68     if [ -f $HOME/vsperf.conf ] ; then
69         CONF_FILE="--conf-file ${HOME}/vsperf.conf"
70     else
71         CONF_FILE=""
72     fi
73 fi
74 # check if sriov specific config file exists if not then use default configuration
75 if [ -f $HOME/vsperf-${BRANCH}.conf.sriov ] ; then
76     CONF_FILE_SRIOV="${CONF_FILE}.sriov"
77 else
78     CONF_FILE_SRIOV=$CONF_FILE
79 fi
80
81 # Test report related configuration
82 TEST_REPORT_PARTIAL="*_test_report.rst"
83 TEST_REPORT_DIR="${WORKSPACE}/docs/results"
84 TEST_REPORT_INDEX="${TEST_REPORT_DIR}/index.rst"
85 TEST_REPORT_LINK_OLD="https://wiki.opnfv.org/wiki/vsperf_results"
86 TEST_REPORT_FILE="${WORKSPACE}/docs_output/results/index.html"
87 TEST_REPORT_TARBALL="vswitchperf_logs_${DATE}.tar.gz"
88
89 if [[ "x${BRANCH}" == "xmaster" ]]; then
90     TEST_REPORT_LINK_NEW="https://artifacts.opnfv.org/logs/$PROJECT/$NODE_NAME/$DATE/${TEST_REPORT_TARBALL}"
91 else
92     TEST_REPORT_LINK_NEW="https://artifacts.opnfv.org/logs/$PROJECT/$NODE_NAME/$BRANCH/$DATE/${TEST_REPORT_TARBALL}"
93 fi
94
95 TEST_REPORT_LOG_DIR="${HOME}/opnfv/$PROJECT/results/$BRANCH"
96
97 #
98 # functions
99 #
100
101 # terminate vsperf and all its utilities
102 # it is expected that vsperf is the only python3 app
103 # and no other ovs or qemu instances are running
104 # at CI machine
105 # parameters:
106 #   none
107 function terminate_vsperf() {
108     sudo pkill stress &> /dev/null
109     sudo pkill python3 &> /dev/null
110     sudo killall -9 qemu-system-x86_64 &> /dev/null
111
112     # sometimes qemu resists to terminate, so wait a bit and kill it again
113     if pgrep qemu-system-x86_64 &> /dev/null ; then
114         sleep 5
115         sudo killall -9 qemu-system-x86_64 &> /dev/null
116         sleep 5
117     fi
118
119     sudo pkill ovs-vswitchd &> /dev/null
120     sleep 1
121     sudo pkill ovsdb-server &> /dev/null
122     sleep 1
123 }
124
125 # check and print testcase execution status
126 # parameters:
127 #   $1 - directory with results
128 function print_results() {
129     for i in $TESTCASES ; do
130         RES_FILE=`ls -1 $1 | egrep "result_${i}_[0-9a-zA-Z\-]+.csv"`
131
132         if [ "x$RES_FILE" != "x" -a -e "${1}/${RES_FILE}" ]; then
133             if grep ^FAILED "${1}/${RES_FILE}" &> /dev/null ; then
134                 printf "    %-70s %-6s\n" "result_${i}" "FAILED"
135                 EXIT=$EXIT_TC_FAILED
136             else
137                 printf "    %-70s %-6s\n" "result_${i}" "OK"
138             fi
139         else
140             printf "    %-70s %-6s\n" "result_${i}" "FAILED"
141             EXIT=$EXIT_TC_FAILED
142         fi
143     done
144 }
145
146 # execute tests and display results
147 # parameters:
148 #   $1 - vswitch and vnf combination, one of OVS_vanilla, OVS_with_DPDK_and_vHost_User
149 #   $2 - CI job type, one of verify, merge, daily
150 function execute_vsperf() {
151     OPNFVPOD=""
152     # figure out list of TCs and execution parameters
153     case $2 in
154         "verify")
155             if [ "$1" == "VPP" ] ; then
156                 TESTPARAM=$TESTPARAM_VERIFY_VPP
157                 TESTCASES=$TESTCASES_VERIFY_VPP
158             else
159                 TESTPARAM=$TESTPARAM_VERIFY
160                 TESTCASES=$TESTCASES_VERIFY
161             fi
162             ;;
163         "merge")
164             if [ "$1" == "VPP" ] ; then
165                 TESTPARAM=$TESTPARAM_MERGE_VPP
166                 TESTCASES=$TESTCASES_MERGE_VPP
167             else
168                 TESTPARAM=$TESTPARAM_MERGE
169                 TESTCASES=$TESTCASES_MERGE
170             fi
171             ;;
172         *)
173             # by default use daily build and upload results to the OPNFV databse
174             if [ "$1" == "VPP" ] ; then
175                 TESTPARAM=$TESTPARAM_DAILY_VPP
176                 TESTCASES=$TESTCASES_DAILY_VPP
177                 # don't report VPP results into testresults DB, until TC name mapping
178                 # for VPP tests will be defined
179                 #OPNFVPOD="--opnfvpod=$NODE_NAME"
180             else
181                 TESTPARAM=$TESTPARAM_DAILY
182                 TESTCASES=$TESTCASES_DAILY
183                 OPNFVPOD="--opnfvpod=$NODE_NAME"
184             fi
185             ;;
186     esac
187
188     # execute testcases
189     echo -e "\nExecution of VSPERF for $1"
190
191     DATE_SUFFIX=$(date -u +"%Y-%m-%d_%H-%M-%S")
192
193     case $1 in
194         "SRIOV")
195             # use SRIOV specific TCs and configuration
196             TESTPARAM=$TESTPARAM_SRIOV
197             TESTCASES=$TESTCASES_SRIOV
198             # figure out log file name
199             LOG_SUBDIR="SRIOV"
200             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
201
202             echo "    $VSPERF_BIN --vswitch none --vnf QemuPciPassthrough $CONF_FILE_SRIOV $TESTPARAM $TESTCASES &> $LOG_FILE"
203             $VSPERF_BIN --vswitch none --vnf QemuPciPassthrough $CONF_FILE_SRIOV $TESTPARAM $TESTCASES &> $LOG_FILE
204             ;;
205         "VPP")
206             # figure out log file name
207             LOG_SUBDIR="VppDpdkVhost"
208             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
209
210             hugepages_info > $LOG_FILE
211             echo "    $VSPERF_BIN $OPNFVPOD --vswitch VppDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES > $LOG_FILE"
212             $VSPERF_BIN $OPNFVPOD --vswitch VppDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES &>> $LOG_FILE
213             hugepages_info >> $LOG_FILE
214             ;;
215         "OVS_vanilla")
216             # figure out log file name
217             LOG_SUBDIR="OvsVanilla"
218             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
219
220             echo "    $VSPERF_BIN $OPNFVPOD --vswitch OvsVanilla --vnf QemuVirtioNet $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE"
221             $VSPERF_BIN $OPNFVPOD --vswitch OvsVanilla --vnf QemuVirtioNet $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE
222             ;;
223         *)
224             # figure out log file name
225             LOG_SUBDIR="OvsDpdkVhost"
226             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
227
228             hugepages_info > $LOG_FILE
229             echo "    $VSPERF_BIN $OPNFVPOD --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES > $LOG_FILE"
230             $VSPERF_BIN $OPNFVPOD --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES &>> $LOG_FILE
231             hugepages_info >> $LOG_FILE
232             ;;
233     esac
234
235     # evaluation of results
236     echo -e "\nResults for $1"
237     RES_DIR="/$(grep "Creating result directory" $LOG_FILE | cut -d'/' -f2-)"
238     if [[ "/" == "${RES_DIR}" ]] ; then
239         echo "FAILURE: Results are not available."
240         echo "-------------------------------------------------------------------"
241         cat $LOG_FILE
242         echo "-------------------------------------------------------------------"
243         exit $EXIT_NO_RESULTS
244     else
245         print_results "${RES_DIR}"
246         if [ $(($EXIT & $EXIT_TC_FAILED)) -gt 0 ] ; then
247             echo "-------------------------------------------------------------------"
248             cat $LOG_FILE
249             echo "-------------------------------------------------------------------"
250         fi
251     fi
252
253     # show detailed result figures
254     for md_file in $(grep '\.md"$' $LOG_FILE | cut -d'"' -f2); do
255         # TC resut file header
256         echo -e "\n-------------------------------------------------------------------"
257         echo -e " $md_file"
258         echo -e "-------------------------------------------------------------------\n"
259         # TC details
260         sed -n '/^- Test ID/,/Bidirectional/{/Packet size/b;p;/Bidirectional/q};/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file
261         # TC results
262         sed -n '/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file | grep -v "Unknown" | cat -s
263     done
264
265     # add test results into the final doc template
266     for report in ${RES_DIR}/${TEST_REPORT_PARTIAL} ; do
267         # modify link to the artifactory with test report and logs
268         if [ -f $report ] ; then
269             sed -i -e "s,$TEST_REPORT_LINK_OLD,$TEST_REPORT_LINK_NEW," "$report"
270             cp $report $TEST_REPORT_DIR
271             echo "   $(basename $report)" >> $TEST_REPORT_INDEX
272         fi
273     done
274
275     # copy logs into dedicated directory
276     mkdir ${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}
277     [ -f "$LOG_FILE" ] && cp -a "${LOG_FILE}" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
278     [ -d "$RES_DIR" ] && cp -ar "$RES_DIR" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
279 }
280
281 # generates final test_report in PDF and HTML formats
282 function generate_report() {
283
284     # prepare final tarball with all logs...
285     tar --exclude "${TEST_REPORT_TARBALL}" -czf "${TEST_REPORT_LOG_DIR}/${TEST_REPORT_TARBALL}" $(find "${TEST_REPORT_LOG_DIR}" -mindepth 1 -maxdepth 1 -type d)
286     # ...and move original log files to the archive directory
287     find "${TEST_REPORT_LOG_DIR}" -mindepth 1 -maxdepth 1 -type d -exec mv \{\} ${RESULTS_ARCHIVE} \;
288
289     # clone opnfvdocs repository
290     echo "Cloning opnfvdocs repository..."
291     [ -d opnfvdocs ] && rm -rf opnfvdocs
292     git clone https://gerrit.opnfv.org/gerrit/opnfvdocs &> /dev/null
293
294     # generate final docs with test results
295     echo "Generating test report..."
296     sed -ie 's,python ,python2 ,g' ./opnfvdocs/scripts/docs-build.sh
297     OPNFVDOCS_DIR='./opnfvdocs' ./opnfvdocs/scripts/docs-build.sh &> /dev/null
298
299     # store HTML report with test results into dedicated directory
300     if [ -f $TEST_REPORT_FILE ] ; then
301         cp -ar $TEST_REPORT_FILE $(dirname $TEST_REPORT_FILE)/_static $TEST_REPORT_LOG_DIR
302         echo "Final test report has been created."
303     else
304         echo "FAILURE: Generation of final test report has failed."
305     fi
306 }
307
308 # generates graphs from recent test results
309 function generate_and_push_graphs() {
310     # create graphs from results in archive directory
311     ./ci/plot-results.sh "phy2phy_tput back2back pvp_tput pvvp_tput" ",OvsDpdkVhost," $RESULTS_ARCHIVE
312
313     # push graphs into artifactory
314     if ls *png &> /dev/null ; then
315         gsutil cp *png gs://artifacts.opnfv.org/logs/vswitchperf/intel-pod12/graphs/
316     else
317         echo "Graphs were not created."
318     fi
319 }
320
321 # pushes test report and logs collected during test execution into artifactory
322 function push_results_to_artifactory() {
323     # clone releng repository
324     echo "Cloning releng repository..."
325     [ -d releng ] && rm -rf releng
326     git clone https://gerrit.opnfv.org/gerrit/releng &> /dev/null
327
328     echo "Pushing results and logs into artifactory..."
329     . ./releng/utils/push-test-logs.sh "$DATE"
330
331     # enter workspace as it could be modified by 3rd party script
332     cd $WORKSPACE
333 }
334
335 # removes any local changes of repository
336 function cleanup() {
337     echo "Cleaning up..."
338     git stash -u
339 }
340
341 # prepares directory for logs collection and removes old logs
342 function initialize_logdir() {
343     if [[ "x$TEST_REPORT_LOG_DIR" == "x" ]] ; then
344         echo "FAILURE: Logging directory is not defined. Logs and report cannot be published!"
345         exit $EXIT_NO_TEST_REPORT_LOG_DIR
346     else
347         # remove TEST_REPORT_LOG_DIR if it exists
348         if [ -e $TEST_REPORT_LOG_DIR ] ; then
349             if [ -f $TEST_REPORT_LOG_DIR ] ; then
350                 rm $TEST_REPORT_LOG_DIR
351             else
352                 rm -rf ${TEST_REPORT_LOG_DIR}
353             fi
354         fi
355         # create TEST_REPORT_LOG_DIR
356         mkdir -p $TEST_REPORT_LOG_DIR
357     fi
358 }
359
360 # verify basic vsperf functionality
361 function execute_vsperf_sanity() {
362     DATE_SUFFIX=$(date -u +"%Y-%m-%d_%H-%M-%S")
363     LOG_FILE="${LOG_FILE_PREFIX}_sanity_${DATE_SUFFIX}.log"
364     echo "Execution of VSPERF sanity checks:"
365     for PARAM in '--version' '--help' '--list-trafficgens' '--list-collectors' '--list-vswitches' '--list-fwdapps' '--list-vnfs' '--list-settings' '--list' '--integration --list'; do
366         echo -e "-------------------------------------------------------------------" >> $LOG_FILE
367         echo "$VSPERF_BIN $PARAM $CONF_FILE" >> $LOG_FILE
368         echo -e "-------------------------------------------------------------------" >> $LOG_FILE
369         $VSPERF_BIN $PARAM $CONF_FILE &>> $LOG_FILE
370         if $VSPERF_BIN $PARAM $CONF_FILE &>> $LOG_FILE ; then
371             printf "    %-70s %-6s\n" "$VSPERF_BIN $PARAM" "OK"
372         else
373             printf "    %-70s %-6s\n" "$VSPERF_BIN $PARAM" "FAILED"
374             EXIT=$EXIT_SANITY_TC_FAILED
375         fi
376         echo >> $LOG_FILE
377     done
378     echo "Sanity log file $LOG_FILE"
379     if [ $(($EXIT & $EXIT_SANITY_TC_FAILED)) -gt 0 ] ; then
380         echo "-------------------------------------------------------------------"
381         cat $LOG_FILE
382         echo "-------------------------------------------------------------------"
383     fi
384 }
385
386 # execute pylint to check code quality
387 function execute_vsperf_pylint_check() {
388     if ! ./check -b ; then
389         EXIT=$EXIT_PYLINT_FAILED
390     fi
391 }
392
393 # check and install required packages at nodes running VERIFY and MERGE jobs
394 function dependencies_check() {
395     . /etc/os-release
396     if [ $ID == "ubuntu" ] ; then
397         echo "Dependencies check"
398         echo "=================="
399         # install system packages
400         for PACKAGE in "python3-tk" "sysstat" "bc" ; do
401             if dpkg -s $PACKAGE &> /dev/null ; then
402                 printf "    %-70s %-6s\n" $PACKAGE "OK"
403             else
404                 printf "    %-70s %-6s\n" $PACKAGE "missing"
405                 sudo apt-get install -y $PACKAGE
406             fi
407         done
408         # install additional python packages into python environment
409         for PACKAGE in "pylint" ; do
410             if pip show $PACKAGE &> /dev/null ; then
411                 printf "    %-70s %-6s\n" $PACKAGE "OK"
412             else
413                 printf "    %-70s %-6s\n" $PACKAGE "missing"
414                 pip install $PACKAGE
415             fi
416         done
417         echo
418     fi
419 }
420
421 # configure hugepages
422 function configure_hugepages() {
423     sudo bash -c "echo 2048 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages"
424     sudo bash -c "echo 0 > /sys/devices/system/node/node1/hugepages/hugepages-2048kB/nr_hugepages"
425 }
426
427 # dump hugepages configuration
428 function hugepages_info() {
429     echo "-------------------------------------------------------------------"
430     head /sys/devices/system/node/node*/hugepages/hugepages*/*
431     echo "-------------------------------------------------------------------"
432 }
433
434 #
435 # main
436 #
437
438 echo
439
440 # enter workspace dir
441 cd $WORKSPACE
442
443 # create virtualenv if needed
444 if [ ! -e $VSPERFENV_DIR ] ; then
445     echo "Create VSPERF environment"
446     echo "========================="
447     virtualenv --python=python3 "$VSPERFENV_DIR"
448     echo
449 fi
450
451 # acivate and update virtualenv
452 echo "Update VSPERF environment"
453 echo "========================="
454 source "$VSPERFENV_DIR"/bin/activate
455 pip install -r ./requirements.txt
456 echo
457
458 # VERFIY&MERGE job specific - check if required packages are installed
459 dependencies_check
460
461 # initialization
462 initialize_logdir
463
464 # configure hugepages
465 configure_hugepages
466
467 # execute job based on passed parameter
468 case $1 in
469     "verify")
470         echo "================="
471         echo "VSPERF verify job"
472         echo "================="
473
474         execute_vsperf_pylint_check
475         terminate_vsperf
476         execute_vsperf_sanity
477         terminate_vsperf
478         execute_vsperf OVS_with_DPDK_and_vHost_User $1
479         terminate_vsperf
480         execute_vsperf OVS_vanilla $1
481         terminate_vsperf
482         execute_vsperf VPP $1
483         terminate_vsperf
484
485         exit $EXIT
486         ;;
487     "merge")
488         echo "================"
489         echo "VSPERF merge job"
490         echo "================"
491
492         execute_pylint_check
493         terminate_vsperf
494         execute_vsperf_sanity
495         terminate_vsperf
496         execute_vsperf OVS_with_DPDK_and_vHost_User $1
497         terminate_vsperf
498         execute_vsperf OVS_vanilla $1
499         terminate_vsperf
500         execute_vsperf VPP $1
501         terminate_vsperf
502
503         exit $EXIT
504         ;;
505     *)
506         echo "================"
507         echo "VSPERF daily job"
508         echo "================"
509
510         terminate_vsperf
511         execute_vsperf OVS_with_DPDK_and_vHost_User $1
512         terminate_vsperf
513         execute_vsperf OVS_vanilla $1
514         terminate_vsperf
515         execute_vsperf VPP $1
516         terminate_vsperf
517         execute_vsperf SRIOV $1
518         terminate_vsperf
519
520         generate_report
521
522         push_results_to_artifactory
523
524         generate_and_push_graphs
525
526         cleanup
527
528         exit $EXIT
529         ;;
530 esac
531
532 exit $EXIT
533
534 #
535 # end
536 #