rls1710: rls_notes update.
[csit.git] / bootstrap-hc2vpp-verify.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 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
21
22 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
23 VIRL_SERVER=""
24
25 VIRL_USERNAME=jenkins-in
26 VIRL_PKEY=priv_key
27 VIRL_SERVER_STATUS_FILE="status"
28 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
29
30 ARCHIVE_ARTIFACTS=(log.html output.xml report.html honeycomb.log)
31
32 OS=$1
33
34 if [ -f "/etc/redhat-release" ]; then
35     DISTRO="CENTOS"
36     sudo yum install -y python-devel python-virtualenv
37     VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_CENTOS)
38     VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_CENTOS)
39 else
40     DISTRO="UBUNTU"
41     export DEBIAN_FRONTEND=noninteractive
42     sudo apt-get -y update
43     sudo apt-get -y install libpython2.7-dev python-virtualenv
44     VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_UBUNTU)
45     VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_UBUNTU)
46 fi
47
48 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
49
50 function ssh_do() {
51     echo
52     echo "### "  ssh $@
53     ssh ${SSH_OPTIONS} $@
54 }
55
56 rm -f ${VIRL_PKEY}
57 cat > ${VIRL_PKEY} <<EOF
58 -----BEGIN RSA PRIVATE KEY-----
59 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
60 GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX
61 VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9
62 asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz
63 L3dM3iSmlmQlzv9bThjo+nI4KFYh6m5wrZmAo5r/4q9CIJc21HVnTqkGOWJIZz6J
64 73lePJVSq5gYqaoGw3swFEA/MDkOx7baWKSoLQIDAQABAoIBAQCNBeolNp+JWJ76
65 gQ4fwLsknyXSV6sxYyhkDW4PEwwcTU06uqce0AAzXVffxne0fMe48x47+zqBgPbb
66 4huM+Pu8B9nfojUMr5TaYtl9Zbgpk3F8H7dT7LKOa6XrxvZTZrADSRc30+Z26zPN
67 e9zTaf42Gvt0/l0Zs1BHwbaOXqO+XuwJ3/F9Sf3PQYWXD3EOWjpHDP/X/1vAs6lV
68 SLkm6J/9KKE1m6I6LTYjIXuYt4SXybW6N2TSy54hhQtYcDUnIU2hR/PHVWKrGA0J
69 kELgrtTNTdbML27O5gFWU4PLUEYTZ9fN11D6qUZKxLcPOiPPHXkiILMRCCnG5DYI
70 ksBAU/YlAoGBAPxZO9VO18TYc8THV1nLKcvT2+1oSs1UcA2wNQMU55t910ZYinRa
71 MRwUhMOf8Mv5wOeiZaRICQB1PnVWtDVmGECgPpK6jUxqAwn8rgJcnoafLGL5YKMY
72 RVafTe6N5LXgCaOcJrk21wxs6v7ninEbUxxc575urOvZMBkymDw91dwbAoGBAPwa
73 YRhKhrzFKZzdK0RadVjnxKvolUllpoqqg3XuvmeAJHAOAnaOgVWq68NAcp5FZJv0
74 2D2Up7TX8pjf9MofP1SJbcraKBpK4NzfNkA0dSdEi+FhVofAJ9umB2o5LW1n7sab
75 UIrjsdzSJK/9Zb9yTTHPyibYzNEgaJV1HsbxfEFXAoGAYO2RmvRm0phll18OQVJV
76 IpKk9kLKAKZ/R/K32hAsikBC8SVPQTPniyaifFWx81diblalff2hX4ipTf7Yx24I
77 wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS
78 NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
79 xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
80 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
81 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
82 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
83 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
84 -----END RSA PRIVATE KEY-----
85 EOF
86 chmod 600 ${VIRL_PKEY}
87
88 #
89 # Pick a random host from the array of VIRL servers, and attempt
90 # to reach it and verify it's status.
91 #
92 # The server must be reachable, and have a "status" file with
93 # the content "PRODUCTION", to be selected.
94 #
95 # If the server is not reachable, or does not have the correct
96 # status, remove it from the array and start again.
97 #
98 # Abort if there are no more servers left in the array.
99 #
100 while [[ ! "$VIRL_SERVER" ]]
101 do
102     num_hosts=${#VIRL_SERVERS[@]}
103     if [ $num_hosts == 0 ]
104     then
105         echo "No more VIRL candidate hosts available, failing."
106         exit 127
107     fi
108     element=$[ $RANDOM % $num_hosts ]
109     virl_server_candidate=${VIRL_SERVERS[$element]}
110     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1)
111     echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\"
112     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
113     then
114         # Candidate is in good status. Select this server.
115         VIRL_SERVER="$virl_server_candidate"
116     else
117         # Candidate is in bad status. Remove from array.
118         VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}")
119     fi
120 done
121
122 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
123
124 # VPP, VPP plugin and Honeycomb packages should already be in working directory
125 if [ "${OS}" == "centos7" ]; then
126     VPP_PKGS=(*.rpm)
127 else
128     VPP_PKGS=(*.deb)
129 fi
130 echo ${VPP_PKGS[@]}
131 VIRL_DIR_LOC="/tmp"
132 VPP_PKGS_FULL=(${VPP_PKGS[@]})
133
134 # Prepend directory location at remote host to package file list
135 for index in "${!VPP_PKGS_FULL[@]}"; do
136     VPP_PKGS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_PKGS_FULL[${index}]}
137 done
138
139 echo "Updated file names: " ${VPP_PKGS_FULL[@]}
140
141 cat ${VIRL_PKEY}
142
143 # Copy the files to VIRL hosts
144 DONE=""
145 for index in "${!VIRL_SERVER[@]}"; do
146     # Do not copy files in case they have already been copied to the VIRL host
147     [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1
148
149     if [ "${copy}" -eq "0" ]; then
150         echo "files have already been copied to the VIRL host ${VIRL_SERVER[${index}]}"
151     else
152         if [ "${OS}" == "centos7" ]; then
153             scp ${SSH_OPTIONS} *.rpm \
154                 ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
155         else
156             scp ${SSH_OPTIONS} *.deb \
157                 ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
158         fi
159          result=$?
160         if [ "${result}" -ne "0" ]; then
161             echo "Failed to copy files to VIRL host ${VIRL_SERVER[${index}]}"
162             echo ${result}
163             exit ${result}
164         else
165             echo "files successfully copied to the VIRL host ${VIRL_SERVER[${index}]}"
166         fi
167         DONE+=(${VIRL_SERVER[${index}]})
168     fi
169 done
170
171 # Start a simulation on VIRL server
172 echo "Starting simulation on VIRL server"
173
174 function stop_virl_simulation {
175     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
176         "stop-testcase ${VIRL_SID}"
177 }
178
179 VIRL_SID=$(ssh ${SSH_OPTIONS} \
180     ${VIRL_USERNAME}@${VIRL_SERVER} \
181     "start-testcase -c ${VIRL_TOPOLOGY} -r ${VIRL_RELEASE} ${VPP_PKGS_FULL[@]}")
182 retval=$?
183 if [ "${retval}" -ne "0" ]; then
184     echo "VIRL simulation start failed"
185     exit ${retval}
186 fi
187
188 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
189     echo "No VIRL session ID reported."
190     exit 127
191 fi
192
193 # Upon script exit, cleanup the simulation execution
194 trap stop_virl_simulation EXIT
195 echo ${VIRL_SID}
196
197 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
198
199 # Download the topology file from virl session
200 scp ${SSH_OPTIONS} \
201     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
202     topologies/enabled/topology.yaml
203
204 retval=$?
205 if [ "${retval}" -ne "0" ]; then
206     echo "Failed to copy topology file from VIRL simulation"
207     exit ${retval}
208 fi
209
210 virtualenv --system-site-packages env
211 . env/bin/activate
212
213 echo pip install
214 pip install -r ${SCRIPT_DIR}/requirements.txt
215
216 pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
217           -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
218           -d ${SCRIPT_DIR}/topologies/enabled/topology.yaml \
219           -vvv
220
221 if [ "$?" -ne "0" ]; then
222     echo "Topology schema validation failed."
223     echo "However, the tests will start."
224 fi
225
226 PYTHONPATH=`pwd` pybot -L TRACE -W 136\
227     -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology.yaml \
228     --suite "tests.vpp.func" \
229     --include HC_FUNC \
230     --noncritical EXPECTED_FAILING \
231     tests/
232
233 RETURN_STATUS=$?
234
235 # Get Honeycomb log file from virl host
236 scp ${SSH_OPTIONS} \
237     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/honeycomb.log . || true
238
239 # Archive artifacts
240 mkdir archive
241 for i in ${ARCHIVE_ARTIFACTS[@]}; do
242     cp $( readlink -f ${i} | tr '\n' ' ' ) archive/
243 done
244
245 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.