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