Patch to tldk bootstrap on the tldk package download.
[csit.git] / bootstrap-TLDK.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 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
21 export PYTHONPATH=${SCRIPT_DIR}
22
23 export DEBIAN_FRONTEND=noninteractive
24 sudo apt-get -y update
25 sudo apt-get -y install libpython2.7-dev python-virtualenv
26
27 VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30")
28 VIRL_SERVER=""
29
30 VIRL_USERNAME=jenkins-in
31 VIRL_PKEY=priv_key
32 VIRL_SERVER_STATUS_FILE="status"
33 VIRL_SERVER_EXPECTED_STATUS="PRODUCTION"
34
35 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
36
37 DPDK_VERSION=16.11.1
38 DPDK_DIR=dpdk
39 DPDK_PACKAGE=${DPDK_DIR}"-"${DPDK_VERSION}.tar.xz
40
41 function ssh_do() {
42     echo
43     echo "### "  ssh $@
44     ssh ${SSH_OPTIONS} $@
45 }
46
47 rm -f ${VIRL_PKEY}
48 cat > ${VIRL_PKEY} <<EOF
49 -----BEGIN RSA PRIVATE KEY-----
50 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
51 GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiH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ipTf7Yx24I
68 wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS
69 NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM
70 xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
71 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
72 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
73 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
74 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
75 -----END RSA PRIVATE KEY-----
76 EOF
77 chmod 600 ${VIRL_PKEY}
78
79 #
80 # Pick a random host from the array of VIRL servers, and attempt
81 # to reach it and verify it's status.
82 #
83 # The server must be reachable, and have a "status" file with
84 # the content "PRODUCTION", to be selected.
85 #
86 # If the server is not reachable, or does not have the correct
87 # status, remove it from the array and start again.
88 #
89 # Abort if there are no more servers left in the array.
90 #
91 while [[ ! "$VIRL_SERVER" ]]
92 do
93     num_hosts=${#VIRL_SERVERS[@]}
94     if [ $num_hosts == 0 ]
95     then
96         echo "No more VIRL candidate hosts available, failing."
97         exit 127
98     fi
99     element=$[ $RANDOM % $num_hosts ]
100     virl_server_candidate=${VIRL_SERVERS[$element]}
101     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1)
102     echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\"
103     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
104     then
105         # Candidate is in good status. Select this server.
106         VIRL_SERVER="$virl_server_candidate"
107     else
108         # Candidate is in bad status. Remove from array.
109         VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}")
110     fi
111 done
112
113
114 #we will pack all the TLDK depend files and copy it to the VIRL_SERVER
115 VIRL_DIR_LOC="/tmp"
116 TLDK_TAR_FILE="tldk_depends.tar.gz"
117
118 wget "fast.dpdk.org/rel/${DPDK_PACKAGE}"
119
120 tar zcf ${TLDK_TAR_FILE} ${DPDK_PACKAGE} ./tldk/ \
121     ./tests/tldk/tldk_testconfig/
122
123 cat ${VIRL_PKEY}
124 # Copy the files to VIRL host
125 scp ${SSH_OPTIONS} ${TLDK_TAR_FILE} \
126     ${VIRL_USERNAME}@${VIRL_SERVER}:${VIRL_DIR_LOC}/
127
128 result=$?
129 if [ "${result}" -ne "0" ]; then
130     echo "Failed to copy tldk package file to virl host"
131     echo ${result}
132     exit ${result}
133 fi
134
135 # Start a simulation on VIRL server
136 echo "Starting simulation on VIRL server"
137
138 VIRL_TOPOLOGY=double-ring-nested.xenial
139 VIRL_RELEASE=csit-ubuntu-16.04.1_2016-12-19_1.6
140
141 function stop_virl_simulation {
142     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
143         "stop-testcase ${VIRL_SID}"
144 }
145
146 # Upon script exit, cleanup the simulation execution
147 trap stop_virl_simulation EXIT
148
149 # use the start-testcase-TLDK for the TLDK test case
150 VIRL_SID=$(ssh ${SSH_OPTIONS} \
151     ${VIRL_USERNAME}@${VIRL_SERVER} \
152     "start-testcase-TLDK -c ${VIRL_TOPOLOGY} -r ${VIRL_RELEASE} ${VIRL_DIR_LOC}/${TLDK_TAR_FILE}")
153 retval=$?
154 if [ "${retval}" -ne "0" ]; then
155     echo "VIRL simulation start failed"
156     exit ${retval}
157 fi
158
159 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
160     echo "No VIRL session ID reported."
161     exit 127
162 fi
163
164 echo ${VIRL_SID}
165
166 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
167
168 # Download the topology file from virl session
169 scp ${SSH_OPTIONS} \
170     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
171     topologies/enabled/topology.yaml
172
173 retval=$?
174 if [ "${retval}" -ne "0" ]; then
175     echo "Failed to copy topology file from VIRL simulation"
176     exit ${retval}
177 fi
178
179 # create a python virtual environment env
180 virtualenv --system-site-packages env
181 . env/bin/activate
182
183 echo pip install
184 pip install -r ${SCRIPT_DIR}/requirements.txt
185
186 pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
187           -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
188           -d ${SCRIPT_DIR}/topologies/enabled/topology.yaml \
189           -vvv
190
191 if [ "$?" -ne "0" ]; then
192     echo "Topology schema validation failed."
193     echo "However, the tests will start."
194 fi
195
196 PYTHONPATH=`pwd` pybot -L TRACE -W 150 \
197     -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology.yaml \
198     --suite "tests.tldk.func" \
199     --include vm_envAND3_node_single_link_topo \
200     --noncritical EXPECTED_FAILING \
201     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.