Remove leftovers related to Xenial
[csit.git] / bootstrap-DMM.sh
1 #!/bin/bash
2 # Copyright (c) 2018 Huawei Technologies Co.,Ltd.
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 JOB_ARCHIVE_ARTIFACTS=(log.html output.xml report.html *.log)
21 LOG_ARCHIVE_ARTIFACTS=(log.html output.xml report.html *.log)
22 JOB_ARCHIVE_DIR="archive"
23 LOG_ARCHIVE_DIR="$WORKSPACE/archives"
24 mkdir -p ${JOB_ARCHIVE_DIR}
25 mkdir -p ${LOG_ARCHIVE_DIR}
26 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
27 export PYTHONPATH=${SCRIPT_DIR}
28
29 if [ -f "/etc/redhat-release" ]; then
30     DISTRO="CENTOS"
31     sudo yum install -y python-devel python-virtualenv openssh-clients sshpass
32     DPDK_ARTIFACTS=""
33     VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_CENTOS)
34     VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_CENTOS)
35 else
36     DISTRO="UBUNTU"
37     export DEBIAN_FRONTEND=noninteractive
38     sudo apt-get -y update
39     sudo apt-get -y install libpython2.7-dev python-virtualenv
40     DPDK_ARTIFACTS=""
41     VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_UBUNTU)
42     VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_UBUNTU)
43 fi
44
45 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
46 IPS_PER_VIRL=( "10.30.51.28:252"
47                "10.30.51.29:252"
48                "10.30.51.30:252" )
49 SIMS_PER_VIRL=( "10.30.51.28:13"
50                "10.30.51.29:13"
51                "10.30.51.30:13" )
52 IPS_PER_SIMULATION=5
53
54 function get_max_ip_nr() {
55     virl_server=$1
56     IP_VALUE="0"
57     for item in "${IPS_PER_VIRL[@]}" ; do
58         if [ "${item%%:*}" == "${virl_server}" ]
59         then
60             IP_VALUE=${item#*:}
61             break
62         fi
63     done
64     echo "$IP_VALUE"
65 }
66
67 function get_max_sim_nr() {
68     virl_server=$1
69     SIM_VALUE="0"
70     for item in "${SIMS_PER_VIRL[@]}" ; do
71         if [ "${item%%:*}" == "${virl_server}" ]
72         then
73             SIM_VALUE=${item#*:}
74             break
75         fi
76     done
77     echo "$SIM_VALUE"
78 }
79
80 VIRL_USERNAME=jenkins-in
81 VIRL_PKEY=priv_key
82 VIRL_SERVER_STATUS_FILE="status"
83 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
84
85 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
86
87 TEST_GROUPS=("func")
88 SUITE_PATH="tests.dmm"
89 SKIP_PATCH="SKIP_PATCH"
90
91 # Create tmp dir
92 mkdir ${SCRIPT_DIR}/tmp
93
94 # Use tmp dir to store log files
95 LOG_PATH="${SCRIPT_DIR}/tmp"
96
97 # Use tmp dir for tarballs
98 export TMPDIR="${SCRIPT_DIR}/tmp"
99
100 function ssh_do() {
101     echo
102     echo "### "  ssh $@
103     ssh ${SSH_OPTIONS} $@
104 }
105
106 rm -f ${VIRL_PKEY}
107 cat > ${VIRL_PKEY} <<EOF
108 -----BEGIN RSA PRIVATE KEY-----
109 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
110 GOXl9nFWKsMOzIlIn+8y7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PniyaifFWx81diblalff2hX4ipTf7Yx24I
127 wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS
128 NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
129 xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
130 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
131 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
132 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
133 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
134 -----END RSA PRIVATE KEY-----
135 EOF
136 chmod 600 ${VIRL_PKEY}
137
138 #
139 # The server must be reachable and have a "status" file with
140 # the content "PRODUCTION" to be selected.
141 #
142 # If the server is not reachable or does not have the correct
143 # status remove it from the array and start again.
144 #
145 # Abort if there are no more servers left in the array.
146 #
147 VIRL_PROD_SERVERS=()
148 for index in "${!VIRL_SERVERS[@]}"; do
149     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVERS[$index]} cat $VIRL_SERVER_STATUS_FILE 2>&1)
150     echo VIRL HOST ${VIRL_SERVERS[$index]} status is \"$virl_server_status\"
151     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
152     then
153         # Candidate is in good status. Add to array.
154         VIRL_PROD_SERVERS+=(${VIRL_SERVERS[$index]})
155     fi
156 done
157
158 VIRL_SERVERS=("${VIRL_PROD_SERVERS[@]}")
159 echo "VIRL servers in production: ${VIRL_SERVERS[@]}"
160 num_hosts=${#VIRL_SERVERS[@]}
161 if [ $num_hosts == 0 ]
162 then
163     echo "No more VIRL candidate hosts available, failing."
164     exit 127
165 fi
166
167 # Get the LOAD of each server based on number of active simulations (testcases)
168 VIRL_SERVER_LOAD=()
169 for index in "${!VIRL_SERVERS[@]}"; do
170     VIRL_SERVER_LOAD[${index}]=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVERS[$index]} "list-testcases | grep session | wc -l")
171 done
172
173 # Pick for each TEST_GROUP least loaded server
174 VIRL_SERVER=()
175 for index in "${!TEST_GROUPS[@]}"; do
176     least_load_server_idx=$(echo "${VIRL_SERVER_LOAD[*]}" | tr -s ' ' '\n' | awk '{print($0" "NR)}' | sort -g -k1,1 | head -1 | cut -f2 -d' ')
177     least_load_server=${VIRL_SERVERS[$least_load_server_idx-1]}
178     VIRL_SERVER+=($least_load_server)
179     # Adjusting load as we are not going run simulation immediately
180     VIRL_SERVER_LOAD[$least_load_server_idx-1]=$((VIRL_SERVER_LOAD[$least_load_server_idx-1]+1))
181 done
182
183 echo "Selected VIRL servers: ${VIRL_SERVER[@]}"
184
185 # Temporarily download  DPDK packages
186 DMM_TAR_FILE="dmm_depends.tar.gz"
187
188 cd dmm/scripts/
189 ./build.sh all
190 cd -
191
192 DPDK_DOWNLOAD_PATH=$(cat dmm/scripts/build_dpdk.sh | grep DPDK_DOWNLOAD_PATH=  | cut -d "=" -f2)
193 mv $DPDK_DOWNLOAD_PATH/dpdk-18.02.tar.xz .
194
195 wget http://security.ubuntu.com/ubuntu/pool/main/n/numactl/libnuma1_2.0.11-1ubuntu1.1_amd64.deb
196 wget http://security.ubuntu.com/ubuntu/pool/main/n/numactl/libnuma-dev_2.0.11-1ubuntu1.1_amd64.deb
197 wget http://security.ubuntu.com/ubuntu/pool/main/e/ethtool/ethtool_4.5-1_amd64.deb
198 wget http://security.ubuntu.com/ubuntu/pool/main/l/lsof/lsof_4.89+dfsg-0.1_amd64.deb
199
200 tar zcf ${DMM_TAR_FILE} dpdk-18.02.tar.xz  ./dmm/ libnuma*.deb
201
202 VIRL_DIR_LOC="/tmp"
203
204 cat ${VIRL_PKEY}
205
206 # Copy the files to VIRL hosts
207 DONE=""
208 for index in "${!VIRL_SERVER[@]}"; do
209     # Do not copy files in case they have already been copied to the VIRL host
210     [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1
211
212     if [ "${copy}" -eq "0" ]; then
213         echo "DMM_TAR_FILE has already been copied to the VIRL host ${VIRL_SERVER[${index}]}"
214     else
215         scp ${SSH_OPTIONS} ${DMM_TAR_FILE} \
216         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
217
218         result=$?
219         if [ "${result}" -ne "0" ]; then
220             echo "Failed to copy DMM_TAR_FILE to VIRL host ${VIRL_SERVER[${index}]}"
221             echo ${result}
222             exit ${result}
223         else
224             echo "DMM_TAR_FILE successfully copied to the VIRL host ${VIRL_SERVER[${index}]}"
225         fi
226         DONE+=(${VIRL_SERVER[${index}]})
227     fi
228 done
229
230 # Start a simulation on VIRL server
231
232 function stop_virl_simulation {
233     for index in "${!VIRL_SERVER[@]}"; do
234         ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\
235             "stop-testcase ${VIRL_SID[${index}]}"
236     done
237 }
238
239 # Upon script exit, cleanup the simulation execution
240 trap stop_virl_simulation EXIT
241
242 for index in "${!VIRL_SERVER[@]}"; do
243     echo "Starting simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}"
244     # Get given VIRL server limits for max. number of VMs and IPs
245     max_ips=$(get_max_ip_nr ${VIRL_SERVER[${index}]})
246     max_ips_from_sims=$(($(get_max_sim_nr ${VIRL_SERVER[${index}]})*IPS_PER_SIMULATION))
247     # Set quota to lower value
248     IP_QUOTA=$([ $max_ips -le $max_ips_from_sims ] && echo "$max_ips" || echo "$max_ips_from_sims")
249     # Start the simulation
250     VIRL_SID[${index}]=$(ssh ${SSH_OPTIONS} \
251         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]} \
252         "start-testcase-DMM -vv --quota ${IP_QUOTA} --copy ${VIRL_TOPOLOGY} \
253         --release ${VIRL_RELEASE} ${VIRL_DIR_LOC}/${DMM_TAR_FILE}")
254         # TODO: remove param ${DMM_TAR_FILE} when start-testcase script is
255         # updated on all virl servers
256     retval=$?
257     if [ ${retval} -ne "0" ]; then
258         echo "VIRL simulation start failed on ${VIRL_SERVER[${index}]}"
259         exit ${retval}
260     fi
261     if [[ ! "${VIRL_SID[${index}]}" =~ session-[a-zA-Z0-9_]{6} ]]; then
262         echo "No VIRL session ID reported."
263         exit 127
264     fi
265     echo "VIRL simulation nr. ${index} started on ${VIRL_SERVER[${index}]}"
266
267     ssh_do ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\
268      cat /scratch/${VIRL_SID[${index}]}/topology.yaml
269
270     # Download the topology file from VIRL session and rename it
271     scp ${SSH_OPTIONS} \
272         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:/scratch/${VIRL_SID[${index}]}/topology.yaml \
273         topologies/enabled/topology${index}.yaml
274
275     retval=$?
276     if [ ${retval} -ne "0" ]; then
277         echo "Failed to copy topology file from VIRL simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}"
278         exit ${retval}
279     fi
280 done
281
282 echo ${VIRL_SID[@]}
283
284 virtualenv --system-site-packages env
285 . env/bin/activate
286
287 echo pip install
288 pip install -r ${SCRIPT_DIR}/requirements.txt
289
290 for index in "${!VIRL_SERVER[@]}"; do
291     pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
292               -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
293               -d ${SCRIPT_DIR}/topologies/enabled/topology${index}.yaml \
294               -vvv
295     if [ "$?" -ne "0" ]; then
296         echo "Topology${index} schema validation failed."
297         echo "However, the tests will start."
298     fi
299 done
300
301 function run_test_set() {
302     set +x
303     OLDIFS=$IFS
304     IFS=","
305     nr=$(echo $1)
306     rm -f ${LOG_PATH}/test_run${nr}.log
307     exec &> >(while read line; do echo "$(date +'%H:%M:%S') $line" \
308      >> ${LOG_PATH}/test_run${nr}.log; done;)
309     suite_str=""
310     for suite in ${TEST_GROUPS[${nr}]}; do
311         suite_str="${suite_str} --suite ${SUITE_PATH}.${suite}"
312     done
313     IFS=$OLDIFS
314
315     echo "PYTHONPATH=`pwd` pybot -L TRACE -W 136\
316         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \
317         ${suite_str} \
318         --include vm_envAND3_node_single_link_topo \
319         --include vm_envAND3_node_double_link_topo \
320         --exclude PERFTEST \
321         --exclude ${SKIP_PATCH} \
322         --noncritical EXPECTED_FAILING \
323         --output ${LOG_PATH}/log_test_set_run${nr} \
324         tests/"
325
326     PYTHONPATH=`pwd` pybot -L TRACE -W 136\
327         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \
328         ${suite_str} \
329         --include vm_envAND3_node_single_link_topo \
330         --include vm_envAND3_node_double_link_topo \
331         --exclude PERFTEST \
332         --exclude ${SKIP_PATCH} \
333         --noncritical EXPECTED_FAILING \
334         --output ${LOG_PATH}/log_test_set_run${nr} \
335         tests/
336
337     local local_run_rc=$?
338     set -x
339     echo ${local_run_rc} > ${LOG_PATH}/rc_test_run${nr}
340 }
341
342 set +x
343 # Send to background an instance of the run_test_set() function for each number,
344 # record the pid.
345 for index in "${!VIRL_SERVER[@]}"; do
346     run_test_set ${index} &
347     pid=$!
348     echo "Sent to background: Test_set${index} (pid=$pid)"
349     pids[$pid]=$index
350 done
351
352 echo
353 echo -n "Waiting..."
354
355 # Watch the stable of background processes.
356 # If a pid goes away, remove it from the array.
357 while [ -n "${pids[*]}" ]; do
358     for i in $(seq 0 9); do
359         sleep 1
360         echo -n "."
361     done
362     for pid in "${!pids[@]}"; do
363         if ! ps "$pid" >/dev/null; then
364             echo -e "\n"
365             echo "Test_set${pids[$pid]} with PID $pid finished."
366             unset pids[$pid]
367         fi
368     done
369     if [ -z "${!pids[*]}" ]; then
370         break
371     fi
372     echo -n -e "\nStill waiting for test set(s): ${pids[*]} ..."
373 done
374
375 echo
376 echo "All test set runs finished."
377 echo
378
379 set -x
380
381 RC=0
382 for index in "${!VIRL_SERVER[@]}"; do
383     echo "Test_set${index} log:"
384     cat ${LOG_PATH}/test_run${index}.log
385     RC_PARTIAL_RUN=$(cat ${LOG_PATH}/rc_test_run${index})
386     if [ -z "$RC_PARTIAL_RUN" ]; then
387         echo "Failed to retrieve return code from test run ${index}"
388         exit 1
389     fi
390     RC=$((RC+RC_PARTIAL_RUN))
391     rm -f ${LOG_PATH}/rc_test_run${index}
392     rm -f ${LOG_PATH}/test_run${index}.log
393     echo
394 done
395
396 # Log the final result
397 if [ "${RC}" -eq "0" ]; then
398     set +x
399     echo
400     echo "========================================================================================================================================"
401     echo "Final result of all test loops:                                                                                                 | PASS |"
402     echo "All critical tests have passed."
403     echo "========================================================================================================================================"
404     echo
405     set -x
406 else
407     if [ "${RC}" -eq "1" ]; then
408         HLP_STR="test has"
409     else
410         HLP_STR="tests have"
411     fi
412     set +x
413     echo
414     echo "========================================================================================================================================"
415     echo "Final result of all test loops:                                                                                                 | FAIL |"
416     echo "${RC} critical ${HLP_STR} failed."
417     echo "========================================================================================================================================"
418     echo
419     set -x
420 fi
421
422 echo Post-processing test data...
423
424 partial_logs=""
425 for index in "${!VIRL_SERVER[@]}"; do
426     partial_logs="${partial_logs} ${LOG_PATH}/log_test_set_run${index}.xml"
427 done
428
429 # Rebot output post-processing
430 rebot --noncritical EXPECTED_FAILING \
431       --output output.xml ${partial_logs}
432
433 # Remove unnecessary log files
434 rm -f ${partial_logs}
435
436 # Archive JOB artifacts in jenkins
437 for i in ${JOB_ARCHIVE_ARTIFACTS[@]}; do
438     cp $( readlink -f ${i} | tr '\n' ' ' ) ${JOB_ARCHIVE_DIR}/
439 done
440 # Archive JOB artifacts to logs.fd.io
441 for i in ${LOG_ARCHIVE_ARTIFACTS[@]}; do
442     cp $( readlink -f ${i} | tr '\n' ' ' ) ${LOG_ARCHIVE_DIR}/
443 done
444
445 echo Post-processing finished.
446
447 if [ ${RC} -eq 0 ]; then
448     RETURN_STATUS=0
449 else
450     RETURN_STATUS=1
451 fi
452
453 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.