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