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