6f8fba00b625d840d3ef3a81bfb6a77300beae69
[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 apt-get -y update
21 sudo apt-get -y install libpython2.7-dev python-virtualenv
22
23 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
24
25 VIRL_USERNAME=jenkins-in
26 VIRL_PKEY=priv_key
27 VIRL_SERVER_STATUS_FILE="status"
28 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
29
30 VIRL_TOPOLOGY=double-ring-nested.centos7
31 VIRL_RELEASE=csit-centos-7.3-1611
32
33 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
34
35 TEST_GROUPS=("l2bd,dhcp,gre,honeycomb,l2xc,lisp,softwire" "cop,telemetry,ipsec,ipv6,rpf,tap,vrf" "fds,iacl,ipv4,policer,vlan,vxlan")
36 SUITE_PATH="tests.func"
37
38 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
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="/run/shm"
50
51 function ssh_do() {
52     echo
53     echo "### "  ssh $@
54     ssh ${S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gVWq68NAcp5FZJv0
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 if [ "${#}" -ne "0" ]; then
129     arr=(${@})
130     echo ${arr[0]}
131     # DPDK is not part of the vpp build
132     DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)
133     wget -q "${VPP_REPO_URL}/vpp-dpdk-dev/${DPDK_STABLE_VER}/vpp-dpdk-dev-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
134     wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${DPDK_STABLE_VER}/vpp-dpdk-dkms-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
135 else
136     rm -f *.rpm
137     DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)
138     VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER)
139     VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_CENTOS)
140     VPP_CLASSIFIER="-rpm"
141     wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
142     wget -q "${VPP_REPO_URL}/vpp-dbg/${VPP_STABLE_VER}/vpp-dbg-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
143     wget -q "${VPP_REPO_URL}/vpp-dev/${VPP_STABLE_VER}/vpp-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
144     wget -q "${VPP_REPO_URL}/vpp-dpdk-dev/${DPDK_STABLE_VER}/vpp-dpdk-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
145     wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
146     wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit
147 fi
148
149 VPP_RPMS=(*.rpm)
150 echo ${VPP_RPMS[@]}
151 VIRL_DIR_LOC="/tmp"
152 VPP_RPMS_FULL=(${VPP_RPMS[@]})
153
154 # Prepend directory location at remote host to rpm list
155 for index in "${!VPP_RPMS_FULL[@]}"; do
156     VPP_RPMS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_RPMS_FULL[${index}]}
157 done
158
159 echo "Updated file names: " ${VPP_RPMS_FULL[@]}
160
161 cat ${VIRL_PKEY}
162
163 # Copy the files to VIRL hosts
164 DONE=""
165 for index in "${!VIRL_SERVER[@]}"; do
166     # Do not copy files in case they have already been copied to the VIRL host
167     [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1
168
169     if [ "${copy}" -eq "0" ]; then
170         echo "VPP rpms have already been copied to the VIRL host ${VIRL_SERVER[${index}]}"
171     else
172         scp ${SSH_OPTIONS} *.rpm \
173         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
174
175         result=$?
176         if [ "${result}" -ne "0" ]; then
177             echo "Failed to copy VPP rpms to VIRL host ${VIRL_SERVER[${index}]}"
178             echo ${result}
179             exit ${result}
180         else
181             echo "VPP rpms successfully copied to the VIRL host ${VIRL_SERVER[${index}]}"
182         fi
183         DONE+=(${VIRL_SERVER[${index}]})
184     fi
185 done
186
187 # Start a simulation on VIRL server
188
189 function stop_virl_simulation {
190     for index in "${!VIRL_SERVER[@]}"; do
191         ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\
192             "stop-testcase ${VIRL_SID[${index}]}"
193     done
194 }
195
196 # Upon script exit, cleanup the simulation execution
197 trap stop_virl_simulation EXIT
198
199 for index in "${!VIRL_SERVER[@]}"; do
200     echo "Starting simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}"
201     VIRL_SID[${index}]=$(ssh ${SSH_OPTIONS} \
202         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]} \
203         "start-testcase -c ${VIRL_TOPOLOGY} -r ${VIRL_RELEASE} ${VPP_RPMS_FULL[@]}")
204     retval=$?
205     if [ ${retval} -ne "0" ]; then
206         echo "VIRL simulation start failed on ${VIRL_SERVER[${index}]}"
207         exit ${retval}
208     fi
209     if [[ ! "${VIRL_SID[${index}]}" =~ session-[a-zA-Z0-9_]{6} ]]; then
210         echo "No VIRL session ID reported."
211         exit 127
212     fi
213     echo "VIRL simulation started on ${VIRL_SERVER[${index}]}"
214
215     ssh_do ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\
216      cat /scratch/${VIRL_SID[${index}]}/topology.yaml
217
218     # Download the topology file from VIRL session and rename it
219     scp ${SSH_OPTIONS} \
220         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:/scratch/${VIRL_SID[${index}]}/topology.yaml \
221         topologies/enabled/topology${index}.yaml
222
223     retval=$?
224     if [ ${retval} -ne "0" ]; then
225         echo "Failed to copy topology file from VIRL simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}"
226         exit ${retval}
227     fi
228 done
229
230 echo ${VIRL_SID[@]}
231
232 virtualenv --system-site-packages env
233 . env/bin/activate
234
235 echo pip install
236 pip install -r ${SCRIPT_DIR}/requirements.txt
237
238 for index in "${!VIRL_SERVER[@]}"; do
239     pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
240               -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
241               -d ${SCRIPT_DIR}/topologies/enabled/topology${index}.yaml \
242               -vvv
243     if [ "$?" -ne "0" ]; then
244         echo "Topology${index} schema validation failed."
245         echo "However, the tests will start."
246     fi
247 done
248
249 function run_test_set() {
250     set +x
251     OLDIFS=$IFS
252     IFS=","
253     nr=$(echo $1)
254     rm -f ${LOG_PATH}/test_run${nr}.log
255     exec &> >(while read line; do echo "$(date +'%H:%M:%S') $line" \
256      >> ${LOG_PATH}/test_run${nr}.log; done;)
257     suite_str=""
258     for suite in ${TEST_GROUPS[${nr}]}; do
259         suite_str="${suite_str} --suite ${SUITE_PATH}.${suite}"
260     done
261     IFS=$OLDIFS
262
263     echo "PYTHONPATH=`pwd` pybot -L TRACE -W 136\
264         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \
265         ${suite_str} \
266         --include vm_envAND3_node_single_link_topo \
267         --include vm_envAND3_node_double_link_topo \
268         --exclude PERFTEST \
269         --exclude SKIP_PATCH \
270         --noncritical EXPECTED_FAILING \
271         --output ${LOG_PATH}/log_test_set_run${nr} \
272         tests/"
273
274     PYTHONPATH=`pwd` pybot -L TRACE -W 136\
275         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \
276         ${suite_str} \
277         --include vm_envAND3_node_single_link_topo \
278         --include vm_envAND3_node_double_link_topo \
279         --exclude PERFTEST \
280         --exclude SKIP_PATCH \
281         --noncritical EXPECTED_FAILING \
282         --output ${LOG_PATH}/log_test_set_run${nr} \
283         tests/
284
285     local_run_rc=$?
286     echo ${local_run_rc} > ${SHARED_MEMORY_PATH}/rc_test_run${nr}
287     set -x
288 }
289
290 set +x
291 # Send to background an instance of the run_test_set() function for each number,
292 # record the pid.
293 for index in "${!VIRL_SERVER[@]}"; do
294     run_test_set ${index} &
295     pid=$!
296     echo "Sent to background: Test_set${index} (pid=$pid)"
297     pids[$pid]=$index
298 done
299
300 echo
301 echo -n "Waiting..."
302
303 # Watch the stable of background processes.
304 # If a pid goes away, remove it from the array.
305 while [ -n "${pids[*]}" ]; do
306     for i in $(seq 0 9); do
307         sleep 1
308         echo -n "."
309     done
310     for pid in "${!pids[@]}"; do
311         if ! ps "$pid" >/dev/null; then
312             echo -e "\n"
313             echo "Test_set${pids[$pid]} with PID $pid finished."
314             unset pids[$pid]
315         fi
316     done
317     if [ -z "${!pids[*]}" ]; then
318         break
319     fi
320     echo -n -e "\nStill waiting for test set(s): ${pids[*]} ..."
321 done
322
323 echo
324 echo "All test set runs finished."
325 echo
326
327 set -x
328
329 RC=0
330 for index in "${!VIRL_SERVER[@]}"; do
331     echo "Test_set${index} log:"
332     cat ${LOG_PATH}/test_run${index}.log
333     RC_PARTIAL_RUN=$(cat ${SHARED_MEMORY_PATH}/rc_test_run${index})
334     RC=$((RC+RC_PARTIAL_RUN))
335     rm -f ${SHARED_MEMORY_PATH}/rc_test_run${index}
336     rm -f ${LOG_PATH}/test_run${index}.log
337     echo
338 done
339
340 # Log the final result
341 if [ "${RC}" -eq "0" ]; then
342     set +x
343     echo
344     echo "========================================================================================================================================"
345     echo "Final result of all test loops:                                                                                                 | PASS |"
346     echo "All critical tests have passed."
347     echo "========================================================================================================================================"
348     echo
349     set -x
350 else
351     if [ "${RC}" -eq "1" ]; then
352         HLP_STR="test has"
353     else
354         HLP_STR="tests have"
355     fi
356     set +x
357     echo
358     echo "========================================================================================================================================"
359     echo "Final result of all test loops:                                                                                                 | FAIL |"
360     echo "${RC} critical ${HLP_STR} failed."
361     echo "========================================================================================================================================"
362     echo
363     set -x
364 fi
365
366 echo Post-processing test data...
367
368 partial_logs=""
369 for index in "${!VIRL_SERVER[@]}"; do
370     partial_logs="${partial_logs} ${LOG_PATH}/log_test_set_run${index}.xml"
371 done
372
373 # Rebot output post-processing
374 rebot --noncritical EXPECTED_FAILING \
375       --output output.xml ${partial_logs}
376
377 # Remove unnecessary log files
378 rm -f ${partial_logs}
379
380 echo Post-processing finished.
381
382 if [ ${RC} -eq 0 ]; then
383     RETURN_STATUS=0
384 else
385     RETURN_STATUS=1
386 fi
387
388 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.