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