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