d9749d5eb111f81af3455cd54011e7c44637f572
[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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qHE7hOq3giVfgg+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 and DPDK packages from nexus.fd.io
110 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
111
112 DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)
113 VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL)
114 VPP_CLASSIFIER="-deb"
115
116 if [ "${#}" -ne "0" ]; then
117     arr=(${@})
118     echo ${arr[0]}
119     # DPDK is not part of the vpp build
120     wget -q "${VPP_REPO_URL}/vpp-dpdk-dev/${DPDK_STABLE_VER}/vpp-dpdk-dev-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
121     wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${DPDK_STABLE_VER}/vpp-dpdk-dkms-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
122 else
123     rm -f *.deb
124     VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER)
125     wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
126     wget -q "${VPP_REPO_URL}/vpp-dbg/${VPP_STABLE_VER}/vpp-dbg-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
127     wget -q "${VPP_REPO_URL}/vpp-dev/${VPP_STABLE_VER}/vpp-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
128     wget -q "${VPP_REPO_URL}/vpp-dpdk-dev/${DPDK_STABLE_VER}/vpp-dpdk-dev-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
129     wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${DPDK_STABLE_VER}/vpp-dpdk-dkms-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
130     wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
131     wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
132 fi
133
134 VPP_DEBS=(*.deb)
135 echo ${VPP_DEBS[@]}
136 VIRL_DIR_LOC="/tmp"
137 VPP_DEBS_FULL=(${VPP_DEBS[@]})
138
139 # Prepend directory location at remote host to deb file list
140 for index in "${!VPP_DEBS_FULL[@]}"; do
141     VPP_DEBS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_DEBS_FULL[${index}]}
142 done
143
144 echo "Updated file names: " ${VPP_DEBS_FULL[@]}
145
146 # Copy the files to VIRL host
147 scp ${SSH_OPTIONS} *.deb \
148     ${VIRL_USERNAME}@${VIRL_SERVER}:${VIRL_DIR_LOC}/
149
150 result=$?
151 if [ "${result}" -ne "0" ]; then
152     echo "Failed to copy vpp deb files to virl host"
153     echo ${result}
154     exit ${result}
155 fi
156
157 # Start a simulation on VIRL server
158 echo "Starting simulation on VIRL server"
159
160 function stop_virl_simulation {
161     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
162         "stop-testcase ${VIRL_SID}"
163 }
164
165 VIRL_SID=$(ssh ${SSH_OPTIONS} \
166     ${VIRL_USERNAME}@${VIRL_SERVER} \
167     "start-testcase -c ${VIRL_TOPOLOGY} -r ${VIRL_RELEASE} ${VPP_DEBS_FULL[@]}")
168 retval=$?
169 if [ ${retval} -ne "0" ]; then
170     echo "VIRL simulation start failed"
171     exit ${retval}
172 fi
173
174 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
175     echo "No VIRL session ID reported."
176     exit 127
177 fi
178
179 # Upon script exit, cleanup the simulation execution
180 trap stop_virl_simulation EXIT
181 echo ${VIRL_SID}
182
183 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
184
185 # Download the topology file from virl session
186 scp ${SSH_OPTIONS} \
187     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
188     topologies/enabled/topology.yaml
189
190 retval=$?
191 if [ ${retval} -ne "0" ]; then
192     echo "Failed to copy topology file from VIRL simulation"
193     exit ${retval}
194 fi
195
196
197 virtualenv --system-site-packages env
198 . env/bin/activate
199
200 echo pip install
201 pip install -r ${SCRIPT_DIR}/requirements.txt
202
203 # There are used three iterations of tests there to check
204 # the stability and reliability of the results
205
206 RC=0
207 MORE_FAILS=0
208
209 for test_set in 1 2 3
210 do
211     echo
212     echo ${test_set}. test loop
213     PYTHONPATH=`pwd` pybot -L TRACE -W 136\
214         -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology.yaml \
215         --suite "tests.func" \
216         --include vm_envAND3_node_single_link_topo \
217         --include vm_envAND3_node_double_link_topo \
218         --exclude PERFTEST \
219         --noncritical EXPECTED_FAILING \
220         --output log_test_set${test_set} \
221         tests/
222     PARTIAL_RC=$(echo $?)
223     if [ ${PARTIAL_RC} -eq 250 ]; then
224         MORE_FAILS=1
225     fi
226     RC=$((RC+PARTIAL_RC))
227 done
228
229 # Log the final result
230 if [ ${RC} -eq 0 ]; then
231     set +x
232     echo
233     echo "========================================================================================================================================"
234     echo "Final result of all test loops:                                                                                                 | PASS |"
235     echo "All critical tests have passed."
236     echo "========================================================================================================================================"
237     echo
238     set -x
239 elif [ ${MORE_FAILS} -eq 0 ]; then
240     if [ ${RC} -eq 1 ]; then
241         HLP_STR="test has"
242     else
243         HLP_STR="tests have"
244     fi
245     set +x
246     echo
247     echo "========================================================================================================================================"
248     echo "Final result of all test loops:                                                                                                 | FAIL |"
249     echo "${RC} critical ${HLP_STR} failed."
250     echo "========================================================================================================================================"
251     echo
252     set -x
253 else
254     set +x
255     echo
256     echo "========================================================================================================================================"
257     echo "Final result of all test loops:                                                                                                 | FAIL |"
258     echo "More then 250 critical tests have failed in one test loop."
259     echo "========================================================================================================================================"
260     echo
261     set -x
262 fi
263
264 echo Post-processing test data...
265
266 # Rebot output post-processing
267 rebot --noncritical EXPECTED_FAILING \
268       --output output.xml \
269       ./log_test_set1.xml ./log_test_set2.xml ./log_test_set3.xml
270
271 # Remove unnecessary log files
272 rm -f ./log_test_set1.xml ./log_test_set2.xml ./log_test_set3.xml
273
274 echo Post-processing finished.
275
276 if [ ${RC} -eq 0 ]; then
277     RETURN_STATUS=0
278 else
279     RETURN_STATUS=1
280 fi
281
282 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.