Fail bootstrap immediately if no topology found
[csit.git] / bootstrap-verify-perf-ligato.sh
1 #!/bin/bash
2 # Copyright (c) 2018 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_3n_hsw_testbed1.yaml \
19             topologies/available/lf_3n_hsw_testbed2.yaml \
20             topologies/available/lf_3n_hsw_testbed3.yaml"
21
22 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
23 export PYTHONPATH=${SCRIPT_DIR}
24 export DEBIAN_FRONTEND=noninteractive
25
26 # Reservation dir
27 RESERVATION_DIR="/tmp/reservation_dir"
28 INSTALLATION_DIR="/tmp/install_dir"
29
30 JOB_ARCHIVE_ARTIFACTS=(log.html output.xml report.html)
31 LOG_ARCHIVE_ARTIFACTS=(log.html output.xml report.html)
32 JOB_ARCHIVE_DIR="archive"
33 LOG_ARCHIVE_DIR="$WORKSPACE/archives"
34 mkdir -p ${JOB_ARCHIVE_DIR}
35 mkdir -p ${LOG_ARCHIVE_DIR}
36
37 # If we run this script from CSIT jobs we want to use stable vpp version
38 if [[ ${JOB_NAME} == csit-* ]] ;
39 then
40     mkdir -p vpp_download
41     cd vpp_download
42
43     if [[ ${TEST_TAG} == *DAILY ]] || \
44        [[ ${TEST_TAG} == *WEEKLY ]];
45     then
46         echo Downloading latest VPP packages from NEXUS...
47         bash ${SCRIPT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh \
48             --skip-install
49     else
50         echo Downloading VPP packages of specific version from NEXUS...
51         DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)
52         VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_UBUNTU)
53         #Temporary if arch will not be removed from VPP_STABLE_VER_UBUNTU
54         #VPP_STABLE_VER=${VPP_STABLE_VER%_amd64}
55         bash ${SCRIPT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh \
56             --skip-install --vpp ${VPP_STABLE_VER} --dkms ${DPDK_STABLE_VER}
57     fi
58     # Jenkins VPP deb paths (convert to full path)
59     VPP_DEBS="$( readlink -f vpp*.deb | tr '\n' ' ' )"
60     cd ${SCRIPT_DIR}
61
62 # If we run this script from vpp project we want to use local build
63 elif [[ ${JOB_NAME} == vpp-* ]] ;
64 then
65     # Use local packages provided as argument list
66     # Jenkins VPP deb paths (convert to full path)
67     VPP_DEBS="$( readlink -f $@ | tr '\n' ' ' )"
68 else
69     echo "Unable to identify job type based on JOB_NAME variable: ${JOB_NAME}"
70     exit 1
71 fi
72
73 # Extract VPP API to specific folder
74 dpkg -x vpp_download/vpp_*.deb /tmp/vpp
75
76 LIGATO_REPO_URL='https://github.com/ligato/'
77 VPP_AGENT_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_AGENT_STABLE_VER)
78 DOCKER_DEB="docker-ce_18.03.0~ce-0~ubuntu_amd64.deb"
79
80 # Clone & checkout stable vnf-agent
81 cd .. && git clone -b ${VPP_AGENT_STABLE_VER} --single-branch \
82     ${LIGATO_REPO_URL}/vpp-agent vpp-agent
83 # If the git clone fails, complain clearly and exit
84 if [ $? != 0 ]; then
85     echo "Failed to run: git clone ${LIGATO_REPO_URL}/vpp-agent"
86     exit 1
87 fi
88 cd vpp-agent
89
90 # Install Docker
91 wget -q https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/${DOCKER_DEB}
92 sudo dpkg -i ${DOCKER_DEB}
93 # If installation fails, complain clearly and exit
94 if [ $? != 0 ]; then
95     echo "Failed to install Docker"
96     exit 1
97 fi
98
99 # Pull ligato/dev_vpp_agent docker image and re-tag as local
100 sudo docker pull ligato/dev-vpp-agent:${VPP_AGENT_STABLE_VER}
101 sudo docker tag ligato/dev-vpp-agent:${VPP_AGENT_STABLE_VER}\
102     dev_vpp_agent:latest
103
104 # Start dev_vpp_agent container as daemon
105 sudo docker run --rm -itd --name agentcnt dev_vpp_agent bash
106
107 # Copy latest vpp api into running container
108 sudo docker cp /tmp/vpp/usr/share/vpp/api agentcnt:/usr/share/vpp
109 for f in ${SCRIPT_DIR}/vpp_download/*; do
110     sudo docker cp $f agentcnt:/opt/vpp-agent/dev/vpp/build-root/
111 done
112
113 # Recompile vpp-agent
114 sudo docker exec -i agentcnt \
115     script -qec '. ~/.bashrc; cd /go/src/github.com/ligato/vpp-agent && make generate && make install'
116 if [ $? != 0 ]; then
117     echo "Failed to build vpp-agent in Docker image."
118     exit 1
119 fi
120 # Save container state
121 sudo docker commit `sudo docker ps -q` dev_vpp_agent:latest
122
123 # Build prod_vpp_agent docker image
124 cd docker/prod/ &&\
125     sudo docker build --tag prod_vpp_agent --no-cache .
126 # Export Docker image
127 sudo docker save prod_vpp_agent | gzip > prod_vpp_agent.tar.gz
128 # Kill running agentcnt container
129 sudo docker rm -f agentcnt
130 # If image build fails, complain clearly and exit
131 if [ $? != 0 ]; then
132     echo "Failed to build vpp-agent Docker image."
133     exit 1
134 fi
135 DOCKER_IMAGE="$( readlink -f prod_vpp_agent.tar.gz | tr '\n' ' ' )"
136
137 cd ${SCRIPT_DIR}
138
139 WORKING_TOPOLOGY=""
140
141 sudo apt-get -y update
142 sudo apt-get -y install libpython2.7-dev python-virtualenv
143
144 virtualenv --system-site-packages env
145 . env/bin/activate
146
147 echo pip install
148 pip install -r requirements.txt
149
150 if [ -z "${TOPOLOGIES}" ]; then
151     echo "No applicable topology found!"
152     exit 1
153 fi
154 # We iterate over available topologies and wait until we reserve topology
155 while :; do
156     for TOPOLOGY in ${TOPOLOGIES};
157     do
158         python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -t ${TOPOLOGY}
159         if [ $? -eq 0 ]; then
160             WORKING_TOPOLOGY=${TOPOLOGY}
161             echo "Reserved: ${WORKING_TOPOLOGY}"
162             break
163         fi
164     done
165
166     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
167         # Exit the infinite while loop if we made a reservation
168         break
169     fi
170
171     # Wait ~3minutes before next try
172     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
173     echo "Sleeping ${SLEEP_TIME}"
174     sleep ${SLEEP_TIME}
175 done
176
177 function cancel_all {
178     python ${SCRIPT_DIR}/resources/tools/scripts/topo_container_copy.py -c -d ${INSTALLATION_DIR} -t $1
179     python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -c -t $1
180 }
181
182 # On script exit we cancel the reservation and installation and delete all vpp
183 # packages
184 trap "cancel_all ${WORKING_TOPOLOGY}" EXIT
185
186 python ${SCRIPT_DIR}/resources/tools/scripts/topo_container_copy.py \
187     -t ${WORKING_TOPOLOGY} -d ${INSTALLATION_DIR} -i ${DOCKER_IMAGE}
188 if [ $? -eq 0 ]; then
189     echo "Docker image copied and loaded on hosts from: ${WORKING_TOPOLOGY}"
190 else
191     echo "Failed to copy and load Docker image to DUTs"
192     exit 1
193 fi
194
195 # Based on job we will identify DUT
196 if [[ ${JOB_NAME} == *hc2vpp* ]] ;
197 then
198     DUT="hc2vpp"
199 elif [[ ${JOB_NAME} == *vpp* ]] ;
200 then
201     DUT="vpp"
202 elif [[ ${JOB_NAME} == *ligato* ]] ;
203 then
204     DUT="kubernetes"
205 elif [[ ${JOB_NAME} == *dpdk* ]] ;
206 then
207     DUT="dpdk"
208 else
209     echo "Unable to identify dut type based on JOB_NAME variable: ${JOB_NAME}"
210     exit 1
211 fi
212
213 PYBOT_ARGS="--consolewidth 100 --loglevel TRACE --variable TOPOLOGY_PATH:${WORKING_TOPOLOGY} --suite tests.${DUT}.perf"
214
215 case "$TEST_TAG" in
216     # select specific performance tests based on jenkins job type variable
217     PERFTEST_DAILY )
218         TAGS=('ndrdiscANDnic_intel-x520-da2AND1c'
219               'ndrdiscANDnic_intel-x520-da2AND2c'
220               'ndrdiscAND1cANDipsec'
221               'ndrdiscAND2cANDipsec')
222         ;;
223     PERFTEST_SEMI_WEEKLY )
224         TAGS=('ndrdiscANDnic_intel-x710AND1c'
225               'ndrdiscANDnic_intel-x710AND2c'
226               'ndrdiscANDnic_intel-xl710AND1c'
227               'ndrdiscANDnic_intel-xl710AND2c')
228         ;;
229     PERFTEST_MRR_DAILY )
230        TAGS=('mrrAND64bAND1c'
231              'mrrAND64bAND2c'
232              'mrrAND64bAND4c'
233              'mrrAND78bAND1c'
234              'mrrAND78bAND2c'
235              'mrrAND78bAND4c'
236              'mrrANDimixAND1cANDvhost'
237              'mrrANDimixAND2cANDvhost'
238              'mrrANDimixAND4cANDvhost'
239              'mrrANDimixAND1cANDmemif'
240              'mrrANDimixAND2cANDmemif'
241              'mrrANDimixAND4cANDmemif')
242         ;;
243     VERIFY-PERF-PATCH )
244         if [[ -z "$TEST_TAG_STRING" ]]; then
245             # If nothing is specified, we will run pre-selected tests by
246             # following tags. Items of array will be concatenated by OR in Robot
247             # Framework.
248             TEST_TAG_ARRAY=('mrrANDnic_intel-x710AND1cAND64bANDip4base'
249                             'mrrANDnic_intel-x710AND1cAND78bANDip6base'
250                             'mrrANDnic_intel-x710AND1cAND64bANDl2bdbase')
251         else
252             # If trigger contains tags, split them into array.
253             TEST_TAG_ARRAY=(${TEST_TAG_STRING//:/ })
254         fi
255
256         TAGS=()
257
258         for TAG in "${TEST_TAG_ARRAY[@]}"; do
259             if [[ ${TAG} == "!"* ]]; then
260                 # Exclude tags are not prefixed.
261                 TAGS+=("${TAG}")
262             else
263                 # We will prefix with perftest to prevent running other tests
264                 # (e.g. Functional).
265                 prefix="perftestAND"
266                 if [[ ${JOB_NAME} == vpp-* ]] ; then
267                     # Automatic prefixing for VPP jobs to limit the NIC used and
268                     # traffic evaluation to MRR.
269                     prefix="${prefix}mrrANDnic_intel-x710AND"
270                 fi
271                 TAGS+=("$prefix${TAG}")
272             fi
273         done
274         ;;
275     * )
276         TAGS=('perftest')
277 esac
278
279 # Catenate TAG selections
280 EXPANDED_TAGS=()
281 for TAG in "${TAGS[@]}"; do
282     if [[ ${TAG} == "!"* ]]; then
283         EXPANDED_TAGS+=(" --exclude ${TAG#$"!"} ")
284     else
285         EXPANDED_TAGS+=(" --include ${TAG} ")
286     fi
287 done
288
289 # Execute the test
290 pybot ${PYBOT_ARGS}${EXPANDED_TAGS[@]} tests/
291 RETURN_STATUS=$(echo $?)
292
293 # Archive JOB artifacts in jenkins
294 for i in ${JOB_ARCHIVE_ARTIFACTS[@]}; do
295     cp $( readlink -f ${i} | tr '\n' ' ' ) ${JOB_ARCHIVE_DIR}/
296 done
297 # Archive JOB artifacts to logs.fd.io
298 for i in ${LOG_ARCHIVE_ARTIFACTS[@]}; do
299     cp $( readlink -f ${i} | tr '\n' ' ' ) ${LOG_ARCHIVE_DIR}/
300 done
301
302 exit ${RETURN_STATUS}

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.