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