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