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