cuse: Remove vHost Cuse support
[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_NO_RESULTS=10
30 EXIT_NO_TEST_REPORT_LOG_DIR=11
31
32 #
33 # configuration
34 #
35
36 VSPERF_BIN='./vsperf'
37 LOG_FILE_PREFIX="/tmp/vsperf_build"
38 DATE=$(date -u +"%Y-%m-%d_%H-%M-%S")
39 BRANCH=${GIT_BRANCH##*/}
40
41 # CI job specific configuration
42 # VERIFY - run basic set of TCs with default settings
43 TESTCASES_VERIFY="phy2phy_tput pvp_tput"
44 TESTPARAM_VERIFY=""
45 # MERGE - run selected TCs with default settings
46 TESTCASES_MERGE="phy2phy_tput back2back phy2phy_cont pvp_tput pvvp_tput"
47 TESTPARAM_MERGE=""
48 # DAILY - run selected TCs for defined packet sizes
49 TESTCASES_DAILY='phy2phy_tput back2back phy2phy_tput_mod_vlan phy2phy_scalability pvp_tput pvp_back2back pvvp_tput pvvp_back2back'
50 TESTPARAM_DAILY='--test-params pkt_sizes=64,128,512,1024,1518'
51 # check if user config file exists if not then we will use default settings
52 if [ -f $HOME/vsperf-${BRANCH}.conf ] ; then
53     # branch specific config was found
54     CONF_FILE="--conf-file ${HOME}/vsperf-${BRANCH}.conf"
55 else
56     if [ -f $HOME/vsperf.conf ] ; then
57         CONF_FILE="--conf-file ${HOME}/vsperf.conf"
58     else
59         CONF_FILE=""
60     fi
61 fi
62
63 # Test report related configuration
64 TEST_REPORT_PARTIAL="*_test_report.rst"
65 TEST_REPORT_DIR="${WORKSPACE}/docs/results"
66 TEST_REPORT_INDEX="${TEST_REPORT_DIR}/index.rst"
67 TEST_REPORT_LINK_OLD="https://wiki.opnfv.org/wiki/vsperf_results"
68 TEST_REPORT_FILE="${WORKSPACE}/docs_output/results/results.pdf"
69 TEST_REPORT_TARBALL="vswitchperf_logs_${DATE}.tar.gz"
70
71 if [[ "x${BRANCH}" == "xmaster" ]]; then
72     TEST_REPORT_LINK_NEW="https://artifacts.opnfv.org/logs/$PROJECT/$NODE_NAME/$DATE/${TEST_REPORT_TARBALL}"
73 else
74     TEST_REPORT_LINK_NEW="https://artifacts.opnfv.org/logs/$PROJECT/$NODE_NAME/$BRANCH/$DATE/${TEST_REPORT_TARBALL}"
75 fi
76
77 TEST_REPORT_LOG_DIR="${HOME}/opnfv/$PROJECT/results/$BRANCH"
78
79 #
80 # functions
81 #
82
83 # terminate vsperf and all its utilities
84 # it is expected that vsperf is the only python3 app
85 # and no other ovs or qemu instances are running
86 # at CI machine
87 # parameters:
88 #   none
89 function terminate_vsperf() {
90     sudo pkill stress &> /dev/null
91     sudo pkill python3 &> /dev/null
92     sudo killall -9 qemu-system-x86_64 &> /dev/null
93
94     # sometimes qemu resists to terminate, so wait a bit and kill it again
95     if pgrep qemu-system-x86_64 &> /dev/null ; then
96         sleep 5
97         sudo killall -9 qemu-system-x86_64 &> /dev/null
98         sleep 5
99     fi
100
101     sudo pkill ovs-vswitchd &> /dev/null
102     sleep 1
103     sudo pkill ovsdb-server &> /dev/null
104     sleep 1
105 }
106
107 # check and print testcase execution status
108 # parameters:
109 #   $1 - directory with results
110 function print_results() {
111     for i in $TESTCASES ; do
112         if [[ $i == *"pvp"* ]]; then
113             DEPLOYMENT="pvp"
114         elif [[ $i == *"pvvp"* ]]; then
115             DEPLOYMENT="pvvp"
116         else
117             DEPLOYMENT="p2p"
118         fi
119         RES_FILE="result_${i}_${DEPLOYMENT}.csv"
120
121         if [ -e "${1}/${RES_FILE}" ]; then
122             printf "    %-70s %-6s\n" $RES_FILE "OK"
123         else
124             printf "    %-70s %-6s\n" $RES_FILE "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     # figure out list of TCs and execution parameters
136     case $2 in
137         "verify")
138             TESTPARAM=$TESTPARAM_VERIFY
139             TESTCASES=$TESTCASES_VERIFY
140             ;;
141         "merge")
142             TESTPARAM=$TESTPARAM_MERGE
143             TESTCASES=$TESTCASES_MERGE
144             ;;
145         *)
146             # by default use daily build
147             TESTPARAM=$TESTPARAM_DAILY
148             TESTCASES=$TESTCASES_DAILY
149             ;;
150     esac
151
152     # execute testcases
153     echo -e "\nExecution of VSPERF for $1"
154
155     DATE_SUFFIX=$(date -u +"%Y-%m-%d_%H-%M-%S")
156
157     case $1 in
158         "OVS_vanilla")
159             # figure out log file name
160             LOG_SUBDIR="OvsVanilla"
161             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
162
163             echo "$VSPERF_BIN --opnfvpod="$NODE_NAME" --vswitch OvsVanilla --vnf QemuVirtioNet $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE"
164             $VSPERF_BIN --opnfvpod="$NODE_NAME" --vswitch OvsVanilla --vnf QemuVirtioNet $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE
165             ;;
166         *)
167             # figure out log file name
168             LOG_SUBDIR="OvsDpdkVhost"
169             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
170
171             echo "$VSPERF_BIN --opnfvpod="$NODE_NAME" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES > $LOG_FILE"
172             $VSPERF_BIN --opnfvpod="$NODE_NAME" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE
173             ;;
174     esac
175
176     # evaluation of results
177     echo -e "\nResults for $1"
178     RES_DIR="/$(grep "Creating result directory" $LOG_FILE | cut -d'/' -f2-)"
179     if [[ "/" == "${RES_DIR}" ]] ; then
180         echo "FAILURE: Results are not available."
181         exit $EXIT_NO_RESULTS
182     else
183         print_results "${RES_DIR}"
184     fi
185
186     # show detailed result figures
187     for md_file in $(grep '\.md"$' $LOG_FILE | cut -d'"' -f2); do
188         # TC resut file header
189         echo -e "\n-------------------------------------------------------------------"
190         echo -e " $md_file"
191         echo -e "-------------------------------------------------------------------\n"
192         # TC details
193         sed -n '/^- Test ID/,/Bidirectional/{/Packet size/b;p;/Bidirectional/q};/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file
194         # TC results
195         sed -n '/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file | grep -v "Unknown" | cat -s
196     done
197
198     # add test results into the final doc template
199     for report in ${RES_DIR}/${TEST_REPORT_PARTIAL} ; do
200         # modify link to the artifactory with test report and logs
201         if [ -f $report ] ; then
202             sed -i -e "s,$TEST_REPORT_LINK_OLD,$TEST_REPORT_LINK_NEW," "$report"
203             cp $report $TEST_REPORT_DIR
204             echo "   $(basename $report)" >> $TEST_REPORT_INDEX
205         fi
206     done
207
208     # copy logs into dedicated directory
209     mkdir ${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}
210     [ -f "$LOG_FILE" ] && cp -a "${LOG_FILE}" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
211     [ -d "$RES_DIR" ] && cp -ar "$RES_DIR" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
212 }
213
214 # generates final test_report in PDF and HTML formats
215 function generate_report() {
216
217     # prepare final tarball with all logs...
218     tar --exclude "${TEST_REPORT_TARBALL}" -czf "${TEST_REPORT_LOG_DIR}/${TEST_REPORT_TARBALL}" $(find "${TEST_REPORT_LOG_DIR}" -mindepth 1 -maxdepth 1 -type d)
219     # ...and remove original log files
220     find "${TEST_REPORT_LOG_DIR}" -mindepth 1 -maxdepth 1 -type d -exec rm -rf \{\} \;
221
222     # clone opnfvdocs repository
223     echo "Cloning opnfvdocs repository..."
224     [ -d opnfvdocs ] && rm -rf opnfvdocs
225     git clone https://gerrit.opnfv.org/gerrit/opnfvdocs &> /dev/null
226
227     # generate final docs with test results
228     echo "Generating test report..."
229     sed -ie 's,python ,python2 ,g' ./opnfvdocs/scripts/docs-build.sh
230     OPNFVDOCS_DIR='./opnfvdocs' ./opnfvdocs/scripts/docs-build.sh &> /dev/null
231
232     # store PDF with test results into dedicated directory
233     if [ -f $TEST_REPORT_FILE ] ; then
234         cp -a $TEST_REPORT_FILE $TEST_REPORT_LOG_DIR
235         echo "Final test report has been created."
236     else
237         echo "FAILURE: Generation of final test report has failed."
238     fi
239 }
240
241 # pushes test report and logs collected during test execution into artifactory
242 function push_results_to_artifactory() {
243     # clone releng repository
244     echo "Cloning releng repository..."
245     [ -d releng ] && rm -rf releng
246     git clone https://gerrit.opnfv.org/gerrit/releng &> /dev/null
247
248     echo "Pushing results and logs into artifactory..."
249     . ./releng/utils/push-test-logs.sh "$DATE"
250
251     # enter workspace as it could be modified by 3rd party script
252     cd $WORKSPACE
253 }
254
255 # removes any local changes of repository
256 function cleanup() {
257     echo "Cleaning up..."
258     git stash -u
259 }
260
261 # prepares directory for logs collection and removes old logs
262 function initialize_logdir() {
263     if [[ "x$TEST_REPORT_LOG_DIR" == "x" ]] ; then
264         echo "FAILURE: Logging directory is not defined. Logs and report cannot be published!"
265         exit $EXIT_NO_TEST_REPORT_LOG_DIR
266     else
267         # remove TEST_REPORT_LOG_DIR if it exists
268         if [ -e $TEST_REPORT_LOG_DIR ] ; then
269             if [ -f $TEST_REPORT_LOG_DIR ] ; then
270                 rm $TEST_REPORT_LOG_DIR
271             else
272                 rm -rf ${TEST_REPORT_LOG_DIR}
273             fi
274         fi
275         # create TEST_REPORT_LOG_DIR
276         mkdir -p $TEST_REPORT_LOG_DIR
277     fi
278 }
279
280 #
281 # main
282 #
283
284 # enter workspace dir
285 cd $WORKSPACE
286
287 # initialization
288 initialize_logdir
289
290 # execute job based on passed parameter
291 case $1 in
292     "verify")
293         echo "VSPERF verify job"
294         echo "================="
295
296         #execute_vsperf OVS_with_DPDK_and_vHost_User $1
297
298         exit $EXIT
299         ;;
300     "merge")
301         echo "VSPERF merge job"
302         echo "================"
303
304         #execute_vsperf OVS_with_DPDK_and_vHost_User $1
305
306         exit $EXIT
307         ;;
308     *)
309         echo "VSPERF daily job"
310         echo "================"
311
312         terminate_vsperf
313         execute_vsperf OVS_with_DPDK_and_vHost_User $1
314         terminate_vsperf
315         execute_vsperf OVS_vanilla $1
316         terminate_vsperf
317
318         generate_report
319
320         push_results_to_artifactory
321
322         cleanup
323
324         exit $EXIT
325         ;;
326 esac
327
328 exit $EXIT
329
330 #
331 # end
332 #