CSIT-395 Update TRex version to v2.09
[csit.git] / bootstrap-verify-perf.sh
1 #!/bin/bash
2 # Copyright (c) 2016 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 -x
16
17 # Space separated list of available testbeds, described by topology files
18 TOPOLOGIES="topologies/available/lf_testbed1.yaml \
19             topologies/available/lf_testbed2.yaml \
20             topologies/available/lf_testbed3.yaml"
21
22 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
23
24 VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER)
25 VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL)
26
27 # Reservation dir
28 RESERVATION_DIR="/tmp/reservation_dir"
29 INSTALLATION_DIR="/tmp/install_dir"
30
31 PYBOT_ARGS="-W 150"
32
33 ARCHIVE_ARTIFACTS=(log.html output.xml report.html output_perf_data.xml)
34
35 # If we run this script from CSIT jobs we want to use stable vpp version
36 if [[ ${JOB_NAME} == csit-* ]] ;
37 then
38     mkdir vpp_download
39     cd vpp_download
40
41     if [[ ${TEST_TAG} == "PERFTEST_NIGHTLY" ]] ;
42     then
43         # Download the latest VPP build .deb install packages
44         echo Downloading VPP packages...
45         bash ${SCRIPT_DIR}/resources/tools/download_install_vpp_pkgs.sh --skip-install
46
47         VPP_DEBS="$( readlink -f *.deb | tr '\n' ' ' )"
48
49     else
50         VPP_CLASSIFIER="-deb"
51         #download vpp build from nexus and set VPP_DEBS variable
52         wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
53         wget -q "${VPP_REPO_URL}/vpp-dbg/${VPP_STABLE_VER}/vpp-dbg-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
54         wget -q "${VPP_REPO_URL}/vpp-dev/${VPP_STABLE_VER}/vpp-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
55         wget -q "${VPP_REPO_URL}/vpp-dpdk-dev/${VPP_STABLE_VER}/vpp-dpdk-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
56         wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${VPP_STABLE_VER}/vpp-dpdk-dkms-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
57         wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
58         wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
59         VPP_DEBS="$( readlink -f *.deb | tr '\n' ' ' )"
60     fi
61
62     cd ..
63
64 # If we run this script from vpp project we want to use local build
65 elif [[ ${JOB_NAME} == vpp-* ]] ;
66 then
67     #use local packages provided as argument list
68     # Jenkins VPP deb paths (convert to full path)
69     VPP_DEBS="$( readlink -f $@ | tr '\n' ' ' )"
70 else
71     echo "Unable to identify job type based on JOB_NAME variable: ${JOB_NAME}"
72     exit 1
73 fi
74
75 WORKING_TOPOLOGY=""
76 export PYTHONPATH=${SCRIPT_DIR}
77
78 sudo apt-get -y update
79 sudo apt-get -y install libpython2.7-dev python-virtualenv
80
81 virtualenv --system-site-packages env
82 . env/bin/activate
83
84 echo pip install
85 pip install -r requirements.txt
86
87 # We iterate over available topologies and wait until we reserve topology
88 while :; do
89     for TOPOLOGY in ${TOPOLOGIES};
90     do
91         python ${SCRIPT_DIR}/resources/tools/topo_reservation.py -t ${TOPOLOGY}
92         if [ $? -eq 0 ]; then
93             WORKING_TOPOLOGY=${TOPOLOGY}
94             echo "Reserved: ${WORKING_TOPOLOGY}"
95             break
96         fi
97     done
98
99     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
100         # Exit the infinite while loop if we made a reservation
101         break
102     fi
103
104     # Wait ~3minutes before next try
105     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
106     echo "Sleeping ${SLEEP_TIME}"
107     sleep ${SLEEP_TIME}
108 done
109
110 function cancel_all {
111     python ${SCRIPT_DIR}/resources/tools/topo_installation.py -c -d ${INSTALLATION_DIR} -t $1
112     python ${SCRIPT_DIR}/resources/tools/topo_reservation.py -c -t $1
113 }
114
115 # On script exit we cancel the reservation and installation and delete all vpp
116 # packages
117 trap "cancel_all ${WORKING_TOPOLOGY}" EXIT
118
119 python ${SCRIPT_DIR}/resources/tools/topo_installation.py -t ${WORKING_TOPOLOGY} \
120                                                        -d ${INSTALLATION_DIR} \
121                                                        -p ${VPP_DEBS}
122 if [ $? -eq 0 ]; then
123     echo "VPP Installed on hosts from: ${WORKING_TOPOLOGY}"
124 else
125     echo "Failed to copy vpp deb files to DUTs"
126     exit 1
127 fi
128
129 case "$TEST_TAG" in
130     # run specific performance tests based on jenkins job type variable
131     PERFTEST_LONG )
132         pybot ${PYBOT_ARGS} \
133               -L TRACE \
134               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
135               -s "tests.perf" \
136               --exclude SKIP_PATCH \
137               -i perftest_long \
138               tests/
139         RETURN_STATUS=$(echo $?)
140         ;;
141     PERFTEST_SHORT )
142         pybot ${PYBOT_ARGS} \
143               -L TRACE \
144               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
145               -s "tests.perf" \
146               -i perftest_short \
147               tests/
148         RETURN_STATUS=$(echo $?)
149         ;;
150     PERFTEST_LONG_BRIDGE )
151         pybot ${PYBOT_ARGS} \
152               -L TRACE \
153               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
154               -s "tests.perf.Long_Bridge_Domain*" \
155               tests/
156         RETURN_STATUS=$(echo $?)
157         ;;
158     PERFTEST_LONG_IPV4 )
159         pybot ${PYBOT_ARGS} \
160               -L TRACE \
161               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
162               -s "tests.perf.Long_IPv4*" \
163               tests/
164         RETURN_STATUS=$(echo $?)
165         ;;
166     PERFTEST_LONG_IPV6 )
167         pybot ${PYBOT_ARGS} \
168               -L TRACE \
169               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
170               -s "tests.perf.Long_IPv6*" \
171               tests/
172         RETURN_STATUS=$(echo $?)
173         ;;
174     PERFTEST_LONG_XCONNECT )
175         pybot ${PYBOT_ARGS} \
176               -L TRACE \
177               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
178               -s "tests.perf.Long_Xconnect*" \
179               tests/
180         RETURN_STATUS=$(echo $?)
181         ;;
182     PERFTEST_LONG_XCONNECT_DOT1Q )
183         pybot ${PYBOT_ARGS} \
184               -L TRACE \
185               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
186               -s "tests.perf.Long_Xconnect_Dot1q*" \
187         RETURN_STATUS=$(echo $?)
188         ;;
189     PERFTEST_NDR )
190         pybot ${PYBOT_ARGS} \
191               -L TRACE \
192               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
193               -s "tests.perf" -i NDR \
194               tests/
195         RETURN_STATUS=$(echo $?)
196         ;;
197     PERFTEST_PDR )
198         pybot ${PYBOT_ARGS} \
199               -L TRACE \
200               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
201               -s "tests.perf" -i PDR \
202               tests/
203         RETURN_STATUS=$(echo $?)
204         ;;
205    PERFTEST_NIGHTLY )
206         #run all available tests
207         pybot ${PYBOT_ARGS} \
208               -L TRACE \
209               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
210               -s "tests.perf" \
211               tests/
212         RETURN_STATUS=$(echo $?)
213         ;;
214     * )
215         # run full performance test suite and exit on fail
216         pybot ${PYBOT_ARGS} \
217               -L TRACE \
218               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
219               -s "tests.perf" \
220               tests/
221         RETURN_STATUS=$(echo $?)
222 esac
223
224 # Pybot output post-processing
225 echo Post-processing test data...
226
227 python ${SCRIPT_DIR}/resources/tools/robot_output_parser.py \
228        -i ${SCRIPT_DIR}/output.xml \
229        -o ${SCRIPT_DIR}/output_perf_data.xml \
230        -v ${VPP_STABLE_VER}
231 if [ ! $? -eq 0 ]; then
232     echo "Parsing ${SCRIPT_DIR}/output.xml failed"
233 fi
234
235 # Archive artifacts
236 mkdir archive
237 for i in ${ARCHIVE_ARTIFACTS[@]}; do
238     cp $( readlink -f ${i} | tr '\n' ' ' ) archive/
239 done
240
241 echo Post-processing finished.
242
243 exit ${RETURN_STATUS}