b704bfd32ec86a5e642145ef9820b11664d28ea0
[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 # We iterate over available topologies and wait until we reserve topology
151 while :; do
152     for TOPOLOGY in ${TOPOLOGIES};
153     do
154         python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -t ${TOPOLOGY}
155         if [ $? -eq 0 ]; then
156             WORKING_TOPOLOGY=${TOPOLOGY}
157             echo "Reserved: ${WORKING_TOPOLOGY}"
158             break
159         fi
160     done
161
162     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
163         # Exit the infinite while loop if we made a reservation
164         break
165     fi
166
167     # Wait ~3minutes before next try
168     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
169     echo "Sleeping ${SLEEP_TIME}"
170     sleep ${SLEEP_TIME}
171 done
172
173 function cancel_all {
174     python ${SCRIPT_DIR}/resources/tools/scripts/topo_container_copy.py -c -d ${INSTALLATION_DIR} -t $1
175     python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -c -t $1
176 }
177
178 # On script exit we cancel the reservation and installation and delete all vpp
179 # packages
180 trap "cancel_all ${WORKING_TOPOLOGY}" EXIT
181
182 python ${SCRIPT_DIR}/resources/tools/scripts/topo_container_copy.py \
183     -t ${WORKING_TOPOLOGY} -d ${INSTALLATION_DIR} -i ${DOCKER_IMAGE}
184 if [ $? -eq 0 ]; then
185     echo "Docker image copied and loaded on hosts from: ${WORKING_TOPOLOGY}"
186 else
187     echo "Failed to copy and load Docker image to DUTs"
188     exit 1
189 fi
190
191 # Based on job we will identify DUT
192 if [[ ${JOB_NAME} == *hc2vpp* ]] ;
193 then
194     DUT="hc2vpp"
195 elif [[ ${JOB_NAME} == *vpp* ]] ;
196 then
197     DUT="vpp"
198 elif [[ ${JOB_NAME} == *ligato* ]] ;
199 then
200     DUT="kubernetes"
201 elif [[ ${JOB_NAME} == *dpdk* ]] ;
202 then
203     DUT="dpdk"
204 else
205     echo "Unable to identify dut type based on JOB_NAME variable: ${JOB_NAME}"
206     exit 1
207 fi
208
209 PYBOT_ARGS="--consolewidth 100 --loglevel TRACE --variable TOPOLOGY_PATH:${WORKING_TOPOLOGY} --suite tests.${DUT}.perf"
210
211 case "$TEST_TAG" in
212     # select specific performance tests based on jenkins job type variable
213     PERFTEST_DAILY )
214         TAGS=('ndrdiscANDnic_intel-x520-da2AND1c'
215               'ndrdiscANDnic_intel-x520-da2AND2c'
216               'ndrdiscAND1cANDipsec'
217               'ndrdiscAND2cANDipsec')
218         ;;
219     PERFTEST_SEMI_WEEKLY )
220         TAGS=('ndrdiscANDnic_intel-x710AND1c'
221               'ndrdiscANDnic_intel-x710AND2c'
222               'ndrdiscANDnic_intel-xl710AND1c'
223               'ndrdiscANDnic_intel-xl710AND2c')
224         ;;
225     PERFTEST_MRR_DAILY )
226        TAGS=('mrrAND64bAND1c'
227              'mrrAND64bAND2c'
228              'mrrAND64bAND4c'
229              'mrrAND78bAND1c'
230              'mrrAND78bAND2c'
231              'mrrAND78bAND4c'
232              'mrrANDimixAND1cANDvhost'
233              'mrrANDimixAND2cANDvhost'
234              'mrrANDimixAND4cANDvhost'
235              'mrrANDimixAND1cANDmemif'
236              'mrrANDimixAND2cANDmemif'
237              'mrrANDimixAND4cANDmemif')
238         ;;
239     VERIFY-PERF-PATCH )
240         if [[ -z "$TEST_TAG_STRING" ]]; then
241             # If nothing is specified, we will run pre-selected tests by
242             # following tags. Items of array will be concatenated by OR in Robot
243             # Framework.
244             TEST_TAG_ARRAY=('mrrANDnic_intel-x710AND1cAND64bANDip4base'
245                             'mrrANDnic_intel-x710AND1cAND78bANDip6base'
246                             'mrrANDnic_intel-x710AND1cAND64bANDl2bdbase')
247         else
248             # If trigger contains tags, split them into array.
249             TEST_TAG_ARRAY=(${TEST_TAG_STRING//:/ })
250         fi
251
252         TAGS=()
253
254         for TAG in "${TEST_TAG_ARRAY[@]}"; do
255             if [[ ${TAG} == "!"* ]]; then
256                 # Exclude tags are not prefixed.
257                 TAGS+=("${TAG}")
258             else
259                 # We will prefix with perftest to prevent running other tests
260                 # (e.g. Functional).
261                 prefix="perftestAND"
262                 if [[ ${JOB_NAME} == vpp-* ]] ; then
263                     # Automatic prefixing for VPP jobs to limit the NIC used and
264                     # traffic evaluation to MRR.
265                     prefix="${prefix}mrrANDnic_intel-x710AND"
266                 fi
267                 TAGS+=("$prefix${TAG}")
268             fi
269         done
270         ;;
271     * )
272         TAGS=('perftest')
273 esac
274
275 # Catenate TAG selections
276 EXPANDED_TAGS=()
277 for TAG in "${TAGS[@]}"; do
278     if [[ ${TAG} == "!"* ]]; then
279         EXPANDED_TAGS+=(" --exclude ${TAG#$"!"} ")
280     else
281         EXPANDED_TAGS+=(" --include ${TAG} ")
282     fi
283 done
284
285 # Execute the test
286 pybot ${PYBOT_ARGS}${EXPANDED_TAGS[@]} tests/
287 RETURN_STATUS=$(echo $?)
288
289 # Archive JOB artifacts in jenkins
290 for i in ${JOB_ARCHIVE_ARTIFACTS[@]}; do
291     cp $( readlink -f ${i} | tr '\n' ' ' ) ${JOB_ARCHIVE_DIR}/
292 done
293 # Archive JOB artifacts to logs.fd.io
294 for i in ${LOG_ARCHIVE_ARTIFACTS[@]}; do
295     cp $( readlink -f ${i} | tr '\n' ' ' ) ${LOG_ARCHIVE_DIR}/
296 done
297
298 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.