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