698d94baf08eb7df485a04eb30819102438666c1
[csit.git] / bootstrap-verify-perf-DPDK.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
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     *ligato*)
66         DUT="kubernetes"
67         ;;
68     *dpdk*)
69         DUT="dpdk"
70
71         # If we run this script from CSIT jobs we want to use stable version
72         DPDK_REPO='https://fast.dpdk.org/rel/'
73         if [[ ${TEST_TAG} == *DAILY ]] || \
74            [[ ${TEST_TAG} == *WEEKLY ]];
75         then
76             echo Downloading latest DPDK packages from repo...
77             DPDK_STABLE_VER=$(wget --no-check-certificate --quiet -O - ${DPDK_REPO} | \
78                 grep -v '2015' | grep -Eo 'dpdk-[^\"]+xz' | tail -1)
79         else
80             echo Downloading DPDK packages of specific version from repo...
81             DPDK_STABLE_VER='dpdk-18.05.tar.xz'
82         fi
83         wget --no-check-certificate --quiet ${DPDK_REPO}${DPDK_STABLE_VER}
84         ;;
85     *)
86         echo "Unable to identify dut type based on JOB_NAME variable: ${JOB_NAME}"
87         exit 1
88         ;;
89 esac
90
91
92 # ENVIRONMENT PREPARATION
93 virtualenv --system-site-packages env
94 . env/bin/activate
95 pip install -r requirements.txt
96
97 # We iterate over available topologies and wait until we reserve topology
98 while :; do
99     for TOPOLOGY in ${TOPOLOGIES};
100     do
101         python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -t ${TOPOLOGY}
102         if [ $? -eq 0 ]; then
103             WORKING_TOPOLOGY=${TOPOLOGY}
104             echo "Reserved: ${WORKING_TOPOLOGY}"
105             break
106         fi
107     done
108
109     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
110         # Exit the infinite while loop if we made a reservation
111         break
112     fi
113
114     # Wait ~3minutes before next try
115     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
116     echo "Sleeping ${SLEEP_TIME}"
117     sleep ${SLEEP_TIME}
118 done
119
120 #for DPDK test, we don't need to install the VPP deb
121 function cancel_all {
122     python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -c -t $1
123 }
124
125 # On script exit we cancel the reservation
126 trap "cancel_all ${WORKING_TOPOLOGY}" EXIT
127
128 # CSIT EXECUTION
129 PYBOT_ARGS="--consolewidth 100 \
130             --loglevel TRACE \
131             --variable TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
132             --suite tests.${DUT}.perf"
133
134 case "$TEST_TAG" in
135     # select specific performance tests based on jenkins job type variable
136     PERFTEST_MRR_DAILY )
137        TAGS=('mrrAND64bAND1c'
138              'mrrAND64bAND2c'
139              'mrrAND64bAND4c'
140              'mrrAND78bAND1c'
141              'mrrAND78bAND2c'
142              'mrrAND78bAND4c'
143              'mrrANDimixAND1c'
144              'mrrANDimixAND2c'
145              'mrrANDimixAND4c')
146         ;;
147     VERIFY-PERF-PATCH )
148         if [[ -z "$TEST_TAG_STRING" ]]; then
149             # If nothing is specified, we will run pre-selected tests by
150             # following tags. Items of array will be concatenated by OR in Robot
151             # Framework.
152             TEST_TAG_ARRAY=('mrrANDnic_intel-x710AND1cAND64b')
153         else
154             # If trigger contains tags, split them into array.
155             TEST_TAG_ARRAY=(${TEST_TAG_STRING//:/ })
156         fi
157
158         TAGS=()
159
160         for TAG in "${TEST_TAG_ARRAY[@]}"; do
161             if [[ ${TAG} == "!"* ]]; then
162                 # Exclude tags are not prefixed.
163                 TAGS+=("${TAG}")
164             else
165                 # We will prefix with perftest to prevent running other tests
166                 # (e.g. Functional).
167                 prefix="perftestAND"
168                 if [[ ${JOB_NAME} == vpp-* ]] ; then
169                     # Automatic prefixing for VPP jobs to limit the NIC used and
170                     # traffic evaluation to MRR.
171                     prefix="${prefix}mrrANDnic_intel-x710AND"
172                 fi
173                 TAGS+=("$prefix${TAG}")
174             fi
175         done
176         ;;
177     * )
178         TAGS=('perftest')
179 esac
180
181 # Catenate TAG selections
182 EXPANDED_TAGS=()
183 for TAG in "${TAGS[@]}"; do
184     if [[ ${TAG} == "!"* ]]; then
185         EXPANDED_TAGS+=(" --exclude ${TAG#$"!"} ")
186     else
187         EXPANDED_TAGS+=(" --include ${TOPOLOGIES_TAGS}AND${TAG} ")
188     fi
189 done
190
191 # Execute the test
192 pybot ${PYBOT_ARGS}${EXPANDED_TAGS[@]} tests/
193 RETURN_STATUS=$(echo $?)
194
195 # Archive JOB artifacts in jenkins
196 for i in ${JOB_ARCHIVE_ARTIFACTS[@]}; do
197     cp $( readlink -f ${i} | tr '\n' ' ' ) ${JOB_ARCHIVE_DIR}/
198 done
199 # Archive JOB artifacts to logs.fd.io
200 for i in ${LOG_ARCHIVE_ARTIFACTS[@]}; do
201     cp $( readlink -f ${i} | tr '\n' ' ' ) ${LOG_ARCHIVE_DIR}/
202 done
203
204 exit ${RETURN_STATUS}