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