Source data
[csit.git] / bootstrap-verify-perf-ligato.sh
1 #!/bin/bash
2 # Copyright (c) 2017 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 -xo pipefail
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 -L TRACE"
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 -p vpp/build-root
36     cd vpp/build-root
37
38     if [[ ${TEST_TAG} == *NIGHTLY ]] || \
39        [[ ${TEST_TAG} == *DAILY ]] || \
40        [[ ${TEST_TAG} == *WEEKLY ]];
41     then
42         # Download the latest VPP build .deb install packages
43         echo Downloading VPP packages...
44         bash ${SCRIPT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh --skip-install
45
46         VPP_DEBS="$( readlink -f *.deb | tr '\n' ' ' )"
47         # Take vpp package and get the vpp version
48         VPP_STABLE_VER="$( expr match $(ls *.deb | head -n 1) 'vpp-\(.*\)-deb.deb' )"
49     else
50         DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)_amd64
51         VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_UBUNTU)
52         VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_UBUNTU)
53         VPP_CLASSIFIER="-deb"
54         # Download vpp build from nexus and set VPP_DEBS variable
55         wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
56         wget -q "${VPP_REPO_URL}/vpp-dbg/${VPP_STABLE_VER}/vpp-dbg-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
57         wget -q "${VPP_REPO_URL}/vpp-dev/${VPP_STABLE_VER}/vpp-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
58         # Temporary disable using dpdk
59         # wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${DPDK_STABLE_VER}/vpp-dpdk-dkms-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
60         wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
61         wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
62         VPP_DEBS="$( readlink -f *.deb | tr '\n' ' ' )"
63     fi
64
65     # Temporary workaround as ligato docker file requires specific file name
66     rename -v 's/^(.*)-(\d.*)-deb.deb/$1_$2.deb/' *.deb
67     cd ${SCRIPT_DIR}
68
69 # If we run this script from vpp project we want to use local build
70 elif [[ ${JOB_NAME} == vpp-* ]] ;
71 then
72     mkdir -p vpp/build-root
73     # Use local packages provided as argument list
74     # Jenkins VPP deb paths (convert to full path)
75     VPP_DEBS="$( readlink -f $@ | tr '\n' ' ' )"
76     # Take vpp package and get the vpp version
77     VPP_STABLE_VER="$( expr match $1 'vpp-\(.*\)-deb.deb' )"
78     # Move files to build-root for packing
79     for deb in ${VPP_DEBS}; do mv ${deb} vpp/build-root/; done
80 else
81     echo "Unable to identify job type based on JOB_NAME variable: ${JOB_NAME}"
82     exit 1
83 fi
84 dpkg -x vpp/build-root/vpp_${VPP_STABLE_VER}.deb /tmp/vpp
85
86 # Compress all VPP debs and remove temporary directory
87 tar -zcvf ${SCRIPT_DIR}/vpp.tar.gz vpp/* && rm -R vpp
88
89 LIGATO_REPO_URL=$(cat ${SCRIPT_DIR}/LIGATO_REPO_URL)
90 VPP_AGENT_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_AGENT_STABLE_VER)
91 VPP_AGENT_STABLE_COMMIT="$( expr match `cat VPP_AGENT_STABLE_VER` '.*g\(.*\)' )"
92 DOCKER_DEB="docker-ce_17.09.0~ce-0~ubuntu_amd64.deb"
93
94 # Clone & checkout stable vnf-agent
95 cd .. && git clone ${LIGATO_REPO_URL}/vpp-agent
96 # If the git clone fails, complain clearly and exit
97 if [ $? != 0 ]; then
98     echo "Failed to run: git clone --depth 1 ${LIGATO_REPO_URL}/vpp-agent"
99     exit 1
100 fi
101 cd vpp-agent && git checkout ${VPP_AGENT_STABLE_COMMIT}
102 # If the git checkout fails, complain clearly and exit
103 if [ $? != 0 ]; then
104     echo "Failed to run: git checkout ${VPP_AGENT_STABLE_VER}"
105     exit 1
106 fi
107
108 # Install Docker
109 wget -q https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/${DOCKER_DEB}
110 sudo dpkg -i ${DOCKER_DEB}
111 # If installation fails, complain clearly and exit
112 if [ $? != 0 ]; then
113     echo "Failed to install Docker"
114     exit 1
115 fi
116
117 # Pull ligato/dev_vpp_agent docker image and re-tag as local
118 if [[ ${VPP_AGENT_STABLE_VER} == g* ]] ;
119 then
120     sudo docker pull ligato/dev-vpp-agent:${VPP_AGENT_STABLE_COMMIT}
121     sudo docker tag ligato/dev-vpp-agent:${VPP_AGENT_STABLE_COMMIT}\
122         dev_vpp_agent:latest
123 else
124     sudo docker pull ligato/dev-vpp-agent:${VPP_AGENT_STABLE_VER}
125     sudo docker tag ligato/dev-vpp-agent:${VPP_AGENT_STABLE_VER}\
126         dev_vpp_agent:latest
127 fi
128 sudo docker images
129 # Start dev_vpp_agent container as daemon
130 sudo docker run --rm -itd --name agentcnt dev_vpp_agent bash
131 # Copy latest vpp api into running container
132 sudo docker cp /tmp/vpp/usr/share/vpp/api agentcnt:/usr/share/vpp
133 # Recompile vpp-agent
134 sudo docker exec -i agentcnt \
135     script -qec '. ~/.bashrc; cd /root/go/src/github.com/ligato/vpp-agent && make generate && make install'
136 if [ $? != 0 ]; then
137     echo "Failed to build vpp-agent in Docker image."
138     exit 1
139 fi
140 # Extract vpp-agent
141 rm -rf agent
142 mkdir -p agent
143 sudo docker cp agentcnt:/root/go/bin/vpp-agent agent/
144 sudo docker cp agentcnt:/root/go/bin/vpp-agent-ctl agent/
145 sudo docker cp agentcnt:/root/go/bin/agentctl agent/
146 tar -zcvf ${SCRIPT_DIR}/../vpp-agent/docker/prod_vpp_agent/agent.tar.gz agent
147 # Kill running container
148 sudo docker rm -f agentcnt
149
150 # Build prod_vpp_agent docker image
151 cd ${SCRIPT_DIR}/../vpp-agent/docker/prod_vpp_agent/ &&\
152     mv ${SCRIPT_DIR}/vpp.tar.gz . &&\
153     sudo docker build -t prod_vpp_agent --no-cache .
154 # Export Docker image
155 sudo docker save prod_vpp_agent | gzip > prod_vpp_agent.tar.gz
156 # If image build fails, complain clearly and exit
157 if [ $? != 0 ]; then
158     echo "Failed to build vpp-agent Docker image."
159     exit 1
160 fi
161 DOCKER_IMAGE="$( readlink -f prod_vpp_agent.tar.gz | tr '\n' ' ' )"
162
163 cd ${SCRIPT_DIR}
164
165 sudo apt-get -y update
166 sudo apt-get -y install libpython2.7-dev python-virtualenv
167
168 WORKING_TOPOLOGY=""
169 export PYTHONPATH=${SCRIPT_DIR}
170
171 virtualenv --system-site-packages env
172 . env/bin/activate
173
174 echo pip install
175 pip install -r requirements.txt
176
177 # We iterate over available topologies and wait until we reserve topology
178 while :; do
179     for TOPOLOGY in ${TOPOLOGIES};
180     do
181         python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -t ${TOPOLOGY}
182         if [ $? -eq 0 ]; then
183             WORKING_TOPOLOGY=${TOPOLOGY}
184             echo "Reserved: ${WORKING_TOPOLOGY}"
185             break
186         fi
187     done
188
189     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
190         # Exit the infinite while loop if we made a reservation
191         break
192     fi
193
194     # Wait ~3minutes before next try
195     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
196     echo "Sleeping ${SLEEP_TIME}"
197     sleep ${SLEEP_TIME}
198 done
199
200 function cancel_all {
201     python ${SCRIPT_DIR}/resources/tools/scripts/topo_container_copy.py -c -d ${INSTALLATION_DIR} -t $1
202     python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -c -t $1
203 }
204
205 # On script exit we cancel the reservation and installation and delete all vpp
206 # packages
207 trap "cancel_all ${WORKING_TOPOLOGY}" EXIT
208
209 python ${SCRIPT_DIR}/resources/tools/scripts/topo_container_copy.py\
210     -t ${WORKING_TOPOLOGY} -d ${INSTALLATION_DIR} -i ${DOCKER_IMAGE}
211 if [ $? -eq 0 ]; then
212     echo "Docker image copied and loaded on hosts from: ${WORKING_TOPOLOGY}"
213 else
214     echo "Failed to copy and load Docker image to DUTs"
215     exit 1
216 fi
217
218 case "$TEST_TAG" in
219     # run specific performance tests based on jenkins job type variable
220     PERFTEST_DAILY )
221         pybot ${PYBOT_ARGS} \
222               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
223               -v DPDK_TEST:True \
224               -s "tests.kubernetes.perf" \
225               --include ndrdiscANDnic_intel-x520-da2AND1t1cORndrdiscANDnic_intel-x520-da2AND2t2c \
226               tests/
227         RETURN_STATUS=$(echo $?)
228         ;;
229     PERFTEST_SEMI_WEEKLY )
230         pybot ${PYBOT_ARGS} \
231               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
232               -v DPDK_TEST:True \
233               -s "tests.kubernetes.perf" \
234               --include ndrdiscANDnic_intel-x710AND1t1cORndrdiscANDnic_intel-x710AND2t2cORndrdiscANDnic_intel-xl710AND1t1cORndrdiscANDnic_intel-xl710AND2t2c \
235               tests/
236         RETURN_STATUS=$(echo $?)
237         ;;
238     VERIFY-PERF-NDRDISC )
239         pybot ${PYBOT_ARGS} \
240               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
241               -v DPDK_TEST:True \
242               -s "tests.kubernetes.perf" \
243               --include ndrdiscAND1t1cORndrdiscAND2t2c \
244               tests/
245         RETURN_STATUS=$(echo $?)
246         ;;
247     VERIFY-PERF-PDRDISC )
248         pybot ${PYBOT_ARGS} \
249               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
250               -v DPDK_TEST:True \
251               -s "tests.kubernetes.perf" \
252               --include pdrdiscAND1t1cORpdrdiscAND2t2c \
253               tests/
254         RETURN_STATUS=$(echo $?)
255         ;;
256     VERIFY-PERF-NDRCHK )
257         pybot ${PYBOT_ARGS} \
258               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
259               -v DPDK_TEST:True \
260               -s "tests.kubernetes.perf" \
261               --include ndrchkAND1t1cORndrchkAND2t2c \
262               tests/
263         RETURN_STATUS=$(echo $?)
264         ;;
265     PERFTEST_NDRCHK_DAILY )
266         pybot ${PYBOT_ARGS} \
267               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
268               -v DPDK_TEST:True \
269               -s "tests.kubernetes.perf" \
270               --include ndrchkAND1t1cORndrchkAND2t2c \
271               tests/
272         RETURN_STATUS=$(echo $?)
273         ;;
274     VERIFY-PERF-IP4 )
275         pybot ${PYBOT_ARGS} \
276               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
277               -v DPDK_TEST:True \
278               -s "tests.kubernetes.perf" \
279               --include ndrdiscANDnic_intel-x520-da2AND1t1cANDip4baseORndrdiscANDnic_intel-x520-da2AND1t1cANDip4fwdANDfib_2m \
280               tests/
281         RETURN_STATUS=$(echo $?)
282         ;;
283     VERIFY-PERF-IP6 )
284         pybot ${PYBOT_ARGS} \
285               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
286               -v DPDK_TEST:True \
287               -s "tests.kubernetes.perf" \
288               --include ndrdiscANDnic_intel-x520-da2AND1t1cANDip6baseORndrdiscANDnic_intel-x520-da2AND1t1cANDip6fwdANDfib_2m \
289               tests/
290         RETURN_STATUS=$(echo $?)
291         ;;
292     VERIFY-PERF-L2 )
293         pybot ${PYBOT_ARGS} \
294               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
295               -v DPDK_TEST:True \
296               -s "tests.kubernetes.perf" \
297               --include ndrdiscANDnic_intel-x520-da2AND1t1cANDl2xcbaseORndrdiscANDnic_intel-x520-da2AND1t1cANDl2bdbase \
298               tests/
299         RETURN_STATUS=$(echo $?)
300         ;;
301     VERIFY-PERF-LISP )
302         pybot ${PYBOT_ARGS} \
303               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
304               -v DPDK_TEST:True \
305               -s "tests.kubernetes.perf" \
306               --include ndrdiscANDnic_intel-x520-da2AND1t1cANDlisp \
307               tests/
308         RETURN_STATUS=$(echo $?)
309         ;;
310     VERIFY-PERF-VXLAN )
311         pybot ${PYBOT_ARGS} \
312               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
313               -v DPDK_TEST:True \
314               -s "tests.kubernetes.perf" \
315               --include ndrdiscANDnic_intel-x520-da2AND1t1cANDvxlan \
316               tests/
317         RETURN_STATUS=$(echo $?)
318         ;;
319     VERIFY-PERF-VHOST )
320         pybot ${PYBOT_ARGS} \
321               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
322               -v DPDK_TEST:True \
323               -s "tests.kubernetes.perf" \
324               --include ndrdiscANDnic_intel-x520-da2AND1t1cANDvhost \
325               tests/
326         RETURN_STATUS=$(echo $?)
327         ;;
328     VPP-VERIFY-PERF-IP4 )
329         pybot ${PYBOT_ARGS} \
330               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
331               -v DPDK_TEST:True \
332               -s "tests.kubernetes.perf" \
333               --include pdrchkANDnic_intel-x520-da2AND1t1cANDip4baseORpdrchkANDnic_intel-x520-da2AND1t1cANDip4fwdANDfib_2m \
334               tests/
335         RETURN_STATUS=$(echo $?)
336         ;;
337     VPP-VERIFY-PERF-IP6 )
338         pybot ${PYBOT_ARGS} \
339               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
340               -v DPDK_TEST:True \
341               -s "tests.kubernetes.perf" \
342               --include pdrchkANDnic_intel-x520-da2AND1t1cANDip6baseORpdrchkANDnic_intel-x520-da2AND1t1cANDip6fwdANDfib_2m \
343               tests/
344         RETURN_STATUS=$(echo $?)
345         ;;
346     VPP-VERIFY-PERF-L2 )
347         pybot ${PYBOT_ARGS} \
348               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
349               -v DPDK_TEST:True \
350               -s "tests.kubernetes.perf" \
351               --include pdrchkANDnic_intel-x520-da2AND1t1cANDl2xcbaseORpdrchkANDnic_intel-x520-da2AND1t1cANDl2bdbase \
352               tests/
353         RETURN_STATUS=$(echo $?)
354         ;;
355     VPP-VERIFY-PERF-LISP )
356         pybot ${PYBOT_ARGS} \
357               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
358               -v DPDK_TEST:True \
359               -s "tests.kubernetes.perf" \
360               --include pdrchkANDnic_intel-x520-da2AND1t1cANDlisp \
361               tests/
362         RETURN_STATUS=$(echo $?)
363         ;;
364     VPP-VERIFY-PERF-VXLAN )
365         pybot ${PYBOT_ARGS} \
366               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
367               -v DPDK_TEST:True \
368               -s "tests.kubernetes.perf" \
369               --include pdrchkANDnic_intel-x520-da2AND1t1cANDvxlan \
370               tests/
371         RETURN_STATUS=$(echo $?)
372         ;;
373     VPP-VERIFY-PERF-VHOST )
374         pybot ${PYBOT_ARGS} \
375               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
376               -v DPDK_TEST:True \
377               -s "tests.kubernetes.perf" \
378               --include pdrdiscANDnic_intel-x520-da2AND1t1cANDvhost \
379               tests/
380         RETURN_STATUS=$(echo $?)
381         ;;
382     VPP-VERIFY-PERF-ACL )
383         pybot ${PYBOT_ARGS} \
384               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
385               -v DPDK_TEST:True \
386               -s "tests.kubernetes.perf" \
387               --include pdrdiscANDnic_intel-x520-da2AND1t1cANDacl \
388               --include pdrdiscANDnic_intel-x520-da2AND2t2cANDacl \
389               tests/
390         RETURN_STATUS=$(echo $?)
391         ;;
392     PERFTEST_LONG )
393         pybot ${PYBOT_ARGS} \
394               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
395               -v DPDK_TEST:True \
396               -s "tests.kubernetes.perf" \
397               --exclude SKIP_PATCH \
398               -i NDRPDRDISC \
399               tests/
400         RETURN_STATUS=$(echo $?)
401         ;;
402     PERFTEST_SHORT )
403         pybot ${PYBOT_ARGS} \
404               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
405               -v DPDK_TEST:True \
406               -s "tests.kubernetes.perf" \
407               -i NDRCHK \
408               tests/
409         RETURN_STATUS=$(echo $?)
410         ;;
411     PERFTEST_NIGHTLY )
412         #run all available tests
413         pybot ${PYBOT_ARGS} \
414               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
415               -v DPDK_TEST:True \
416               -s "tests.kubernetes.perf" \
417               tests/
418         RETURN_STATUS=$(echo $?)
419         ;;
420     * )
421         # run full performance test suite and exit on fail
422         pybot ${PYBOT_ARGS} \
423               -v TOPOLOGY_PATH:${WORKING_TOPOLOGY} \
424               -v DPDK_TEST:True \
425               -s "tests.kubernetes.perf" \
426               tests/
427         RETURN_STATUS=$(echo $?)
428 esac
429
430 # Pybot output post-processing
431 echo Post-processing test data...
432
433 python ${SCRIPT_DIR}/resources/tools/scripts/robot_output_parser.py \
434        -i ${SCRIPT_DIR}/output.xml \
435        -o ${SCRIPT_DIR}/output_perf_data.xml \
436        -v ${VPP_STABLE_VER}
437 if [ ! $? -eq 0 ]; then
438     echo "Parsing ${SCRIPT_DIR}/output.xml failed"
439 fi
440
441 # Archive artifacts
442 mkdir -p archive
443 for i in ${ARCHIVE_ARTIFACTS[@]}; do
444     cp $( readlink -f ${i} | tr '\n' ' ' ) archive/
445 done
446
447 echo Post-processing finished.
448
449 exit ${RETURN_STATUS}