CSIT-1101: Optimize input data processing
[csit.git] / bootstrap-verify-perf.sh
1 #!/bin/bash
2 # Copyright (c) 2018 Cisco and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 set -xo pipefail
16
17 # Space separated list of available testbeds, described by topology files
18 TOPOLOGIES="topologies/available/lf_testbed1.yaml \
19             topologies/available/lf_testbed2.yaml \
20             topologies/available/lf_testbed3.yaml"
21
22 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
23
24 # Reservation dir
25 RESERVATION_DIR="/tmp/reservation_dir"
26 INSTALLATION_DIR="/tmp/install_dir"
27
28 JOB_ARCHIVE_ARTIFACTS=(log.html output.xml report.html)
29 LOG_ARCHIVE_ARTIFACTS=(log.html output.xml report.html)
30 JOB_ARCHIVE_DIR="archive"
31 LOG_ARCHIVE_DIR="$WORKSPACE/archives"
32 mkdir -p ${JOB_ARCHIVE_DIR}
33 mkdir -p ${LOG_ARCHIVE_DIR}
34
35 # If we run this script from CSIT jobs we want to use stable vpp version
36 if [[ ${JOB_NAME} == csit-* ]] ;
37 then
38     mkdir vpp_download
39     cd vpp_download
40
41     if [[ ${TEST_TAG} == *DAILY ]] || \
42        [[ ${TEST_TAG} == *WEEKLY ]];
43     then
44         # Download the latest VPP build .deb install packages
45         echo Downloading VPP packages...
46         bash ${SCRIPT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh --skip-install
47
48         VPP_DEBS="$( readlink -f *.deb | tr '\n' ' ' )"
49         # Take vpp package and get the vpp version
50         VPP_STABLE_VER="$( expr match $(ls *.deb | head -n 1) 'vpp-\(.*\)-deb.deb' )"
51     else
52         DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)_amd64
53         VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_UBUNTU)
54         VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_UBUNTU)
55         VPP_CLASSIFIER="-deb"
56         # Download vpp build from nexus and set VPP_DEBS variable
57         wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
58         wget -q "${VPP_REPO_URL}/vpp-dbg/${VPP_STABLE_VER}/vpp-dbg-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
59         wget -q "${VPP_REPO_URL}/vpp-dev/${VPP_STABLE_VER}/vpp-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
60         wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${DPDK_STABLE_VER}/vpp-dpdk-dkms-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
61         wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
62         wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
63         VPP_DEBS="$( readlink -f *.deb | tr '\n' ' ' )"
64     fi
65
66     cd ${SCRIPT_DIR}
67
68 # If we run this script from vpp project we want to use local build
69 elif [[ ${JOB_NAME} == vpp-* ]] ;
70 then
71     # Use local packages provided as argument list
72     # Jenkins VPP deb paths (convert to full path)
73     VPP_DEBS="$( readlink -f $@ | tr '\n' ' ' )"
74     # Take vpp package and get the vpp version
75     VPP_STABLE_VER="$( expr match $1 'vpp-\(.*\)-deb.deb' )"
76 else
77     echo "Unable to identify job type based on JOB_NAME variable: ${JOB_NAME}"
78     exit 1
79 fi
80
81 WORKING_TOPOLOGY=""
82 export PYTHONPATH=${SCRIPT_DIR}
83
84 sudo apt-get -y update
85 sudo apt-get -y install libpython2.7-dev python-virtualenv
86
87 virtualenv --system-site-packages env
88 . env/bin/activate
89
90 echo pip install
91 pip install -r requirements.txt
92
93 # We iterate over available topologies and wait until we reserve topology
94 while :; do
95     for TOPOLOGY in ${TOPOLOGIES};
96     do
97         python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -t ${TOPOLOGY}
98         if [ $? -eq 0 ]; then
99             WORKING_TOPOLOGY=${TOPOLOGY}
100             echo "Reserved: ${WORKING_TOPOLOGY}"
101             break
102         fi
103     done
104
105     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
106         # Exit the infinite while loop if we made a reservation
107         break
108     fi
109
110     # Wait ~3minutes before next try
111     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
112     echo "Sleeping ${SLEEP_TIME}"
113     sleep ${SLEEP_TIME}
114 done
115
116 function cancel_all {
117     python ${SCRIPT_DIR}/resources/tools/scripts/topo_installation.py -c -d ${INSTALLATION_DIR} -t $1
118     python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -c -t $1
119 }
120
121 # On script exit we cancel the reservation and installation and delete all vpp
122 # packages
123 trap "cancel_all ${WORKING_TOPOLOGY}" EXIT
124
125 python ${SCRIPT_DIR}/resources/tools/scripts/topo_installation.py \
126     -t ${WORKING_TOPOLOGY} -d ${INSTALLATION_DIR} -p ${VPP_DEBS}
127 if [ $? -eq 0 ]; then
128     echo "VPP Installed on hosts from: ${WORKING_TOPOLOGY}"
129 else
130     echo "Failed to copy vpp deb files to DUTs"
131     exit 1
132 fi
133
134 # Based on job we will identify DUT
135 if [[ ${JOB_NAME} == *hc2vpp* ]] ;
136 then
137     DUT="hc2vpp"
138 elif [[ ${JOB_NAME} == *vpp* ]] ;
139 then
140     DUT="vpp"
141 elif [[ ${JOB_NAME} == *ligato* ]] ;
142 then
143     DUT="kubernetes"
144 elif [[ ${JOB_NAME} == *dpdk* ]] ;
145 then
146     DUT="dpdk"
147 else
148     echo "Unable to identify dut type based on JOB_NAME variable: ${JOB_NAME}"
149     exit 1
150 fi
151
152 PYBOT_ARGS="--consolewidth 120 --loglevel TRACE --variable TOPOLOGY_PATH:${WORKING_TOPOLOGY} --suite tests.${DUT}.perf"
153
154 case "$TEST_TAG" in
155     # select specific performance tests based on jenkins job type variable
156     PERFTEST_DAILY )
157         TAGS=('ndrdiscANDnic_intel-x520-da2AND1t1c'
158               'ndrdiscANDnic_intel-x520-da2AND2t2c'
159               'ndrpdrANDnic_intel-x520-da2AND1t1c'
160               'ndrpdrANDnic_intel-x520-da2AND2t2c'
161               'ndrdiscAND1t1cANDipsec'
162               'ndrdiscAND2t2cANDipsec')
163         ;;
164     PERFTEST_SEMI_WEEKLY )
165         TAGS=('ndrdiscANDnic_intel-x710AND1t1c'
166               'ndrdiscANDnic_intel-x710AND2t2c'
167               'ndrdiscANDnic_intel-xl710AND1t1c'
168               'ndrdiscANDnic_intel-xl710AND2t2c')
169         ;;
170     PERFTEST_MRR_DAILY )
171        TAGS=('mrrAND64bAND1t1c'
172              'mrrAND64bAND2t2c'
173              'mrrAND64bAND4t4c'
174              'mrrAND78bAND1t1c'
175              'mrrAND78bAND2t2c'
176              'mrrAND78bAND4t4c'
177              'mrrANDimixAND1t1cANDvhost'
178              'mrrANDimixAND2t2cANDvhost'
179              'mrrANDimixAND4t4cANDvhost'
180              'mrrANDimixAND1t1cANDmemif'
181              'mrrANDimixAND2t2cANDmemif'
182              'mrrANDimixAND4t4cANDmemif')
183         ;;
184     VERIFY-PERF-NDRDISC )
185         TAGS=('ndrdiscAND1t1c'
186               'ndrdiscAND2t2c')
187         ;;
188     VERIFY-PERF-PDRDISC )
189         TAGS=('pdrdiscAND1t1c'
190               'pdrdiscAND2t2c')
191         ;;
192     VERIFY-PERF-MRR )
193         TAGS=('mrrAND1t1c'
194               'mrrAND2t2c')
195         ;;
196     VERIFY-PERF-IP4 )
197         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDip4base'
198               'mrrANDnic_intel-x520-da2AND1t1cANDip4fwdANDfib_2m')
199         ;;
200     VERIFY-PERF-IP6 )
201         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDip6base'
202               'mrrANDnic_intel-x520-da2AND1t1cANDip6fwdANDfib_2m')
203         ;;
204     VERIFY-PERF-L2 )
205         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDl2xcbase'
206               'mrrANDnic_intel-x520-da2AND1t1cANDl2bdbase')
207         ;;
208     VERIFY-PERF-LISP )
209         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDlisp')
210         ;;
211     VERIFY-PERF-VXLAN )
212         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDvxlan')
213         ;;
214     VERIFY-PERF-VHOST )
215         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDvhost')
216         ;;
217     VERIFY-PERF-MEMIF )
218         TAGS=('pdrdiscANDnic_intel-x520-da2AND1t1cANDmemif'
219               'pdrdiscANDnic_intel-x520-da2AND2t2cANDmemif'
220               'mrrANDnic_intel-x520-da2AND1t1cANDmemif'
221               'mrrANDnic_intel-x520-da2AND2t2cANDmemif')
222         ;;
223     VERIFY-PERF-IPSECHW )
224         TAGS=('pdrdiscANDnic_intel-xl710AND1t1cANDipsechw'
225               'pdrdiscANDnic_intel-xl710AND2t2cANDipsechw'
226               'mrrANDnic_intel-xl710AND1t1cANDipsechw'
227               'mrrANDnic_intel-xl710AND2t2cANDipsechw')
228         ;;
229     VERIFY-PERF-SRV6 )
230         TAGS=('mrrANDsrv6AND1t1c'
231               'mrrANDsrv6AND2t2c')
232         ;;
233     VPP-VERIFY-PERF-IP4 )
234         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDip4base'
235               'mrrANDnic_intel-x520-da2AND1t1cANDip4fwdANDfib_2m')
236         ;;
237     VPP-VERIFY-PERF-IP6 )
238         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDip6base'
239               'mrrANDnic_intel-x520-da2AND1t1cANDip6fwdANDfib_2m')
240         ;;
241     VPP-VERIFY-PERF-L2 )
242         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDl2xcbase'
243               'mrrANDnic_intel-x520-da2AND1t1cANDl2bdbase'
244               'mrrANDnic_intel-x520-da2AND1t1cANDdot1q')
245         ;;
246     VPP-VERIFY-PERF-LISP )
247         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDlisp')
248         ;;
249     VPP-VERIFY-PERF-VXLAN )
250         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDvxlan')
251         ;;
252     VPP-VERIFY-PERF-VHOST )
253         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDvhost')
254         ;;
255     VPP-VERIFY-PERF-MEMIF )
256         TAGS=('pdrdiscANDnic_intel-x520-da2AND1t1cANDmemif'
257               'pdrdiscANDnic_intel-x520-da2AND2t2cANDmemif'
258               'mrrANDnic_intel-x520-da2AND1t1cANDmemif'
259               'mrrANDnic_intel-x520-da2AND2t2cANDmemif')
260         ;;
261     VPP-VERIFY-PERF-ACL )
262         TAGS=('mrrANDnic_intel-x520-da2AND1t1cANDacl'
263               'mrrANDnic_intel-x520-da2AND2t2cANDacl')
264         ;;
265     VPP-VERIFY-PERF-IPSECHW )
266         TAGS=('pdrdiscANDnic_intel-xl710AND1t1cANDipsechw'
267               'pdrdiscANDnic_intel-xl710AND2t2cANDipsechw'
268               'mrrANDnic_intel-xl710AND1t1cANDipsechw'
269               'mrrANDnic_intel-xl710AND2t2cANDipsechw')
270         ;;
271     VPP-VERIFY-PERF-SRV6 )
272         TAGS=('mrrANDsrv6AND1t1c'
273               'mrrANDsrv6AND2t2c')
274         ;;
275     * )
276         TAGS=('perftest')
277 esac
278
279 # Catenate TAG selections by 'OR'
280 printf -v INCLUDES " --include %s " "${TAGS[@]}"
281
282 # Execute the test
283 pybot ${PYBOT_ARGS}${INCLUDES} tests/
284 RETURN_STATUS=$(echo $?)
285
286 # Archive JOB artifacts in jenkins
287 for i in ${JOB_ARCHIVE_ARTIFACTS[@]}; do
288     cp $( readlink -f ${i} | tr '\n' ' ' ) ${JOB_ARCHIVE_DIR}/
289 done
290 # Archive JOB artifacts to logs.fd.io
291 for i in ${LOG_ARCHIVE_ARTIFACTS[@]}; do
292     cp $( readlink -f ${i} | tr '\n' ' ' ) ${LOG_ARCHIVE_DIR}/
293 done
294
295 exit ${RETURN_STATUS}