Add New Skylake topology files
[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/build-root
41     cd vpp/build-root
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 *.deb | tr '\n' ' ' )"
60     # Take vpp package and get the vpp version
61     VPP_STABLE_VER="$( expr match $(ls *.deb | head -n 1) 'vpp_\(.*\)_amd64.deb' )"
62
63     cd ${SCRIPT_DIR}
64
65 # If we run this script from vpp project we want to use local build
66 elif [[ ${JOB_NAME} == vpp-* ]] ;
67 then
68     mkdir -p vpp/build-root
69     # Use local packages provided as argument list
70     # Jenkins VPP deb paths (convert to full path)
71     VPP_DEBS="$( readlink -f $@ | tr '\n' ' ' )"
72     # Take vpp package and get the vpp version
73     VPP_STABLE_VER="$( expr match $1 'vpp-\(.*\)-deb.deb' )"
74     # Move files to build-root for packing
75     for deb in ${VPP_DEBS}; do mv ${deb} vpp/build-root/; done
76 else
77     echo "Unable to identify job type based on JOB_NAME variable: ${JOB_NAME}"
78     exit 1
79 fi
80
81 # Extract VPP API to specific folder
82 dpkg -x vpp/build-root/vpp_${VPP_STABLE_VER}.deb /tmp/vpp
83 # Compress all VPP debs and remove temporary directory
84 tar -zcvf ${SCRIPT_DIR}/vpp.tar.gz vpp/* && rm -R vpp
85
86 LIGATO_REPO_URL=$(cat ${SCRIPT_DIR}/LIGATO_REPO_URL)
87 VPP_AGENT_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_AGENT_STABLE_VER)
88 DOCKER_DEB="docker-ce_18.03.0~ce-0~ubuntu_amd64.deb"
89
90 # Clone & checkout stable vnf-agent
91 cd .. && git clone ${LIGATO_REPO_URL}/vpp-agent
92 # If the git clone fails, complain clearly and exit
93 if [ $? != 0 ]; then
94     echo "Failed to run: git clone --depth 1 ${LIGATO_REPO_URL}/vpp-agent"
95     exit 1
96 fi
97 cd vpp-agent && git checkout ${VPP_AGENT_STABLE_VER}
98 # If the git checkout fails, complain clearly and exit
99 if [ $? != 0 ]; then
100     echo "Failed to run: git checkout ${VPP_AGENT_STABLE_VER}"
101     exit 1
102 fi
103
104 # Install Docker
105 wget -q https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/${DOCKER_DEB}
106 sudo dpkg -i ${DOCKER_DEB}
107 # If installation fails, complain clearly and exit
108 if [ $? != 0 ]; then
109     echo "Failed to install Docker"
110     exit 1
111 fi
112
113 # Pull ligato/dev_vpp_agent docker image and re-tag as local
114 sudo docker pull ligato/dev-vpp-agent:${VPP_AGENT_STABLE_VER}
115 sudo docker tag ligato/dev-vpp-agent:${VPP_AGENT_STABLE_VER}\
116     dev_vpp_agent:latest
117
118 # Start dev_vpp_agent container as daemon
119 sudo docker run --rm -itd --name agentcnt dev_vpp_agent bash
120 # Copy latest vpp api into running container
121 sudo docker cp /tmp/vpp/usr/share/vpp/api agentcnt:/usr/share/vpp
122 # Recompile vpp-agent
123 sudo docker exec -i agentcnt \
124     script -qec '. ~/.bashrc; cd /root/go/src/github.com/ligato/vpp-agent && make generate && make install'
125 if [ $? != 0 ]; then
126     echo "Failed to build vpp-agent in Docker image."
127     exit 1
128 fi
129 # Extract vpp-agent
130 rm -rf agent
131 mkdir -p agent
132 sudo docker cp agentcnt:/root/go/bin/vpp-agent agent/
133 sudo docker cp agentcnt:/root/go/bin/vpp-agent-ctl agent/
134 sudo docker cp agentcnt:/root/go/bin/agentctl agent/
135 tar -zcvf ${SCRIPT_DIR}/../vpp-agent/docker/prod_vpp_agent/agent.tar.gz agent
136 # Kill running container
137 sudo docker rm -f agentcnt
138
139 # Build prod_vpp_agent docker image
140 cd ${SCRIPT_DIR}/../vpp-agent/docker/prod_vpp_agent/ &&\
141     mv ${SCRIPT_DIR}/vpp.tar.gz . &&\
142     sudo docker build -t prod_vpp_agent --no-cache .
143 # Export Docker image
144 sudo docker save prod_vpp_agent | gzip > prod_vpp_agent.tar.gz
145 # If image build fails, complain clearly and exit
146 if [ $? != 0 ]; then
147     echo "Failed to build vpp-agent Docker image."
148     exit 1
149 fi
150 DOCKER_IMAGE="$( readlink -f prod_vpp_agent.tar.gz | tr '\n' ' ' )"
151
152 cd ${SCRIPT_DIR}
153
154 WORKING_TOPOLOGY=""
155
156 sudo apt-get -y update
157 sudo apt-get -y install libpython2.7-dev python-virtualenv
158
159 virtualenv --system-site-packages env
160 . env/bin/activate
161
162 echo pip install
163 pip install -r requirements.txt
164
165 # We iterate over available topologies and wait until we reserve topology
166 while :; do
167     for TOPOLOGY in ${TOPOLOGIES};
168     do
169         python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -t ${TOPOLOGY}
170         if [ $? -eq 0 ]; then
171             WORKING_TOPOLOGY=${TOPOLOGY}
172             echo "Reserved: ${WORKING_TOPOLOGY}"
173             break
174         fi
175     done
176
177     if [ ! -z "${WORKING_TOPOLOGY}" ]; then
178         # Exit the infinite while loop if we made a reservation
179         break
180     fi
181
182     # Wait ~3minutes before next try
183     SLEEP_TIME=$[ ( $RANDOM % 20 ) + 180 ]s
184     echo "Sleeping ${SLEEP_TIME}"
185     sleep ${SLEEP_TIME}
186 done
187
188 function cancel_all {
189     python ${SCRIPT_DIR}/resources/tools/scripts/topo_container_copy.py -c -d ${INSTALLATION_DIR} -t $1
190     python ${SCRIPT_DIR}/resources/tools/scripts/topo_reservation.py -c -t $1
191 }
192
193 # On script exit we cancel the reservation and installation and delete all vpp
194 # packages
195 trap "cancel_all ${WORKING_TOPOLOGY}" EXIT
196
197 python ${SCRIPT_DIR}/resources/tools/scripts/topo_container_copy.py \
198     -t ${WORKING_TOPOLOGY} -d ${INSTALLATION_DIR} -i ${DOCKER_IMAGE}
199 if [ $? -eq 0 ]; then
200     echo "Docker image copied and loaded on hosts from: ${WORKING_TOPOLOGY}"
201 else
202     echo "Failed to copy and load Docker image to DUTs"
203     exit 1
204 fi
205
206 # Based on job we will identify DUT
207 if [[ ${JOB_NAME} == *hc2vpp* ]] ;
208 then
209     DUT="hc2vpp"
210 elif [[ ${JOB_NAME} == *vpp* ]] ;
211 then
212     DUT="vpp"
213 elif [[ ${JOB_NAME} == *ligato* ]] ;
214 then
215     DUT="kubernetes"
216 elif [[ ${JOB_NAME} == *dpdk* ]] ;
217 then
218     DUT="dpdk"
219 else
220     echo "Unable to identify dut type based on JOB_NAME variable: ${JOB_NAME}"
221     exit 1
222 fi
223
224 PYBOT_ARGS="--consolewidth 120 --loglevel TRACE --variable TOPOLOGY_PATH:${WORKING_TOPOLOGY} --suite tests.${DUT}.perf"
225
226 case "$TEST_TAG" in
227     # select specific performance tests based on jenkins job type variable
228     PERFTEST_DAILY )
229         TAGS=('ndrdiscANDnic_intel-x520-da2AND1t1c'
230               'ndrdiscANDnic_intel-x520-da2AND2t2c'
231               'ndrdiscAND1t1cANDipsec'
232               'ndrdiscAND2t2cANDipsec')
233         ;;
234     PERFTEST_SEMI_WEEKLY )
235         TAGS=('ndrdiscANDnic_intel-x710AND1t1c'
236               'ndrdiscANDnic_intel-x710AND2t2c'
237               'ndrdiscANDnic_intel-xl710AND1t1c'
238               'ndrdiscANDnic_intel-xl710AND2t2c')
239         ;;
240     PERFTEST_MRR_DAILY )
241        TAGS=('mrrAND64bAND1t1c'
242              'mrrAND64bAND2t2c'
243              'mrrAND64bAND4t4c'
244              'mrrAND78bAND1t1c'
245              'mrrAND78bAND2t2c'
246              'mrrAND78bAND4t4c'
247              'mrrANDimixAND1t1cANDvhost'
248              'mrrANDimixAND2t2cANDvhost'
249              'mrrANDimixAND4t4cANDvhost'
250              'mrrANDimixAND1t1cANDmemif'
251              'mrrANDimixAND2t2cANDmemif'
252              'mrrANDimixAND4t4cANDmemif')
253         ;;
254     VERIFY-PERF-PATCH )
255         if [[ -z "$TEST_TAG_STRING" ]]; then
256             # If nothing is specified, we will run pre-selected tests by
257             # following tags. Items of array will be concatenated by OR in Robot
258             # Framework.
259             TEST_TAG_ARRAY=('mrrANDnic_intel-x710AND1t1cAND64bANDip4base'
260                             'mrrANDnic_intel-x710AND1t1cAND78bANDip6base'
261                             'mrrANDnic_intel-x710AND1t1cAND64bANDl2bdbase')
262         else
263             # If trigger contains tags, split them into array.
264             TEST_TAG_ARRAY=(${TEST_TAG_STRING//:/ })
265         fi
266
267         TAGS=()
268
269         for TAG in "${TEST_TAG_ARRAY[@]}"; do
270             if [[ ${TAG} == "!"* ]]; then
271                 # Exclude tags are not prefixed.
272                 TAGS+=("${TAG}")
273             else
274                 # We will prefix with perftest to prevent running other tests
275                 # (e.g. Functional).
276                 prefix="perftestAND"
277                 if [[ ${JOB_NAME} == vpp-* ]] ; then
278                     # Automatic prefixing for VPP jobs to limit the NIC used and
279                     # traffic evaluation to MRR.
280                     prefix="${prefix}mrrANDnic_intel-x710AND"
281                 fi
282                 TAGS+=("$prefix${TAG}")
283             fi
284         done
285         ;;
286     * )
287         TAGS=('perftest')
288 esac
289
290 # Catenate TAG selections
291 EXPANDED_TAGS=()
292 for TAG in "${TAGS[@]}"; do
293     if [[ ${TAG} == "!"* ]]; then
294         EXPANDED_TAGS+=(" --exclude ${TAG#$"!"} ")
295     else
296         EXPANDED_TAGS+=(" --include ${TAG} ")
297     fi
298 done
299
300 # Execute the test
301 pybot ${PYBOT_ARGS}${EXPANDED_TAGS[@]} tests/
302 RETURN_STATUS=$(echo $?)
303
304 # Archive JOB artifacts in jenkins
305 for i in ${JOB_ARCHIVE_ARTIFACTS[@]}; do
306     cp $( readlink -f ${i} | tr '\n' ' ' ) ${JOB_ARCHIVE_DIR}/
307 done
308 # Archive JOB artifacts to logs.fd.io
309 for i in ${LOG_ARCHIVE_ARTIFACTS[@]}; do
310     cp $( readlink -f ${i} | tr '\n' ' ' ) ${LOG_ARCHIVE_DIR}/
311 done
312
313 exit ${RETURN_STATUS}