CSIT-488 TLDK jbb validation jobs need cmake installed
[csit.git] / bootstrap-vpp-verify-weekly.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 export DEBIAN_FRONTEND=noninteractive
21 sudo apt-get -y update
22 sudo apt-get -y install libpython2.7-dev python-virtualenv
23
24 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
25 VIRL_SERVER=""
26
27 VIRL_USERNAME=jenkins-in
28 VIRL_PKEY=priv_key
29 VIRL_SERVER_STATUS_FILE="status"
30 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
31
32 VIRL_TOPOLOGY=double-ring-nested.xenial
33 VIRL_RELEASE=csit-ubuntu-16.04.1_2016-12-19_1.6
34
35 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
36
37 function ssh_do() {
38     echo
39     echo "### "  ssh $@
40     ssh ${SSH_OPTIONS} $@
41 }
42
43 rm -f ${VIRL_PKEY}
44 cat > ${VIRL_PKEY} <<EOF
45 -----BEGIN RSA PRIVATE KEY-----
46 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
47 GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX
48 VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ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NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
66 xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
67 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
68 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
69 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
70 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
71 -----END RSA PRIVATE KEY-----
72 EOF
73 chmod 600 ${VIRL_PKEY}
74
75 #
76 # Pick a random host from the array of VIRL servers, and attempt
77 # to reach it and verify it's status.
78 #
79 # The server must be reachable, and have a "status" file with
80 # the content "PRODUCTION", to be selected.
81 #
82 # If the server is not reachable, or does not have the correct
83 # status, remove it from the array and start again.
84 #
85 # Abort if there are no more servers left in the array.
86 #
87 while [[ ! "$VIRL_SERVER" ]]
88 do
89     num_hosts=${#VIRL_SERVERS[@]}
90     if [ $num_hosts == 0 ]
91     then
92         echo "No more VIRL candidate hosts available, failing."
93         exit 127
94     fi
95     element=$[ $RANDOM % $num_hosts ]
96     virl_server_candidate=${VIRL_SERVERS[$element]}
97     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1)
98     echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\"
99     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
100     then
101         # Candidate is in good status. Select this server.
102         VIRL_SERVER="$virl_server_candidate"
103     else
104         # Candidate is in bad status. Remove from array.
105         VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}")
106     fi
107 done
108
109 # Temporarily download VPP packages from nexus.fd.io
110 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
111
112 if [ "${#}" -ne "0" ]; then
113     arr=(${@})
114     echo ${arr[0]}
115 else
116     rm -f *.deb
117     VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER)
118     VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL)
119     VPP_CLASSIFIER="-deb"
120     wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
121     wget -q "${VPP_REPO_URL}/vpp-dbg/${VPP_STABLE_VER}/vpp-dbg-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
122     wget -q "${VPP_REPO_URL}/vpp-dev/${VPP_STABLE_VER}/vpp-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
123     wget -q "${VPP_REPO_URL}/vpp-dpdk-dev/${VPP_STABLE_VER}/vpp-dpdk-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
124     wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${VPP_STABLE_VER}/vpp-dpdk-dkms-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
125     wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
126     wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
127 fi
128
129 VPP_DEBS=(*.deb)
130 echo ${VPP_DEBS[@]}
131 VIRL_DIR_LOC="/tmp"
132 VPP_DEBS_FULL=(${VPP_DEBS[@]})
133
134 # Prepend directory location at remote host to deb file list
135 for index in "${!VPP_DEBS_FULL[@]}"; do
136     VPP_DEBS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_DEBS_FULL[${index}]}
137 done
138
139 echo "Updated file names: " ${VPP_DEBS_FULL[@]}
140
141 # Copy the files to VIRL host
142 scp ${SSH_OPTIONS} *.deb \
143     ${VIRL_USERNAME}@${VIRL_SERVER}:${VIRL_DIR_LOC}/
144
145 result=$?
146 if [ "${result}" -ne "0" ]; then
147     echo "Failed to copy vpp deb files to virl host"
148     echo ${result}
149     exit ${result}
150 fi
151
152 # Start a simulation on VIRL server
153 echo "Starting simulation on VIRL server"
154
155 function stop_virl_simulation {
156     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
157         "stop-testcase ${VIRL_SID}"
158 }
159
160 VIRL_SID=$(ssh ${SSH_OPTIONS} \
161     ${VIRL_USERNAME}@${VIRL_SERVER} \
162     "start-testcase -c ${VIRL_TOPOLOGY} -r ${VIRL_RELEASE} ${VPP_DEBS_FULL[@]}")
163 retval=$?
164 if [ ${retval} -ne "0" ]; then
165     echo "VIRL simulation start failed"
166     exit ${retval}
167 fi
168
169 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
170     echo "No VIRL session ID reported."
171     exit 127
172 fi
173
174 # Upon script exit, cleanup the simulation execution
175 trap stop_virl_simulation EXIT
176 echo ${VIRL_SID}
177
178 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
179
180 # Download the topology file from virl session
181 scp ${SSH_OPTIONS} \
182     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
183     topologies/enabled/topology.yaml
184
185 retval=$?
186 if [ ${retval} -ne "0" ]; then
187     echo "Failed to copy topology file from VIRL simulation"
188     exit ${retval}
189 fi
190
191
192 virtualenv --system-site-packages env
193 . env/bin/activate
194
195 echo pip install
196 pip install -r ${SCRIPT_DIR}/requirements.txt
197
198 # There are used three iterations of tests there to check
199 # the stability and reliability of the results
200
201 RC=0
202 MORE_FAILS=0
203
204 for test_set in 1 2 3
205 do
206     echo
207     echo ${test_set}. test loop
208     PYTHONPATH=`pwd` pybot -L TRACE -W 136\
209         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology.yaml \
210         --suite "tests.func" \
211         --include vm_envAND3_node_single_link_topo \
212         --include vm_envAND3_node_double_link_topo \
213         --exclude PERFTEST \
214         --noncritical EXPECTED_FAILING \
215         --output log_test_set${test_set} \
216         tests/
217     PARTIAL_RC=$(echo $?)
218     if [ ${PARTIAL_RC} -eq 250 ]; then
219         MORE_FAILS=1
220     fi
221     RC=$((RC+PARTIAL_RC))
222 done
223
224 # Log the final result
225 if [ ${RC} -eq 0 ]; then
226     set +x
227     echo
228     echo "========================================================================================================================================"
229     echo "Final result of all test loops:                                                                                                 | PASS |"
230     echo "All critical tests have passed."
231     echo "========================================================================================================================================"
232     echo
233     set -x
234 elif [ ${MORE_FAILS} -eq 0 ]; then
235     if [ ${RC} -eq 1 ]; then
236         HLP_STR="test has"
237     else
238         HLP_STR="tests have"
239     fi
240     set +x
241     echo
242     echo "========================================================================================================================================"
243     echo "Final result of all test loops:                                                                                                 | FAIL |"
244     echo "${RC} critical ${HLP_STR} failed."
245     echo "========================================================================================================================================"
246     echo
247     set -x
248 else
249     set +x
250     echo
251     echo "========================================================================================================================================"
252     echo "Final result of all test loops:                                                                                                 | FAIL |"
253     echo "More then 250 critical tests have failed in one test loop."
254     echo "========================================================================================================================================"
255     echo
256     set -x
257 fi
258
259 echo Post-processing test data...
260
261 # Rebot output post-processing
262 rebot --noncritical EXPECTED_FAILING \
263       --output output.xml \
264       ./log_test_set1.xml ./log_test_set2.xml ./log_test_set3.xml
265
266 # Remove unnecessary log files
267 rm -f ./log_test_set1.xml ./log_test_set2.xml ./log_test_set3.xml
268
269 echo Post-processing finished.
270
271 if [ ${RC} -eq 0 ]; then
272     RETURN_STATUS=0
273 else
274     RETURN_STATUS=1
275 fi
276
277 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.