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