Update of VPP_STABLE_VER
[csit.git] / bootstrap-vpp-honeycomb.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 VIRL_TOPOLOGY=double-ring-nested.trusty
33 VIRL_RELEASE=csit-ubuntu-14.04.4_2016-10-07_1.3
34
35 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
36
37 function ssh_do() {
38     echo
39     echo "### "  ssh $@
40     ssh ${SSH_OPTIONS} $@
41 }
42
43 rm -f ${VIRL_PKEY}
44 cat > ${VIRL_PKEY} <<EOF
45 -----BEGIN RSA PRIVATE KEY-----
46 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
47 GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX
48 VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9
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gg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
66 xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
67 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
68 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
69 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
70 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
71 -----END RSA PRIVATE KEY-----
72 EOF
73 chmod 600 ${VIRL_PKEY}
74
75 #
76 # Pick a random host from the array of VIRL servers, and attempt
77 # to reach it and verify it's status.
78 #
79 # The server must be reachable, and have a "status" file with
80 # the content "PRODUCTION", to be selected.
81 #
82 # If the server is not reachable, or does not have the correct
83 # status, remove it from the array and start again.
84 #
85 # Abort if there are no more servers left in the array.
86 #
87 while [[ ! "$VIRL_SERVER" ]]
88 do
89     num_hosts=${#VIRL_SERVERS[@]}
90     if [ $num_hosts == 0 ]
91     then
92         echo "No more VIRL candidate hosts available, failing."
93         exit 127
94     fi
95     element=$[ $RANDOM % $num_hosts ]
96     virl_server_candidate=${VIRL_SERVERS[$element]}
97     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1)
98     echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\"
99     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
100     then
101         # Candidate is in good status. Select this server.
102         VIRL_SERVER="$virl_server_candidate"
103     else
104         # Candidate is in bad status. Remove from array.
105         VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}")
106     fi
107 done
108
109 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
110
111 # Download the latest VPP and HC .deb packages
112 echo Downloading packages...
113 bash ${SCRIPT_DIR}/resources/tools/download_hc_pkgs.sh
114
115 VPP_DEBS=(*.deb)
116 echo ${VPP_DEBS[@]}
117 VIRL_DIR_LOC="/tmp"
118 VPP_DEBS_FULL=(${VPP_DEBS[@]})
119
120 # Prepend directory location at remote host to deb file list
121 for index in "${!VPP_DEBS_FULL[@]}"; do
122     VPP_DEBS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_DEBS_FULL[${index}]}
123 done
124
125 echo "Updated file names: " ${VPP_DEBS_FULL[@]}
126
127 cat ${VIRL_PKEY}
128
129 # Copy the files to VIRL hosts
130 DONE=""
131 for index in "${!VIRL_SERVER[@]}"; do
132     # Do not copy files in case they have already been copied to the VIRL host
133     [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1
134
135     if [ "${copy}" -eq "0" ]; then
136         echo "deb files have already been copied to the VIRL host ${VIRL_SERVER[${index}]}"
137     else
138         scp ${SSH_OPTIONS} *.deb \
139         ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/
140
141          result=$?
142         if [ "${result}" -ne "0" ]; then
143             echo "Failed to copy deb files to VIRL host ${VIRL_SERVER[${index}]}"
144             echo ${result}
145             exit ${result}
146         else
147             echo "deb files successfully copied to the VIRL host ${VIRL_SERVER[${index}]}"
148         fi
149         DONE+=(${VIRL_SERVER[${index}]})
150     fi
151 done
152
153 # Start a simulation on VIRL server
154 echo "Starting simulation on VIRL server"
155
156 function stop_virl_simulation {
157     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
158         "stop-testcase ${VIRL_SID}"
159 }
160
161 VIRL_SID=$(ssh ${SSH_OPTIONS} \
162     ${VIRL_USERNAME}@${VIRL_SERVER} \
163     "start-testcase -c ${VIRL_TOPOLOGY} -r ${VIRL_RELEASE} ${VPP_DEBS_FULL[@]}")
164 retval=$?
165 if [ "$?" -ne "0" ]; then
166     echo "VIRL simulation start failed"
167     exit ${retval}
168 fi
169
170 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
171     echo "No VIRL session ID reported."
172     exit 127
173 fi
174
175 # Upon script exit, cleanup the simulation execution
176 trap stop_virl_simulation EXIT
177 echo ${VIRL_SID}
178
179 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
180
181 # Download the topology file from virl session
182 scp ${SSH_OPTIONS} \
183     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
184     topologies/enabled/topology.yaml
185
186 retval=$?
187 if [ "$?" -ne "0" ]; then
188     echo "Failed to copy topology file from VIRL simulation"
189     exit ${retval}
190 fi
191
192 virtualenv --system-site-packages env
193 . env/bin/activate
194
195 echo pip install
196 pip install -r ${SCRIPT_DIR}/requirements.txt
197
198 pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
199           -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
200           -d ${SCRIPT_DIR}/topologies/enabled/topology.yaml \
201           -vvv
202
203 if [ "$?" -ne "0" ]; then
204     echo "Topology schema validation failed."
205     echo "However, the tests will start."
206 fi
207
208 PYTHONPATH=`pwd` pybot -L TRACE -W 136\
209     -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology.yaml \
210     --suite "tests.func" \
211     --include honeycomb_sanity \
212     --noncritical EXPECTED_FAILING \
213     tests/

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