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