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