CSIT-651 Add keywords and template for memif
[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 export DEBIAN_FRONTEND=noninteractive
21 sudo apt-get -y update
22 sudo apt-get -y install libpython2.7-dev python-virtualenv
23
24 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
25 VIRL_SERVER=""
26
27 VIRL_USERNAME=jenkins-in
28 VIRL_PKEY=priv_key
29 VIRL_SERVER_STATUS_FILE="status"
30 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
31
32 OS=$1
33
34 if [ "${OS}" == "ubuntu1604" ]; then
35     VIRL_TOPOLOGY=double-ring-nested.xenial
36     VIRL_RELEASE=csit-ubuntu-16.04.1_2017-02-23_1.8
37 elif [ "${OS}" == "centos7" ]; then
38     VIRL_TOPOLOGY=double-ring-nested.centos7
39     VIRL_RELEASE=csit-centos-7.3-1611_2017-02-23_1.4
40 fi
41
42 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
43
44 function ssh_do() {
45     echo
46     echo "### "  ssh $@
47     ssh ${SSH_OPTIONS} $@
48 }
49
50 rm -f ${VIRL_PKEY}
51 cat > ${VIRL_PKEY} <<EOF
52 -----BEGIN RSA PRIVATE KEY-----
53 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYr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k9kLKAKZ/R/K32hAsikBC8SVPQTPniyaifFWx81diblalff2hX4ipTf7Yx24I
71 wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS
72 NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
73 xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
74 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
75 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
76 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
77 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
78 -----END RSA PRIVATE KEY-----
79 EOF
80 chmod 600 ${VIRL_PKEY}
81
82 #
83 # Pick a random host from the array of VIRL servers, and attempt
84 # to reach it and verify it's status.
85 #
86 # The server must be reachable, and have a "status" file with
87 # the content "PRODUCTION", to be selected.
88 #
89 # If the server is not reachable, or does not have the correct
90 # status, remove it from the array and start again.
91 #
92 # Abort if there are no more servers left in the array.
93 #
94 while [[ ! "$VIRL_SERVER" ]]
95 do
96     num_hosts=${#VIRL_SERVERS[@]}
97     if [ $num_hosts == 0 ]
98     then
99         echo "No more VIRL candidate hosts available, failing."
100         exit 127
101     fi
102     element=$[ $RANDOM % $num_hosts ]
103     virl_server_candidate=${VIRL_SERVERS[$element]}
104     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1)
105     echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\"
106     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
107     then
108         # Candidate is in good status. Select this server.
109         VIRL_SERVER="$virl_server_candidate"
110     else
111         # Candidate is in bad status. Remove from array.
112         VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}")
113     fi
114 done
115
116 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
117
118 # VPP, VPP plugin and Honeycomb packages should already be in working directory
119 if [ "${OS}" == "centos7" ]; then
120     VPP_PKGS=(*.rpm)
121 else
122     VPP_PKGS=(*.deb)
123 fi
124 echo ${VPP_PKGS[@]}
125 VIRL_DIR_LOC="/tmp"
126 VPP_PKGS_FULL=(${VPP_PKGS[@]})
127
128 # Prepend directory location at remote host to package file list
129 for index in "${!VPP_PKGS_FULL[@]}"; do
130     VPP_PKGS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_PKGS_FULL[${index}]}
131 done
132
133 echo "Updated file names: " ${VPP_PKGS_FULL[@]}
134
135 cat ${VIRL_PKEY}
136
137 # Copy the files to VIRL hosts
138 DONE=""
139 for index in "${!VIRL_SERVER[@]}"; do
140     # Do not copy files in case they have already been copied to the VIRL host
141     [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1
142
143     if [ "${copy}" -eq "0" ]; then
144         echo "files have already been copied to the VIRL host ${VIRL_SERVER[${index}]}"
145     else
146         if [ "${OS}" == "centos7" ]; then
147             scp ${SSH_OPTIONS} *.rpm \
148                 ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
149         else
150             scp ${SSH_OPTIONS} *.deb \
151                 ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
152         fi
153          result=$?
154         if [ "${result}" -ne "0" ]; then
155             echo "Failed to copy files to VIRL host ${VIRL_SERVER[${index}]}"
156             echo ${result}
157             exit ${result}
158         else
159             echo "files successfully copied to the VIRL host ${VIRL_SERVER[${index}]}"
160         fi
161         DONE+=(${VIRL_SERVER[${index}]})
162     fi
163 done
164
165 # Start a simulation on VIRL server
166 echo "Starting simulation on VIRL server"
167
168 function stop_virl_simulation {
169     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
170         "stop-testcase ${VIRL_SID}"
171 }
172
173 VIRL_SID=$(ssh ${SSH_OPTIONS} \
174     ${VIRL_USERNAME}@${VIRL_SERVER} \
175     "start-testcase -c ${VIRL_TOPOLOGY} -r ${VIRL_RELEASE} ${VPP_PKGS_FULL[@]}")
176 retval=$?
177 if [ "${retval}" -ne "0" ]; then
178     echo "VIRL simulation start failed"
179     exit ${retval}
180 fi
181
182 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
183     echo "No VIRL session ID reported."
184     exit 127
185 fi
186
187 # Upon script exit, cleanup the simulation execution
188 trap stop_virl_simulation EXIT
189 echo ${VIRL_SID}
190
191 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
192
193 # Download the topology file from virl session
194 scp ${SSH_OPTIONS} \
195     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
196     topologies/enabled/topology.yaml
197
198 retval=$?
199 if [ "${retval}" -ne "0" ]; then
200     echo "Failed to copy topology file from VIRL simulation"
201     exit ${retval}
202 fi
203
204 virtualenv --system-site-packages env
205 . env/bin/activate
206
207 echo pip install
208 pip install -r ${SCRIPT_DIR}/requirements.txt
209
210 pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
211           -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
212           -d ${SCRIPT_DIR}/topologies/enabled/topology.yaml \
213           -vvv
214
215 if [ "$?" -ne "0" ]; then
216     echo "Topology schema validation failed."
217     echo "However, the tests will start."
218 fi
219
220 PYTHONPATH=`pwd` pybot -L TRACE -W 136\
221     -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology.yaml \
222     --suite "tests.vpp.func" \
223     --include HC_FUNC \
224     --noncritical EXPECTED_FAILING \
225     tests/
226
227 # Get Honeycomb log file from virl host
228 scp ${SSH_OPTIONS} \
229     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/honeycomb.log . || true

©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.