HC Test: Disable NSH plugin installation and tests
[csit.git] / bootstrap-vpp-verify-semiweekly.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 ght (c) 2016 Cisco and/or its affiliates.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not usecopy of the License at:
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 set -x
18
19 RETURN_STATUS=0
20
21 cat /etc/hostname
22 cat /etc/hosts
23
24 PYBOT_ARGS="--noncritical MULTI_THREAD"
25
26 ARCHIVE_ARTIFACTS=(log.html output.xml report.html)
27
28 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
29 export PYTHONPATH=${SCRIPT_DIR}
30
31 if [ -f "/etc/redhat-release" ]; then
32     DISTRO="CENTOS"
33     sudo yum install -y python-devel python-virtualenv
34 else
35     DISTRO="UBUNTU"
36     export DEBIAN_FRONTEND=noninteractive
37     sudo apt-get -y update
38     sudo apt-get -y install libpython2.7-dev python-virtualenv
39 fi
40
41 # 1st step: Download and prepare VPP packages
42
43 # Temporarily download VPP packages from nexus.fd.io
44 if [ "${#}" -ne "0" ]; then
45     arr=(${@})
46     echo ${arr[0]}
47 else
48     case "$DISTRO" in
49         CENTOS )
50             PACKAGE=rpm
51             ;;
52         UBUNTU )
53             PACKAGE=deb
54     esac
55     # Download the latest VPP build install packages
56     rm -f *.${PACKAGE}
57     echo Downloading VPP packages...
58     bash ${SCRIPT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh --skip-install
59 fi
60
61 # Take vpp package and get the vpp version
62 VPP_PKGS=(*.$PACKAGE)
63 case "$DISTRO" in
64         CENTOS )
65             VPP_VER="$( expr match $(ls *.rpm | head -n 1) 'vpp-\(.*\).rpm' )"
66             ;;
67         UBUNTU )
68             VPP_VER="$( expr match $(ls *.deb | head -n 1) 'vpp-\(.*\)-deb.deb' )"
69 esac
70
71 echo ${VPP_PKGS[@]}
72
73 set +x
74 echo "****************************************************************************************************************************************"
75 echo "1st step: Download VPP packages                                                                                                 FINISHED"
76 echo "VPP version to be tested: ${VPP_VER}"
77 echo "****************************************************************************************************************************************"
78 set -x
79
80
81 # 2nd step: Start virtual env and install requirements
82
83 echo Starting virtual env...
84 virtualenv --system-site-packages env
85 . env/bin/activate
86
87 echo Installing requirements...
88 pip install -r ${SCRIPT_DIR}/requirements.txt
89
90 set +x
91 echo "****************************************************************************************************************************************"
92 echo "2nd step: Start virtual env and install requirements                                                                            FINISHED"
93 echo "****************************************************************************************************************************************"
94 set -x
95
96
97 # 3rd step: Prepare VIRL system
98 echo Preparing VIRL system...
99
100 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
101 VIRL_SERVER=""
102
103 VIRL_USERNAME=jenkins-in
104 VIRL_PKEY=priv_key
105 VIRL_SERVER_STATUS_FILE="status"
106 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
107 VIRL_SESSION_EXPIRY="620"
108
109 case "$DISTRO" in
110         CENTOS )
111             VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_CENTOS)
112             VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_CENTOS)
113             ;;
114         UBUNTU )
115             VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_UBUNTU)
116             VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_UBUNTU)
117 esac
118
119 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
120
121 function ssh_do() {
122     echo
123     echo "### "  ssh $@
124     ssh ${SSH_OPTIONS} $@
125 }
126
127 rm -f ${VIRL_PKEY}
128 cat > ${VIRL_PKEY} <<EOF
129 -----BEGIN RSA PRIVATE KEY-----
130 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
131 GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX
132 VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9
133 asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz
134 L3dM3iSmlmQlzv9bThjo+nI4KFYh6m5wrZmAo5r/4q9CIJc21HVnTqkGOWJIZz6J
135 73lePJVSq5gYqaoGw3swFEA/MDkOx7baWKSoLQIDAQABAoIBAQCNBeolNp+JWJ76
136 gQ4fwLsknyXSV6sxYyhkDW4PEwwcTU06uqce0AAzXVffxne0fMe48x47+zqBgPbb
137 4huM+Pu8B9nfojUMr5TaYtl9Zbgpk3F8H7dT7LKOa6XrxvZTZrADSRc30+Z26zPN
138 e9zTaf42Gvt0/l0Zs1BHwbaOXqO+XuwJ3/F9Sf3PQYWXD3EOWjpHDP/X/1vAs6lV
139 SLkm6J/9KKE1m6I6LTYjIXuYt4SXybW6N2TSy54hhQtYcDUnIU2hR/PHVWKrGA0J
140 kELgrtTNTdbML27O5gFWU4PLUEYTZ9fN11D6qUZKxLcPOiPPHXkiILMRCCnG5DYI
141 ksBAU/YlAoGBAPxZO9VO18TYc8THV1nLKcvT2+1oSs1UcA2wNQMU55t910ZYinRa
142 MRwUhMOf8Mv5wOeiZaRICQB1PnVWtDVmGECgPpK6jUxqAwn8rgJcnoafLGL5YKMY
143 RVafTe6N5LXgCaOcJrk21wxs6v7ninEbUxxc575urOvZMBkymDw91dwbAoGBAPwa
144 YRhKhrzFKZzdK0RadVjnxKvolUllpoqqg3XuvmeAJHAOAnaOgVWq68NAcp5FZJv0
145 2D2Up7TX8pjf9MofP1SJbcraKBpK4NzfNkA0dSdEi+FhVofAJ9umB2o5LW1n7sab
146 UIrjsdzSJK/9Zb9yTTHPyibYzNEgaJV1HsbxfEFXAoGAYO2RmvRm0phll18OQVJV
147 IpKk9kLKAKZ/R/K32hAsikBC8SVPQTPniyaifFWx81diblalff2hX4ipTf7Yx24I
148 wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS
149 NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
150 xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
151 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
152 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
153 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
154 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
155 -----END RSA PRIVATE KEY-----
156 EOF
157 chmod 600 ${VIRL_PKEY}
158
159 #
160 # Pick a random host from the array of VIRL servers, and attempt
161 # to reach it and verify it's status.
162 #
163 # The server must be reachable, and have a "status" file with
164 # the content "PRODUCTION", to be selected.
165 #
166 # If the server is not reachable, or does not have the correct
167 # status, remove it from the array and start again.
168 #
169 # Abort if there are no more servers left in the array.
170 #
171 while [[ ! "$VIRL_SERVER" ]]
172 do
173     num_hosts=${#VIRL_SERVERS[@]}
174     if [ $num_hosts == 0 ]
175     then
176         echo "No more VIRL candidate hosts available, failing."
177         exit 127
178     fi
179     element=$[ $RANDOM % $num_hosts ]
180     virl_server_candidate=${VIRL_SERVERS[$element]}
181     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1)
182     echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\"
183     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
184     then
185         # Candidate is in good status. Select this server.
186         VIRL_SERVER="$virl_server_candidate"
187     else
188         # Candidate is in bad status. Remove from array.
189         VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}")
190     fi
191 done
192
193
194 VIRL_DIR_LOC="/tmp"
195 VPP_PKGS_VIRL=(${VPP_PKGS[@]})
196
197 # Prepend directory location at remote host to deb file list
198 for index in "${!VPP_PKGS_VIRL[@]}"; do
199     VPP_PKGS_VIRL[${index}]=${VIRL_DIR_LOC}/${VPP_PKGS_VIRL[${index}]}
200 done
201
202 echo "Updated file names: " ${VPP_PKGS_VIRL[@]}
203
204 cat ${VIRL_PKEY}
205 # Copy the files to VIRL host
206 scp ${SSH_OPTIONS} *.${PACKAGE} \
207     ${VIRL_USERNAME}@${VIRL_SERVER}:${VIRL_DIR_LOC}/
208
209 result=$?
210 if [ "${result}" -ne "0" ]; then
211     echo "Failed to copy vpp deb files to virl host"
212     echo ${result}
213     exit ${result}
214 fi
215
216 # Start a simulation on VIRL server
217 echo "Starting simulation on VIRL server"
218
219 function stop_virl_simulation {
220     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
221         "stop-testcase ${VIRL_SID}"
222 }
223
224 VIRL_SID=$(ssh ${SSH_OPTIONS} \
225     ${VIRL_USERNAME}@${VIRL_SERVER} \
226     "start-testcase -vv --copy ${VIRL_TOPOLOGY} \
227     --expiry ${VIRL_SESSION_EXPIRY} \
228     --release ${VIRL_RELEASE} ${VPP_PKGS_VIRL[@]}")
229 retval=$?
230 if [ ${retval} -ne "0" ]; then
231     echo "VIRL simulation start failed"
232     exit ${retval}
233 fi
234
235 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
236     echo "No VIRL session ID reported."
237     exit 127
238 fi
239
240 # Upon script exit, cleanup the VIRL simulation execution
241 trap stop_virl_simulation EXIT
242 echo ${VIRL_SID}
243
244 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
245
246 # Download the topology file from VIRL session
247 scp ${SSH_OPTIONS} \
248     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
249     topologies/enabled/topology_VIRL.yaml
250
251 retval=$?
252 if [ ${retval} -ne "0" ]; then
253     echo "Failed to copy topology file from VIRL simulation"
254     exit ${retval}
255 fi
256
257 set +x
258 echo "****************************************************************************************************************************************"
259 echo "3rd step: Start the simulation on the VIRL server                                                                               FINISHED"
260 echo "****************************************************************************************************************************************"
261 set -x
262
263
264 # 4th step: Run functional test suites
265
266 RC=0
267 MORE_FAILS=0
268
269 echo Running functional tests on the VIRL system...
270
271 # There are used three iterations of functional tests there
272 # to check the stability and reliability of the results.
273 for test_set in 1 2 3
274 do
275     echo
276     echo Functional test loop: ${test_set}
277     echo
278
279     pybot -L TRACE -W 136\
280         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology_VIRL.yaml \
281         --suite "tests.vpp.func" \
282         --include vm_envAND3_node_single_link_topo \
283         --include vm_envAND3_node_double_link_topo \
284         --exclude PERFTEST \
285         --noncritical EXPECTED_FAILING \
286         --output log_func_test_set${test_set} \
287         tests/
288     PARTIAL_RC=$(echo $?)
289     if [ ${PARTIAL_RC} -eq 250 ]; then
290         MORE_FAILS=1
291     fi
292     RC=$((RC+PARTIAL_RC))
293 done
294
295 set +x
296 echo "****************************************************************************************************************************************"
297 echo "4th step: Run functional tests                                                                                                  FINISHED"
298 echo "****************************************************************************************************************************************"
299 set -x
300
301 # Set RETURN_STATUS=1 if some critical test failed
302 if [ ! ${RC} -eq 0 ]; then
303         RETURN_STATUS=1
304 fi
305
306 # Log the final result
307 if [ ${RC} -eq 0 ]; then
308     set +x
309     echo
310     echo "========================================================================================================================================"
311     echo "Final result of all test loops:                                                                                                 | PASS |"
312     echo "All critical tests have passed."
313     echo "========================================================================================================================================"
314     echo
315     set -x
316 elif [ ${MORE_FAILS} -eq 0 ]; then
317     if [ ${RC} -eq 1 ]; then
318         HLP_STR="test has"
319     else
320         HLP_STR="tests have"
321     fi
322     set +x
323     echo
324     echo "========================================================================================================================================"
325     echo "Final result of all test loops:                                                                                                 | FAIL |"
326     echo "${RC} critical ${HLP_STR} failed."
327     echo "========================================================================================================================================"
328     echo
329     set -x
330 else
331     set +x
332     echo
333     echo "========================================================================================================================================"
334     echo "Final result of all test loops:                                                                                                 | FAIL |"
335     echo "More then 250 critical tests have failed in one test loop."
336     echo "========================================================================================================================================"
337     echo
338     set -x
339 fi
340
341 # 7th step: Post-processing test data
342 echo Post-processing test data...
343
344 # Rebot output post-processing
345 rebot --noncritical EXPECTED_FAILING \
346       --output output.xml \
347       ./log_func_test_set1.xml ./log_func_test_set2.xml ./log_func_test_set3.xml
348
349 # Remove unnecessary files
350 rm -f ./log_test_set1.xml ./log_test_set2.xml ./log_test_set3.xml
351
352 # Archive artifacts
353 mkdir archive
354 for i in ${ARCHIVE_ARTIFACTS[@]}; do
355     cp $( readlink -f ${i} | tr '\n' ' ' ) archive/
356 done
357
358 echo Post-processing finished.
359
360 exit ${RETURN_STATUS}