Markdown doc with FD.io CSIT physical lab design for Hsw.
[csit.git] / bootstrap-hc2vpp-integration.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 JOB_ARCHIVE_ARTIFACTS=(log.html output.xml report.html honeycomb.log)
31 LOG_ARCHIVE_ARTIFACTS=(log.html output.xml report.html honeycomb.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
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 # Download VPP and HC packages from the current branch
131 echo Downloading packages...
132 bash ${SCRIPT_DIR}/resources/tools/scripts/download_hc_pkgs.sh ${STREAM} ${OS}
133
134 if [ "${OS}" == "centos7" ]; then
135     VPP_PKGS=(*.rpm)
136 else
137     VPP_PKGS=(*.deb)
138 fi
139 echo ${VPP_PKGS[@]}
140 VIRL_DIR_LOC="/tmp"
141 VPP_PKGS_FULL=(${VPP_PKGS[@]})
142
143 # Prepend directory location at remote host to package file list
144 for index in "${!VPP_PKGS_FULL[@]}"; do
145     VPP_PKGS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_PKGS_FULL[${index}]}
146 done
147
148 echo "Updated file names: " ${VPP_PKGS_FULL[@]}
149
150 cat ${VIRL_PKEY}
151
152 # Copy the files to VIRL hosts
153 DONE=""
154 for index in "${!VIRL_SERVER[@]}"; do
155     # Do not copy files in case they have already been copied to the VIRL host
156     [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1
157
158     if [ "${copy}" -eq "0" ]; then
159         echo "files have already been copied to the VIRL host ${VIRL_SERVER[${index}]}"
160     else
161         if [ "${OS}" == "centos7" ]; then
162             scp ${SSH_OPTIONS} *.rpm \
163                 ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
164         else
165             scp ${SSH_OPTIONS} *.deb \
166                 ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
167         fi
168          result=$?
169         if [ "${result}" -ne "0" ]; then
170             echo "Failed to copy files to VIRL host ${VIRL_SERVER[${index}]}"
171             echo ${result}
172             exit ${result}
173         else
174             echo "files successfully copied to the VIRL host ${VIRL_SERVER[${index}]}"
175         fi
176         DONE+=(${VIRL_SERVER[${index}]})
177     fi
178 done
179
180 # Start a simulation on VIRL server
181 echo "Starting simulation on VIRL server"
182
183 function stop_virl_simulation {
184     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
185         "stop-testcase ${VIRL_SID}"
186 }
187
188 VIRL_SID=$(ssh ${SSH_OPTIONS} \
189     ${VIRL_USERNAME}@${VIRL_SERVER} \
190     "start-testcase -c ${VIRL_TOPOLOGY} -r ${VIRL_RELEASE} ${VPP_PKGS_FULL[@]}")
191 retval=$?
192 if [ "${retval}" -ne "0" ]; then
193     echo "VIRL simulation start failed"
194     exit ${retval}
195 fi
196
197 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
198     echo "No VIRL session ID reported."
199     exit 127
200 fi
201
202 # Upon script exit, cleanup the simulation execution
203 trap stop_virl_simulation EXIT
204 echo ${VIRL_SID}
205
206 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
207
208 # Download the topology file from virl session
209 scp ${SSH_OPTIONS} \
210     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
211     topologies/enabled/topology.yaml
212
213 retval=$?
214 if [ "${retval}" -ne "0" ]; then
215     echo "Failed to copy topology file from VIRL simulation"
216     exit ${retval}
217 fi
218
219 virtualenv --system-site-packages env
220 . env/bin/activate
221
222 echo pip install
223 pip install -r ${SCRIPT_DIR}/requirements.txt
224
225 pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
226           -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
227           -d ${SCRIPT_DIR}/topologies/enabled/topology.yaml \
228           -vvv
229
230 if [ "$?" -ne "0" ]; then
231     echo "Topology schema validation failed."
232     echo "However, the tests will start."
233 fi
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_NSH \
241     --noncritical EXPECTED_FAILING \
242     tests/
243
244 RETURN_STATUS=$?
245
246 # Get Honeycomb log file from virl host
247 scp ${SSH_OPTIONS} \
248     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/honeycomb.log . || true
249
250 # Archive JOB artifacts in jenkins
251 for i in ${JOB_ARCHIVE_ARTIFACTS[@]}; do
252     cp $( readlink -f ${i} | tr '\n' ' ' ) ${JOB_ARCHIVE_DIR}/
253 done
254 # Archive JOB artifacts to logs.fd.io
255 for i in ${LOG_ARCHIVE_ARTIFACTS[@]}; do
256     cp $( readlink -f ${i} | tr '\n' ' ' ) ${LOG_ARCHIVE_DIR}/
257 done
258
259 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.