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