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