4f3d946b3d2b6f2a84e695aae24a8de32edcbc52
[kvmfornfv.git] / ci / envs / packet_forwarding.sh
1 #!/bin/bash
2 JOB_TYPE=$1
3 QEMURPM_VERSION=$2
4 HOME='/home/jenkins'
5 VSPERF="${HOME}/vswitchperf"
6 LOG_FILE_PREFIX="/tmp/vsperf_build"
7 VSPERF_BIN='./vsperf'
8 DATE=$(date -u +"%Y-%m-%d_%H-%M-%S")
9 VSPERFENV_DIR="$HOME/vsperfenv"
10 TEST_REPORT_LOG_DIR="/tmp/packet_fwd_logs"
11 EXIT=0
12 EXIT_TC_FAILED=1
13
14 # DAILY - run selected TCs for defined packet sizes
15 TESTCASES_DAILY='phy2phy_tput phy2phy_tput_mod_vlan pvp_tput'
16 TESTPARAM_DAILY='--test-params TRAFFICGEN_PKT_SIZES=(64,128,512,1024,1518)'
17 TESTCASES_SRIOV='pvp_tput'
18 TESTPARAM_SRIOV='--test-params TRAFFICGEN_PKT_SIZES=(64,128,512,1024,1518)'
19
20 #mounting shared directory for collecting ixia test results.
21 shared_dir=$(sudo mount | grep ixia_results)
22 if [ -z "$shared_dir" ]; then
23     echo "mounting shared directory for results"
24     sudo mount -t cifs //10.10.100.6/ixia_results/kvm4nfv_ci /mnt/ixia_results/kvm4nfv_ci  -o password=kvm4nfv! -o username=kvm4nfv,file_mode=0777,dir_mode=0777,nounix
25 else
26     echo "shared directory is already mounted for results"
27 fi
28
29 # check if user config file exists if not then we will use default settings
30 if [ -f $HOME/vsperf.conf ] ; then
31         CONF_FILE="--conf-file ${HOME}/vsperf.conf"
32     else
33         echo "configuration file not found on the test node"
34         echo "Using configuration file available in kvmfornfv repo"
35         CONF_FILE="--conf-file /root/workspace/scripts/vsperf.conf"
36 fi
37
38 # check if sriov config file exists if not then we will use default settings
39 if [ -f $HOME/vsperf.conf.sriov ] ; then
40         CONF_FILE_SRIOV="--conf-file ${HOME}/vsperf.conf.sriov"
41     else
42         echo "SRIOV configuration file not found on the node"
43         echo "Using SRIOV configuration file available in kvmfornfv repo"
44         CONF_FILE="--conf-file /root/workspace/scripts/vsperf.conf.sriov"
45 fi
46
47 function install_vsperf() {
48     echo "Installing vsperf....."
49     ( cd $VSPERF/systems ; ./build_base_machine.sh )
50 }
51
52 #Install kvmfornfv built qemu for launching guest vm.
53 function install_qemu() {
54     echo "removing existing qemu packages and installing kvmfornfv built qemu"
55     ( cd /root/workspace/scripts ; ./host-install-qemu.sh )
56 }
57
58 function print_results() {
59     for i in $TESTCASES ; do
60         RES_FILE=`ls -1 $1 | egrep "result_${i}_[0-9a-zA-Z\-]+.csv"`
61
62         if [ "x$RES_FILE" != "x" -a -e "${1}/${RES_FILE}" ]; then
63             if grep ^FAILED "${1}/${RES_FILE}" &> /dev/null ; then
64                 printf "    %-70s %-6s\n" "result_${i}" "FAILED"
65                 EXIT=$EXIT_TC_FAILED
66             else
67                 echo "--------------------------------------------------------------"
68                 printf "    %-50s %-6s\n" "result_${i}" "OK"
69                 echo "--------------------------------------------------------------"
70             fi
71         else
72             echo "------------------------------------------------------------------"
73             printf "    %-50s %-6s\n" "result_${i}" "FAILED"
74             echo "------------------------------------------------------------------"
75             EXIT=$EXIT_TC_FAILED
76         fi
77     done
78 }
79
80 function publish_results() {
81     test_type=$1
82     results_dir=${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}/results*
83     time_stamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
84     ( cd /root/workspace/scripts ; python2.7 data_publish.py $time_stamp $test_type $results_dir )
85     #cleaning the results after publishing on grafana dashboard.
86     ( cd ${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR} ; rm -rf results* )
87 }
88
89 function execute_vsperf() {
90     # figure out list of TCs and execution parameters
91     case $2 in
92         "daily")
93             TESTPARAM=$TESTPARAM_DAILY
94             TESTCASES=$TESTCASES_DAILY
95             ;;
96         *)
97             echo "No vsperf test cases implemented for this job type"
98             ;;
99     esac
100
101     # execute testcases
102     echo -e "\nExecution of VSPERF for $1"
103     DATE_SUFFIX=$(date -u +"%Y-%m-%d_%H-%M-%S")
104     source "$VSPERFENV_DIR"/bin/activate
105     case $1 in
106         "SRIOV")
107             # use SRIOV specific TCs and configuration
108             TESTPARAM=$TESTPARAM_SRIOV
109             TESTCASES=$TESTCASES_SRIOV
110             # figure out log file name
111             LOG_SUBDIR="SRIOV"
112             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
113             echo "    $VSPERF_BIN --vswitch none --vnf QemuPciPassthrough $CONF_FILE_SRIOV $TESTPARAM $TESTCASES &> $LOG_FILE"
114             $VSPERF_BIN --vswitch none --vnf QemuPciPassthrough $CONF_FILE_SRIOV $TESTPARAM $TESTCASES &> $LOG_FILE
115             ;;
116         *)
117             # figure out log file name
118             LOG_SUBDIR="OvsDpdkVhost"
119             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
120             cd $HOME/vswitchperf
121             $VSPERF_BIN --list
122             echo "daily test cases started"
123             echo "    $VSPERF_BIN --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES > $LOG_FILE"
124             $VSPERF_BIN  --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES &>> $LOG_FILE
125             ;;
126     esac
127     # evaluation of results
128     echo -e "\nResults for $1"
129     RES_DIR="/$(grep "Creating result directory" $LOG_FILE | cut -d'/' -f2-)"
130     if [[ "/" == "${RES_DIR}" ]] ; then
131         echo "FAILURE: Results are not available."
132         echo "-------------------------------------------------------------------"
133         cat $LOG_FILE
134         echo "-------------------------------------------------------------------"
135         exit $EXIT_NO_RESULTS
136     else
137         print_results "${RES_DIR}"
138         if [ $(($EXIT & $EXIT_TC_FAILED)) -gt 0 ] ; then
139             echo "-------------------------------------------------------------------"
140             cat $LOG_FILE
141             echo "-------------------------------------------------------------------"
142         fi
143     fi
144     # show detailed result figures
145     for md_file in $(grep '\.md"$' $LOG_FILE | cut -d'"' -f2); do
146         # TC resut file header
147         echo -e "\n-------------------------------------------------------------------"
148         echo -e " $md_file"
149         echo -e "-------------------------------------------------------------------\n"
150         # TC details
151         sed -n '/^- Test ID/,/Bidirectional/{/Packet size/b;p;/Bidirectional/q};/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file
152         # TC results
153         sed -n '/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file | grep -v "Unknown" | cat -s
154     done
155
156     # copy logs into dedicated directory
157     mkdir -p ${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}
158     [ -f "$LOG_FILE" ] && mv "${LOG_FILE}" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
159     [ -d "$RES_DIR" ] && mv "$RES_DIR" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
160
161     # Publish test cases results to Grafana Dashboard
162     publish_results $1
163 }
164
165 #Install vsperf and set up the environment
166 install_vsperf
167
168 #Install kvmfornfv built qemu rpm
169 install_qemu
170
171 # execute job based on passed parameter
172 case $1 in
173     "daily")
174         echo "========================================================"
175         echo "KVM4NFV daily job executing packet forwarding test cases"
176         echo "========================================================"
177         execute_vsperf OVS_with_DPDK_and_vHost_User $1
178         execute_vsperf SRIOV $1
179         exit $EXIT
180         ;;
181     *)
182         echo "test cases not implemented for this job type"
183 esac
184
185 exit $EXIT
186