CSIT-1186: Consume MLRsearch in agreed upon way
[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_3n_hsw_testbed1.yaml \
19             topologies/available/lf_3n_hsw_testbed2.yaml \
20             topologies/available/lf_3n_hsw_testbed3.yaml"
21
22 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
23 export PYTHONPATH=${SCRIPT_DIR}
24 export DEBIAN_FRONTEND=noninteractive
25
26 # Reservation dir
27 RESERVATION_DIR="/tmp/reservation_dir"
28 INSTALLATION_DIR="/tmp/install_dir"
29
30 JOB_ARCHIVE_ARTIFACTS=(log.html output.xml report.html)
31 LOG_ARCHIVE_ARTIFACTS=(log.html output.xml report.html)
32 JOB_ARCHIVE_DIR="archive"
33 LOG_ARCHIVE_DIR="$WORKSPACE/archives"
34 mkdir -p ${JOB_ARCHIVE_DIR}
35 mkdir -p ${LOG_ARCHIVE_DIR}
36
37 # If we run this script from CSIT jobs we want to use stable vpp version
38 if [[ ${JOB_NAME} == csit-* ]] ;
39 then
40     if [[ ${TEST_TAG} == *DAILY ]] || \
41        [[ ${TEST_TAG} == *WEEKLY ]];
42     then
43         echo Downloading latest VPP packages from NEXUS...
44         bash ${SCRIPT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh \
45             --skip-install
46     else
47         echo Downloading VPP packages of specific version from NEXUS...
48         DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)
49         VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_UBUNTU)
50         #Temporary if arch will not be removed from VPP_STABLE_VER_UBUNTU
51         #VPP_STABLE_VER=${VPP_STABLE_VER%_amd64}
52         bash ${SCRIPT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh \
53             --skip-install --vpp ${VPP_STABLE_VER} --dkms ${DPDK_STABLE_VER}
54     fi
55     # Jenkins VPP deb paths (convert to full path)
56     VPP_DEBS="$( readlink -f vpp*.deb | tr '\n' ' ' )"
57
58 # If we run this script from vpp project we want to use local build
59 elif [[ ${JOB_NAME} == vpp-* ]] ;
60 then
61     # Use local packages provided as argument list
62     # Jenkins VPP deb paths (convert to full path)
63     VPP_DEBS="$( readlink -f $@ | tr '\n' ' ' )"
64 else
65     echo "Unable to identify job type based on JOB_NAME variable: ${JOB_NAME}"
66     exit 1
67 fi
68
69 WORKING_TOPOLOGY=""
70
71 sudo apt-get -y update
72 sudo apt-get -y install libpython2.7-dev python-virtualenv
73
74 virtualenv --system-site-packages env
75 . env/bin/activate
76
77 echo pip install
78 pip install -r requirements.txt
79
80 # We iterate over available topologies and wait until we reserve topology
81 while :; do
82     for TOPOLOGY in ${TOPOLOGIES};
83     do
84         python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -t ${TOPOLOGY}
85         if [ $? -eq 0 ]; then
86             WORKING_TOPOLOGY=${TOPOLOGY}
87             echo "Reserved: ${WORKING_TOPOLOGY}"
88             break
89         fi
90     done
91
92     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
93         # Exit the infinite while loop if we made a reservation
94         break
95     fi
96
97     # Wait ~3minutes before next try
98     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
99     echo "Sleeping ${SLEEP_TIME}"
100     sleep ${SLEEP_TIME}
101 done
102
103 function cancel_all {
104     python ${SCRIPT_DIR}/resources/tools/scripts/topo_installation.py -c -d ${INSTALLATION_DIR} -t $1
105     python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -c -t $1
106 }
107
108 # On script exit we cancel the reservation and installation and delete all vpp
109 # packages
110 trap "cancel_all ${WORKING_TOPOLOGY}" EXIT
111
112 python ${SCRIPT_DIR}/resources/tools/scripts/topo_installation.py \
113     -t ${WORKING_TOPOLOGY} -d ${INSTALLATION_DIR} -p ${VPP_DEBS}
114 if [ $? -eq 0 ]; then
115     echo "VPP Installed on hosts from: ${WORKING_TOPOLOGY}"
116 else
117     echo "Failed to copy vpp deb files to DUTs"
118     exit 1
119 fi
120
121 # Based on job we will identify DUT
122 if [[ ${JOB_NAME} == *hc2vpp* ]] ;
123 then
124     DUT="hc2vpp"
125 elif [[ ${JOB_NAME} == *vpp* ]] ;
126 then
127     DUT="vpp"
128 elif [[ ${JOB_NAME} == *ligato* ]] ;
129 then
130     DUT="kubernetes"
131 elif [[ ${JOB_NAME} == *dpdk* ]] ;
132 then
133     DUT="dpdk"
134 else
135     echo "Unable to identify dut type based on JOB_NAME variable: ${JOB_NAME}"
136     exit 1
137 fi
138
139 PYBOT_ARGS="--consolewidth 100 --loglevel TRACE --variable TOPOLOGY_PATH:${WORKING_TOPOLOGY} --suite tests.${DUT}.perf"
140
141 case "$TEST_TAG" in
142     # select specific performance tests based on jenkins job type variable
143     PERFTEST_DAILY )
144         TAGS=('ndrdiscANDnic_intel-x520-da2AND1c'
145               'ndrdiscANDnic_intel-x520-da2AND2c'
146               'ndrpdrANDnic_intel-x520-da2AND1c'
147               'ndrpdrANDnic_intel-x520-da2AND2c'
148               'ndrdiscAND1cANDipsec'
149               'ndrdiscAND2cANDipsec')
150         ;;
151     PERFTEST_SEMI_WEEKLY )
152         TAGS=('ndrdiscANDnic_intel-x710AND1c'
153               'ndrdiscANDnic_intel-x710AND2c'
154               'ndrdiscANDnic_intel-xl710AND1c'
155               'ndrdiscANDnic_intel-xl710AND2c')
156         ;;
157     PERFTEST_MRR_DAILY )
158        TAGS=('mrrAND64bAND1c'
159              'mrrAND64bAND2c'
160              'mrrAND64bAND4c'
161              'mrrAND78bAND1c'
162              'mrrAND78bAND2c'
163              'mrrAND78bAND4c'
164              'mrrANDimixAND1cANDvhost'
165              'mrrANDimixAND2cANDvhost'
166              'mrrANDimixAND4cANDvhost'
167              'mrrANDimixAND1cANDmemif'
168              'mrrANDimixAND2cANDmemif'
169              'mrrANDimixAND4cANDmemif')
170         ;;
171     VERIFY-PERF-PATCH )
172         if [[ -z "$TEST_TAG_STRING" ]]; then
173             # If nothing is specified, we will run pre-selected tests by
174             # following tags. Items of array will be concatenated by OR in Robot
175             # Framework.
176             TEST_TAG_ARRAY=('mrrANDnic_intel-x710AND1cAND64bANDip4base'
177                             'mrrANDnic_intel-x710AND1cAND78bANDip6base'
178                             'mrrANDnic_intel-x710AND1cAND64bANDl2bdbase')
179         else
180             # If trigger contains tags, split them into array.
181             TEST_TAG_ARRAY=(${TEST_TAG_STRING//:/ })
182         fi
183
184         TAGS=()
185
186         for TAG in "${TEST_TAG_ARRAY[@]}"; do
187             if [[ ${TAG} == "!"* ]]; then
188                 # Exclude tags are not prefixed.
189                 TAGS+=("${TAG}")
190             else
191                 # We will prefix with perftest to prevent running other tests
192                 # (e.g. Functional).
193                 prefix="perftestAND"
194                 if [[ ${JOB_NAME} == vpp-* ]] ; then
195                     # Automatic prefixing for VPP jobs to limit the NIC used and
196                     # traffic evaluation to MRR.
197                     prefix="${prefix}mrrANDnic_intel-x710AND"
198                 fi
199                 TAGS+=("$prefix${TAG}")
200             fi
201         done
202         ;;
203     * )
204         TAGS=('perftest')
205 esac
206
207 # Catenate TAG selections
208 EXPANDED_TAGS=()
209 for TAG in "${TAGS[@]}"; do
210     if [[ ${TAG} == "!"* ]]; then
211         EXPANDED_TAGS+=(" --exclude ${TAG#$"!"} ")
212     else
213         EXPANDED_TAGS+=(" --include ${TAG} ")
214     fi
215 done
216
217 # Execute the test
218 pybot ${PYBOT_ARGS}${EXPANDED_TAGS[@]} tests/
219 RETURN_STATUS=$(echo $?)
220
221 # Archive JOB artifacts in jenkins
222 for i in ${JOB_ARCHIVE_ARTIFACTS[@]}; do
223     cp $( readlink -f ${i} | tr '\n' ' ' ) ${JOB_ARCHIVE_DIR}/
224 done
225 # Archive JOB artifacts to logs.fd.io
226 for i in ${LOG_ARCHIVE_ARTIFACTS[@]}; do
227     cp $( readlink -f ${i} | tr '\n' ' ' ) ${LOG_ARCHIVE_DIR}/
228 done
229
230 exit ${RETURN_STATUS}