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