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