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