Update of VPP_STABLE_VER files and DPDK_STABLE_VER file
[csit.git] / bootstrap-centos.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 -x
16
17 cat /etc/hostname
18 cat /etc/hosts
19
20 sudo yum install -y python-devel python-virtualenv
21
22 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
23
24 VIRL_USERNAME=jenkins-in
25 VIRL_PKEY=priv_key
26 VIRL_SERVER_STATUS_FILE="status"
27 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
28
29 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
30
31 VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_CENTOS)
32 VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_CENTOS)
33
34 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
35
36 TEST_GROUPS=("gre,ipv6,lisp,policer,rpf,softwire" "dhcp,ipsec,l2bd,l2xc,telemetry,vrf,vxlan" "cop,fds,honeycomb,iacl,ipv4,tap,vhost,vlan")
37 SUITE_PATH="tests.func"
38 SKIP_PATCH="SKIP_PATCH"
39
40 # Create tmp dir
41 mkdir ${SCRIPT_DIR}/tmp
42
43 # Use tmp dir to store log files
44 LOG_PATH="${SCRIPT_DIR}/tmp"
45
46 # Use tmp dir for tarballs
47 export TMPDIR="${SCRIPT_DIR}/tmp"
48
49 SHARED_MEMORY_PATH="/dev/shm"
50
51 function ssh_do() {
52     echo
53     echo "### "  ssh $@
54     ssh ${SSH_OPTIONS} $@
55 }
56
57 rm -f ${VIRL_PKEY}
58 cat > ${VIRL_PKEY} <<EOF
59 -----BEGIN RSA PRIVATE KEY-----
60 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
61 GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX
62 VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9
63 asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz
64 L3dM3iSmlmQlzv9bThjo+nI4KFYh6m5wrZmAo5r/4q9CIJc21HVnTqkGOWJIZz6J
65 73lePJVSq5gYqaoGw3swFEA/MDkOx7baWKSoLQIDAQABAoIBAQCNBeolNp+JWJ76
66 gQ4fwLsknyXSV6sxYyhkDW4PEwwcTU06uqce0AAzXVffxne0fMe48x47+zqBgPbb
67 4huM+Pu8B9nfojUMr5TaYtl9Zbgpk3F8H7dT7LKOa6XrxvZTZrADSRc30+Z26zPN
68 e9zTaf42Gvt0/l0Zs1BHwbaOXqO+XuwJ3/F9Sf3PQYWXD3EOWjpHDP/X/1vAs6lV
69 SLkm6J/9KKE1m6I6LTYjIXuYt4SXybW6N2TSy54hhQtYcDUnIU2hR/PHVWKrGA0J
70 kELgrtTNTdbML27O5gFWU4PLUEYTZ9fN11D6qUZKxLcPOiPPHXkiILMRCCnG5DYI
71 ksBAU/YlAoGBAPxZO9VO18TYc8THV1nLKcvT2+1oSs1UcA2wNQMU55t910ZYinRa
72 MRwUhMOf8Mv5wOeiZaRICQB1PnVWtDVmGECgPpK6jUxqAwn8rgJcnoafLGL5YKMY
73 RVafTe6N5LXgCaOcJrk21wxs6v7ninEbUxxc575urOvZMBkymDw91dwbAoGBAPwa
74 YRhKhrzFKZzdK0RadVjnxKvolUllpoqqg3XuvmeAJHAOAnaOgVWq68NAcp5FZJv0
75 2D2Up7TX8pjf9MofP1SJbcraKBpK4NzfNkA0dSdEi+FhVofAJ9umB2o5LW1n7sab
76 UIrjsdzSJK/9Zb9yTTHPyibYzNEgaJV1HsbxfEFXAoGAYO2RmvRm0phll18OQVJV
77 IpKk9kLKAKZ/R/K32hAsikBC8SVPQTPniyaifFWx81diblalff2hX4ipTf7Yx24I
78 wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS
79 NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
80 xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
81 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
82 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
83 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
84 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
85 -----END RSA PRIVATE KEY-----
86 EOF
87 chmod 600 ${VIRL_PKEY}
88
89 #
90 # Pick a random host from the array of VIRL servers for every test set run
91 # and attempt to reach it and verify it's status.
92 #
93 # The server must be reachable and have a "status" file with
94 # the content "PRODUCTION" to be selected.
95 #
96 # If the server is not reachable or does not have the correct
97 # status remove it from the array and start again.
98 #
99 # Abort if there are no more servers left in the array.
100 #
101 for index in "${!TEST_GROUPS[@]}"; do
102     VIRL_SERVER[${index}]=""
103     while [[ ! "${VIRL_SERVER[${index}]}" ]]; do
104         num_hosts=${#VIRL_SERVERS[@]}
105         if [ $num_hosts == 0 ]
106         then
107             echo "No more VIRL candidate hosts available, failing."
108             exit 127
109         fi
110         element=$[ $RANDOM % $num_hosts ]
111         virl_server_candidate=${VIRL_SERVERS[$element]}
112         virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1)
113         echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\"
114         if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
115         then
116             # Candidate is in good status. Select this server.
117             VIRL_SERVER[${index}]="$virl_server_candidate"
118         else
119             # Candidate is in bad status. Remove from array.
120             VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}")
121         fi
122     done
123 done
124
125 echo "Selected VIRL servers: ${VIRL_SERVER[@]}"
126
127 # Temporarily download VPP packages from nexus.fd.io
128 VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_CENTOS)
129 VPP_CLASSIFIER=""
130 if [ "${#}" -ne "0" ]; then
131     arr=(${@})
132     echo ${arr[0]}
133     SKIP_PATCH="skip_patchORskip_vpp_patch"
134 else
135     rm -f *.rpm
136     VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_CENTOS)
137     wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
138     wget -q "${VPP_REPO_URL}/vpp-debuginfo/${VPP_STABLE_VER}/vpp-debuginfo-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
139     wget -q "${VPP_REPO_URL}/vpp-devel/${VPP_STABLE_VER}/vpp-devel-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
140     wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
141     wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
142 fi
143
144 VPP_RPMS=(*.rpm)
145 echo ${VPP_RPMS[@]}
146 VIRL_DIR_LOC="/tmp"
147 VPP_RPMS_FULL=(${VPP_RPMS[@]})
148
149 # Prepend directory location at remote host to rpm list
150 for index in "${!VPP_RPMS_FULL[@]}"; do
151     VPP_RPMS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_RPMS_FULL[${index}]}
152 done
153
154 echo "Updated file names: " ${VPP_RPMS_FULL[@]}
155
156 cat ${VIRL_PKEY}
157
158 # Copy the files to VIRL hosts
159 DONE=""
160 for index in "${!VIRL_SERVER[@]}"; do
161     # Do not copy files in case they have already been copied to the VIRL host
162     [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1
163
164     if [ "${copy}" -eq "0" ]; then
165         echo "VPP rpms have already been copied to the VIRL host ${VIRL_SERVER[${index}]}"
166     else
167         scp ${SSH_OPTIONS} *.rpm \
168         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
169
170         result=$?
171         if [ "${result}" -ne "0" ]; then
172             echo "Failed to copy VPP rpms to VIRL host ${VIRL_SERVER[${index}]}"
173             echo ${result}
174             exit ${result}
175         else
176             echo "VPP rpms successfully copied to the VIRL host ${VIRL_SERVER[${index}]}"
177         fi
178         DONE+=(${VIRL_SERVER[${index}]})
179     fi
180 done
181
182 # Start a simulation on VIRL server
183
184 function stop_virl_simulation {
185     for index in "${!VIRL_SERVER[@]}"; do
186         ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\
187             "stop-testcase ${VIRL_SID[${index}]}"
188     done
189 }
190
191 # Upon script exit, cleanup the simulation execution
192 trap stop_virl_simulation EXIT
193
194 for index in "${!VIRL_SERVER[@]}"; do
195     echo "Starting simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}"
196     VIRL_SID[${index}]=$(ssh ${SSH_OPTIONS} \
197         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]} \
198         "start-testcase -vv --copy ${VIRL_TOPOLOGY} \
199         --release ${VIRL_RELEASE} ${VPP_RPMS_FULL[@]}")
200     retval=$?
201     if [ ${retval} -ne "0" ]; then
202         echo "VIRL simulation start failed on ${VIRL_SERVER[${index}]}"
203         exit ${retval}
204     fi
205     if [[ ! "${VIRL_SID[${index}]}" =~ session-[a-zA-Z0-9_]{6} ]]; then
206         echo "No VIRL session ID reported."
207         exit 127
208     fi
209     echo "VIRL simulation started on ${VIRL_SERVER[${index}]}"
210
211     ssh_do ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\
212      cat /scratch/${VIRL_SID[${index}]}/topology.yaml
213
214     # Download the topology file from VIRL session and rename it
215     scp ${SSH_OPTIONS} \
216         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:/scratch/${VIRL_SID[${index}]}/topology.yaml \
217         topologies/enabled/topology${index}.yaml
218
219     retval=$?
220     if [ ${retval} -ne "0" ]; then
221         echo "Failed to copy topology file from VIRL simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}"
222         exit ${retval}
223     fi
224 done
225
226 echo ${VIRL_SID[@]}
227
228 virtualenv --system-site-packages env
229 . env/bin/activate
230
231 echo pip install
232 pip install -r ${SCRIPT_DIR}/requirements.txt
233
234 for index in "${!VIRL_SERVER[@]}"; do
235     pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
236               -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
237               -d ${SCRIPT_DIR}/topologies/enabled/topology${index}.yaml \
238               -vvv
239     if [ "$?" -ne "0" ]; then
240         echo "Topology${index} schema validation failed."
241         echo "However, the tests will start."
242     fi
243 done
244
245 function run_test_set() {
246     set +x
247     OLDIFS=$IFS
248     IFS=","
249     nr=$(echo $1)
250     rm -f ${LOG_PATH}/test_run${nr}.log
251     exec &> >(while read line; do echo "$(date +'%H:%M:%S') $line" \
252      >> ${LOG_PATH}/test_run${nr}.log; done;)
253     suite_str=""
254     for suite in ${TEST_GROUPS[${nr}]}; do
255         suite_str="${suite_str} --suite ${SUITE_PATH}.${suite}"
256     done
257     IFS=$OLDIFS
258
259     echo "PYTHONPATH=`pwd` pybot -L TRACE -W 136\
260         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \
261         ${suite_str} \
262         --include vm_envAND3_node_single_link_topo \
263         --include vm_envAND3_node_double_link_topo \
264         --exclude PERFTEST \
265         --exclude ${SKIP_PATCH} \
266         --noncritical EXPECTED_FAILING \
267         --output ${LOG_PATH}/log_test_set_run${nr} \
268         tests/"
269
270     PYTHONPATH=`pwd` pybot -L TRACE -W 136\
271         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \
272         ${suite_str} \
273         --include vm_envAND3_node_single_link_topo \
274         --include vm_envAND3_node_double_link_topo \
275         --exclude PERFTEST \
276         --exclude ${SKIP_PATCH} \
277         --noncritical EXPECTED_FAILING \
278         --output ${LOG_PATH}/log_test_set_run${nr} \
279         tests/
280
281     local_run_rc=$?
282     echo ${local_run_rc} > ${SHARED_MEMORY_PATH}/rc_test_run${nr}
283     set -x
284 }
285
286 set +x
287 # Send to background an instance of the run_test_set() function for each number,
288 # record the pid.
289 for index in "${!VIRL_SERVER[@]}"; do
290     run_test_set ${index} &
291     pid=$!
292     echo "Sent to background: Test_set${index} (pid=$pid)"
293     pids[$pid]=$index
294 done
295
296 echo
297 echo -n "Waiting..."
298
299 # Watch the stable of background processes.
300 # If a pid goes away, remove it from the array.
301 while [ -n "${pids[*]}" ]; do
302     for i in $(seq 0 9); do
303         sleep 1
304         echo -n "."
305     done
306     for pid in "${!pids[@]}"; do
307         if ! ps "$pid" >/dev/null; then
308             echo -e "\n"
309             echo "Test_set${pids[$pid]} with PID $pid finished."
310             unset pids[$pid]
311         fi
312     done
313     if [ -z "${!pids[*]}" ]; then
314         break
315     fi
316     echo -n -e "\nStill waiting for test set(s): ${pids[*]} ..."
317 done
318
319 echo
320 echo "All test set runs finished."
321 echo
322
323 set -x
324
325 RC=0
326 for index in "${!VIRL_SERVER[@]}"; do
327     echo "Test_set${index} log:"
328     cat ${LOG_PATH}/test_run${index}.log
329     RC_PARTIAL_RUN=$(cat ${SHARED_MEMORY_PATH}/rc_test_run${index})
330     RC=$((RC+RC_PARTIAL_RUN))
331     rm -f ${SHARED_MEMORY_PATH}/rc_test_run${index}
332     rm -f ${LOG_PATH}/test_run${index}.log
333     echo
334 done
335
336 # Log the final result
337 if [ "${RC}" -eq "0" ]; then
338     set +x
339     echo
340     echo "========================================================================================================================================"
341     echo "Final result of all test loops:                                                                                                 | PASS |"
342     echo "All critical tests have passed."
343     echo "========================================================================================================================================"
344     echo
345     set -x
346 else
347     if [ "${RC}" -eq "1" ]; then
348         HLP_STR="test has"
349     else
350         HLP_STR="tests have"
351     fi
352     set +x
353     echo
354     echo "========================================================================================================================================"
355     echo "Final result of all test loops:                                                                                                 | FAIL |"
356     echo "${RC} critical ${HLP_STR} failed."
357     echo "========================================================================================================================================"
358     echo
359     set -x
360 fi
361
362 echo Post-processing test data...
363
364 partial_logs=""
365 for index in "${!VIRL_SERVER[@]}"; do
366     partial_logs="${partial_logs} ${LOG_PATH}/log_test_set_run${index}.xml"
367 done
368
369 # Rebot output post-processing
370 rebot --noncritical EXPECTED_FAILING \
371       --output output.xml ${partial_logs}
372
373 # Remove unnecessary log files
374 rm -f ${partial_logs}
375
376 echo Post-processing finished.
377
378 if [ ${RC} -eq 0 ]; then
379     RETURN_STATUS=0
380 else
381     RETURN_STATUS=1
382 fi
383
384 exit ${RETURN_STATUS}