Optimize performance bootstraps
[csit.git] / bootstrap-verify-perf-DPDK.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 -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
27 JOB_ARCHIVE_ARTIFACTS=(log.html output.xml report.html)
28 LOG_ARCHIVE_ARTIFACTS=(log.html output.xml report.html)
29 JOB_ARCHIVE_DIR="archive"
30 LOG_ARCHIVE_DIR="$WORKSPACE/archives"
31 mkdir -p ${JOB_ARCHIVE_DIR}
32 mkdir -p ${LOG_ARCHIVE_DIR}
33
34 # we will download the DPDK in the robot
35
36 WORKING_TOPOLOGY=""
37 export PYTHONPATH=${SCRIPT_DIR}
38
39 sudo apt-get -y update
40 sudo apt-get -y install libpython2.7-dev python-virtualenv
41
42 virtualenv --system-site-packages env
43 . env/bin/activate
44
45 echo pip install
46 pip install -r requirements.txt
47
48 # We iterate over available topologies and wait until we reserve topology
49 while :; do
50     for TOPOLOGY in ${TOPOLOGIES};
51     do
52         python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -t ${TOPOLOGY}
53         if [ $? -eq 0 ]; then
54             WORKING_TOPOLOGY=${TOPOLOGY}
55             echo "Reserved: ${WORKING_TOPOLOGY}"
56             break
57         fi
58     done
59
60     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
61         # Exit the infinite while loop if we made a reservation
62         break
63     fi
64
65     # Wait ~3minutes before next try
66     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
67     echo "Sleeping ${SLEEP_TIME}"
68     sleep ${SLEEP_TIME}
69 done
70
71 #for DPDK test, we don't need to install the VPP deb
72 function cancel_all {
73     python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -c -t $1
74 }
75
76 # On script exit we cancel the reservation
77 trap "cancel_all ${WORKING_TOPOLOGY}" EXIT
78
79 # Based on job we will identify DUT
80 if [[ ${JOB_NAME} == *hc2vpp* ]] ;
81 then
82     DUT="hc2vpp"
83 elif [[ ${JOB_NAME} == *vpp* ]] ;
84 then
85     DUT="vpp"
86 elif [[ ${JOB_NAME} == *ligato* ]] ;
87 then
88     DUT="kubernetes"
89 elif [[ ${JOB_NAME} == *dpdk* ]] ;
90 then
91     DUT="dpdk"
92 else
93     echo "Unable to identify dut type based on JOB_NAME variable: ${JOB_NAME}"
94     exit 1
95 fi
96
97 PYBOT_ARGS="--consolewidth 120 --loglevel TRACE --variable TOPOLOGY_PATH:${WORKING_TOPOLOGY} --suite tests.${DUT}.perf"
98
99 case "$TEST_TAG" in
100     # select specific performance tests based on jenkins job type variable
101     VERIFY-PERF-MRR )
102         TAGS=('mrrAND1t1c'
103               'mrrAND2t2c')
104         ;;
105     * )
106         TAGS=('perftest')
107 esac
108
109 # Catenate TAG selections by 'OR'
110 printf -v INCLUDES " --include %s " "${TAGS[@]}"
111
112 # Execute the test
113 pybot ${PYBOT_ARGS}${INCLUDES} tests/
114 RETURN_STATUS=$(echo $?)
115
116 # Archive JOB artifacts in jenkins
117 for i in ${JOB_ARCHIVE_ARTIFACTS[@]}; do
118     cp $( readlink -f ${i} | tr '\n' ' ' ) ${JOB_ARCHIVE_DIR}/
119 done
120 # Archive JOB artifacts to logs.fd.io
121 for i in ${LOG_ARCHIVE_ARTIFACTS[@]}; do
122     cp $( readlink -f ${i} | tr '\n' ' ' ) ${LOG_ARCHIVE_DIR}/
123 done
124
125 exit ${RETURN_STATUS}