96efa313611def3a31f6b27d025c36e37968bc29
[csit.git] / bootstrap.sh
1 #!/bin/bash
2 # Copyright (c) 2016 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 SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error"
33
34 function ssh_do() {
35     echo
36     echo "### "  ssh $@
37     ssh ${SSH_OPTIONS} $@
38 }
39
40 rm -f ${VIRL_PKEY}
41 cat > ${VIRL_PKEY} <<EOF
42 -----BEGIN RSA PRIVATE KEY-----
43 MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6
44 GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX
45 VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9
46 asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz
47 L3dM3iS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FrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj
64 yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS
65 U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ
66 cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh
67 maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E=
68 -----END RSA PRIVATE KEY-----
69 EOF
70 chmod 600 ${VIRL_PKEY}
71
72 #
73 # Pick a random host from the array of VIRL servers, and attempt
74 # to reach it and verify it's status.
75 #
76 # The server must be reachable, and have a "status" file with
77 # the content "PRODUCTION", to be selected.
78 #
79 # If the server is not reachable, or does not have the correct
80 # status, remove it from the array and start again.
81 #
82 # Abort if there are no more servers left in the array.
83 #
84 while [[ ! "$VIRL_SERVER" ]]
85 do
86     num_hosts=${#VIRL_SERVERS[@]}
87     if [ $num_hosts == 0 ]
88     then
89         echo "No more VIRL candidate hosts available, failing."
90         exit 127
91     fi
92     element=$[ $RANDOM % $num_hosts ]
93     virl_server_candidate=${VIRL_SERVERS[$element]}
94     virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1)
95     echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\"
96     if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ]
97     then
98         # Candidate is in good status. Select this server.
99         VIRL_SERVER="$virl_server_candidate"
100     else
101         # Candidate is in bad status. Remove from array.
102         VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}")
103     fi
104 done
105
106 # Temporarily download VPP packages from nexus.fd.io
107 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
108
109 if [ "${#}" -ne "0" ]; then
110     arr=(${@})
111     echo ${arr[0]}
112 else
113     rm -f *.deb
114     VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER)
115     VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL)
116     VPP_CLASSIFIER="-deb"
117     wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
118     wget -q "${VPP_REPO_URL}/vpp-dbg/${VPP_STABLE_VER}/vpp-dbg-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
119     wget -q "${VPP_REPO_URL}/vpp-dev/${VPP_STABLE_VER}/vpp-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
120     wget -q "${VPP_REPO_URL}/vpp-dpdk-dev/${VPP_STABLE_VER}/vpp-dpdk-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
121     wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${VPP_STABLE_VER}/vpp-dpdk-dkms-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
122     wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
123     wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
124 fi
125
126 VPP_DEBS=(*.deb)
127 echo ${VPP_DEBS[@]}
128 VIRL_DIR_LOC="/tmp"
129 VPP_DEBS_FULL=(${VPP_DEBS[@]})
130
131 # Prepend directory location at remote host to deb file list
132 for index in "${!VPP_DEBS_FULL[@]}"; do
133     VPP_DEBS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_DEBS_FULL[${index}]}
134 done
135
136 echo "Updated file names: " ${VPP_DEBS_FULL[@]}
137
138 cat ${VIRL_PKEY}
139 # Copy the files to VIRL host
140 scp ${SSH_OPTIONS} *.deb \
141     ${VIRL_USERNAME}@${VIRL_SERVER}:${VIRL_DIR_LOC}/
142
143 result=$?
144 if [ "${result}" -ne "0" ]; then
145     echo "Failed to copy vpp deb files to virl host"
146     echo ${result}
147     exit ${result}
148 fi
149
150 # Start a simulation on VIRL server
151 echo "Starting simulation on VIRL server"
152
153 function stop_virl_simulation {
154     ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER}\
155         "stop-testcase ${VIRL_SID}"
156 }
157
158 VIRL_SID=$(ssh ${SSH_OPTIONS} \
159     ${VIRL_USERNAME}@${VIRL_SERVER} \
160     "start-testcase -c double-ring-nested ${VPP_DEBS_FULL[@]}")
161 retval=$?
162 if [ "$?" -ne "0" ]; then
163     echo "VIRL simulation start failed"
164     exit ${retval}
165 fi
166
167 if [[ ! "${VIRL_SID}" =~ session-[a-zA-Z0-9_]{6} ]]; then
168     echo "No VIRL session ID reported."
169     exit 127
170 fi
171
172 # Upon script exit, cleanup the simulation execution
173 trap stop_virl_simulation EXIT
174 echo ${VIRL_SID}
175
176 ssh_do ${VIRL_USERNAME}@${VIRL_SERVER} cat /scratch/${VIRL_SID}/topology.yaml
177
178 # Download the topology file from virl session
179 scp ${SSH_OPTIONS} \
180     ${VIRL_USERNAME}@${VIRL_SERVER}:/scratch/${VIRL_SID}/topology.yaml \
181     topologies/enabled/topology.yaml
182
183 retval=$?
184 if [ "$?" -ne "0" ]; then
185     echo "Failed to copy topology file from VIRL simulation"
186     exit ${retval}
187 fi
188
189
190 virtualenv --system-site-packages env
191 . env/bin/activate
192
193 echo pip install
194 pip install -r ${SCRIPT_DIR}/requirements.txt
195
196 pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \
197           -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \
198           -d ${SCRIPT_DIR}/topologies/enabled/topology.yaml \
199           -vvv
200
201 if [ "$?" -ne "0" ]; then
202     echo "Topology schema validation failed."
203     echo "However, the tests will start."
204 fi
205
206 PYTHONPATH=`pwd` pybot -L TRACE -W 145\
207     -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology.yaml \
208     --suite "tests.func" \
209     --include vm_envAND3_node_single_link_topo \
210     --include vm_envAND3_node_double_link_topo \
211     --exclude PERFTEST \
212     --exclude SKIP_PATCH \
213     --noncritical EXPECTED_FAILING \
214     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.