bugfix: Fix link to the artifactory
[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_Cuse, 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         "OVS_with_DPDK_and_vHost_Cuse")
167             # figure out log file name
168             LOG_SUBDIR="OvsDpdkVhostCuse"
169             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
170
171             echo "$VSPERF_BIN --opnfvpod="$NODE_NAME" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostCuse $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE"
172             $VSPERF_BIN --opnfvpod="$NODE_NAME" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostCuse $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE
173             ;;
174         *)
175             # figure out log file name
176             LOG_SUBDIR="OvsDpdkVhost"
177             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
178
179             echo "$VSPERF_BIN --opnfvpod="$NODE_NAME" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES > $LOG_FILE"
180             $VSPERF_BIN --opnfvpod="$NODE_NAME" --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES &> $LOG_FILE
181             ;;
182     esac
183
184     # evaluation of results
185     echo -e "\nResults for $1"
186     RES_DIR="/$(grep "Creating result directory" $LOG_FILE | cut -d'/' -f2-)"
187     if [[ "/" == "${RES_DIR}" ]] ; then
188         echo "FAILURE: Results are not available."
189         exit $EXIT_NO_RESULTS
190     else
191         print_results "${RES_DIR}"
192     fi
193
194     # show detailed result figures
195     for md_file in $(grep '\.md"$' $LOG_FILE | cut -d'"' -f2); do
196         # TC resut file header
197         echo -e "\n-------------------------------------------------------------------"
198         echo -e " $md_file"
199         echo -e "-------------------------------------------------------------------\n"
200         # TC details
201         sed -n '/^- Test ID/,/Bidirectional/{/Packet size/b;p;/Bidirectional/q};/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file
202         # TC results
203         sed -n '/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file | grep -v "Unknown" | cat -s
204     done
205
206     # add test results into the final doc template
207     for report in ${RES_DIR}/${TEST_REPORT_PARTIAL} ; do
208         # modify link to the artifactory with test report and logs
209         if [ -f $report ] ; then
210             sed -i -e "s,$TEST_REPORT_LINK_OLD,$TEST_REPORT_LINK_NEW," "$report"
211             cp $report $TEST_REPORT_DIR
212             echo "   $(basename $report)" >> $TEST_REPORT_INDEX
213         fi
214     done
215
216     # copy logs into dedicated directory
217     mkdir ${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}
218     [ -f "$LOG_FILE" ] && cp -a "${LOG_FILE}" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
219     [ -d "$RES_DIR" ] && cp -ar "$RES_DIR" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
220 }
221
222 # generates final test_report in PDF and HTML formats
223 function generate_report() {
224
225     # prepare final tarball with all logs...
226     tar --exclude "${TEST_REPORT_TARBALL}" -czf "${TEST_REPORT_LOG_DIR}/${TEST_REPORT_TARBALL}" $(find "${TEST_REPORT_LOG_DIR}" -mindepth 1 -maxdepth 1 -type d)
227     # ...and remove original log files
228     find "${TEST_REPORT_LOG_DIR}" -mindepth 1 -maxdepth 1 -type d -exec rm -rf \{\} \;
229
230     # clone releng repository
231     echo "Cloning releng repository..."
232     [ -d releng ] && rm -rf releng
233     git clone https://gerrit.opnfv.org/gerrit/releng &> /dev/null
234
235     # generate final docs with test results
236     echo "Generating test report..."
237     sed -ie 's,python ,python2 ,g' ./releng/utils/docs-build.sh
238     ./releng/utils/docs-build.sh &> /dev/null
239
240     # store PDF with test results into dedicated directory
241     if [ -f $TEST_REPORT_FILE ] ; then
242         cp -a $TEST_REPORT_FILE $TEST_REPORT_LOG_DIR
243         echo "Final test report has been created."
244     else
245         echo "FAILURE: Generation of final test report has failed."
246     fi
247 }
248
249 # pushes test report and logs collected during test execution into artifactory
250 function push_results_to_artifactory() {
251     echo "Pushing results and logs into artifactory..."
252     . ./releng/utils/push-test-logs.sh "$DATE"
253
254     # enter workspace as it could be modified by 3rd party script
255     cd $WORKSPACE
256 }
257
258 # removes any local changes of repository
259 function cleanup() {
260     echo "Cleaning up..."
261     git stash -u
262 }
263
264 # prepares directory for logs collection and removes old logs
265 function initialize_logdir() {
266     if [[ "x$TEST_REPORT_LOG_DIR" == "x" ]] ; then
267         echo "FAILURE: Logging directory is not defined. Logs and report cannot be published!"
268         exit $EXIT_NO_TEST_REPORT_LOG_DIR
269     else
270         # remove TEST_REPORT_LOG_DIR if it exists
271         if [ -e $TEST_REPORT_LOG_DIR ] ; then
272             if [ -f $TEST_REPORT_LOG_DIR ] ; then
273                 rm $TEST_REPORT_LOG_DIR
274             else
275                 rm -rf ${TEST_REPORT_LOG_DIR}
276             fi
277         fi
278         # create TEST_REPORT_LOG_DIR
279         mkdir -p $TEST_REPORT_LOG_DIR
280     fi
281 }
282
283 #
284 # main
285 #
286
287 # enter workspace dir
288 cd $WORKSPACE
289
290 # initialization
291 initialize_logdir
292
293 # execute job based on passed parameter
294 case $1 in
295     "verify")
296         echo "VSPERF verify job"
297         echo "================="
298
299         #execute_vsperf OVS_with_DPDK_and_vHost_User $1
300
301         exit $EXIT
302         ;;
303     "merge")
304         echo "VSPERF merge job"
305         echo "================"
306
307         #execute_vsperf OVS_with_DPDK_and_vHost_User $1
308
309         exit $EXIT
310         ;;
311     *)
312         echo "VSPERF daily job"
313         echo "================"
314
315         terminate_vsperf
316         execute_vsperf OVS_with_DPDK_and_vHost_User $1
317         terminate_vsperf
318         execute_vsperf OVS_vanilla $1
319         terminate_vsperf
320
321         generate_report
322
323         push_results_to_artifactory
324
325         cleanup
326
327         exit $EXIT
328         ;;
329 esac
330
331 exit $EXIT
332
333 #
334 # end
335 #