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

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