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