c93bb2751e4ce5fb3b59a96abb08f01c88f772a8
[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-%d-%H-%M-%S")
84     ( cd /root/workspace/scripts ; python data_publish.py $time_stamp $test_type $results_dir )
85 }
86
87 function execute_vsperf() {
88     # figure out list of TCs and execution parameters
89     case $2 in
90         "daily")
91             TESTPARAM=$TESTPARAM_DAILY
92             TESTCASES=$TESTCASES_DAILY
93             ;;
94         *)
95             echo "No vsperf test cases implemented for this job type"
96             ;;
97     esac
98
99     # execute testcases
100     echo -e "\nExecution of VSPERF for $1"
101     DATE_SUFFIX=$(date -u +"%Y-%m-%d_%H-%M-%S")
102     source "$VSPERFENV_DIR"/bin/activate
103     case $1 in
104         "SRIOV")
105             # use SRIOV specific TCs and configuration
106             TESTPARAM=$TESTPARAM_SRIOV
107             TESTCASES=$TESTCASES_SRIOV
108             # figure out log file name
109             LOG_SUBDIR="SRIOV"
110             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
111             echo "    $VSPERF_BIN --vswitch none --vnf QemuPciPassthrough $CONF_FILE_SRIOV $TESTPARAM $TESTCASES &> $LOG_FILE"
112             $VSPERF_BIN --vswitch none --vnf QemuPciPassthrough $CONF_FILE_SRIOV $TESTPARAM $TESTCASES &> $LOG_FILE
113             ;;
114         *)
115             # figure out log file name
116             LOG_SUBDIR="OvsDpdkVhost"
117             LOG_FILE="${LOG_FILE_PREFIX}_${LOG_SUBDIR}_${DATE_SUFFIX}.log"
118             cd $HOME/vswitchperf
119             $VSPERF_BIN --list
120             echo "daily test cases started"
121             echo "    $VSPERF_BIN --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES > $LOG_FILE"
122             $VSPERF_BIN  --vswitch OvsDpdkVhost --vnf QemuDpdkVhostUser $CONF_FILE $TESTPARAM $TESTCASES &>> $LOG_FILE
123             ;;
124     esac
125     # evaluation of results
126     echo -e "\nResults for $1"
127     RES_DIR="/$(grep "Creating result directory" $LOG_FILE | cut -d'/' -f2-)"
128     if [[ "/" == "${RES_DIR}" ]] ; then
129         echo "FAILURE: Results are not available."
130         echo "-------------------------------------------------------------------"
131         cat $LOG_FILE
132         echo "-------------------------------------------------------------------"
133         exit $EXIT_NO_RESULTS
134     else
135         print_results "${RES_DIR}"
136         if [ $(($EXIT & $EXIT_TC_FAILED)) -gt 0 ] ; then
137             echo "-------------------------------------------------------------------"
138             cat $LOG_FILE
139             echo "-------------------------------------------------------------------"
140         fi
141     fi
142     # show detailed result figures
143     for md_file in $(grep '\.md"$' $LOG_FILE | cut -d'"' -f2); do
144         # TC resut file header
145         echo -e "\n-------------------------------------------------------------------"
146         echo -e " $md_file"
147         echo -e "-------------------------------------------------------------------\n"
148         # TC details
149         sed -n '/^- Test ID/,/Bidirectional/{/Packet size/b;p;/Bidirectional/q};/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file
150         # TC results
151         sed -n '/Results\/Metrics Collected/,/Statistics collected/{/^$/p;/^|/p}' $md_file | grep -v "Unknown" | cat -s
152     done
153
154     # copy logs into dedicated directory
155     mkdir -p ${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}
156     [ -f "$LOG_FILE" ] && mv "${LOG_FILE}" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
157     [ -d "$RES_DIR" ] && mv "$RES_DIR" "${TEST_REPORT_LOG_DIR}/${LOG_SUBDIR}" &> /dev/null
158
159     # Publish test cases results to Grafana Dashboard
160     publish_results $1
161 }
162
163 #Install vsperf and set up the environment
164 install_vsperf
165
166 #Install kvmfornfv built qemu rpm
167 install_qemu
168
169 # execute job based on passed parameter
170 case $1 in
171     "daily")
172         echo "========================================================"
173         echo "KVM4NFV daily job executing packet forwarding test cases"
174         echo "========================================================"
175         execute_vsperf OVS_with_DPDK_and_vHost_User $1
176         execute_vsperf SRIOV $1
177         exit $EXIT
178         ;;
179     *)
180         echo "test cases not implemented for this job type"
181 esac
182
183 exit $EXIT
184