Merge "TcpDump File addition"
[releng/builder.git] / jjb / integration / include-raw-integration-deploy-openstack-run-test.sh
1 #@IgnoreInspection BashAddShebang
2 # Activate robotframework virtualenv
3 # ${ROBOT_VENV} comes from the include-raw-integration-install-robotframework.sh
4 # script.
5 source ${ROBOT_VENV}/bin/activate
6
7 # TODO: remove this work to run changes.py if/when it's moved higher up to be visible at the Robot level
8 echo "showing recent changes that made it in to the distribution used by this job"
9 pip install --upgrade urllib3
10 python ${WORKSPACE}/test/tools/distchanges/changes.py -d /tmp/distribution_folder \
11                   -u ${ACTUALBUNDLEURL} -b ${DISTROBRANCH} \
12                   -r ssh://jenkins-${SILO}@git.opendaylight.org:29418 || true
13
14 echo "#################################################"
15 echo "##         Deploy Openstack 3-node             ##"
16 echo "#################################################"
17
18
19 SSH="ssh -t -t"
20
21 function create_control_node_local_conf {
22 HOSTIP=$1
23 MGRIP=$2
24 ODL_OVS_MANAGERS="$3"
25 #Needs to be removed
26 if [ "${ODL_ML2_BRANCH}" != "stable/ocata" ]; then
27    RECLONE=no
28 else
29    RECLONE=yes
30 fi
31 local_conf_file_name=${WORKSPACE}/local.conf_control_${HOSTIP}
32 cat > ${local_conf_file_name} << EOF
33 [[local|localrc]]
34 LOGFILE=stack.sh.log
35 SCREEN_LOGDIR=/opt/stack/data/log
36 LOG_COLOR=False
37 RECLONE=${RECLONE}
38 EOF
39
40 IFS=,
41 for service_name in ${DISABLE_OS_SERVICES}
42 do
43 cat >> ${local_conf_file_name} << EOF
44 disable_service ${service_name}
45 EOF
46 done
47 for service_name in ${ENABLE_OS_SERVICES}
48 do
49 cat >> ${local_conf_file_name} << EOF
50 enable_service ${service_name}
51 EOF
52 done
53 for plugin_name in ${ENABLE_OS_PLUGINS}
54 do
55 if [ "$plugin_name" == "networking-odl" ]; then
56     ENABLE_PLUGIN_ARGS="${ODL_ML2_DRIVER_REPO} ${ODL_ML2_BRANCH}"
57 elif [ "$plugin_name" == "kuryr-kubernetes" ]; then
58     ENABLE_PLUGIN_ARGS="${DEVSTACK_KUBERNETES_PLUGIN_REPO} master" # note: kuryr-kubernetes only exists in master at the moment
59 elif [ "$plugin_name" == "neutron-lbaas" ]; then
60     ENABLE_PLUGIN_ARGS="${DEVSTACK_LBAAS_PLUGIN_REPO} ${OPENSTACK_BRANCH}"
61 else
62     echo "Error: Invalid plugin $plugin_name, unsupported"
63     continue
64 fi
65 cat >> ${local_conf_file_name} << EOF
66 enable_plugin ${plugin_name} ${ENABLE_PLUGIN_ARGS}
67 EOF
68 done
69 unset IFS
70 if [ "${OPENSTACK_BRANCH}" == "master" ] || [ "${OPENSTACK_BRANCH}" == "stable/ocata" ]; then # Ocata+
71     # placement is mandatory for nova since Ocata, note that this requires computes to enable placement-client
72     # this should be moved into enabled_services for each job (but only for Ocata)
73     echo "enable_service placement-api" >> ${local_conf_file_name}
74 fi
75 cat >> ${local_conf_file_name} << EOF
76 HOST_IP=${HOSTIP}
77 SERVICE_HOST=\$HOST_IP
78
79 NEUTRON_CREATE_INITIAL_NETWORKS=${CREATE_INITIAL_NETWORKS}
80 Q_PLUGIN=ml2
81 Q_ML2_TENANT_NETWORK_TYPE=${TENANT_NETWORK_TYPE}
82 Q_OVS_USE_VETH=True
83
84 ENABLE_TENANT_TUNNELS=True
85
86 MYSQL_HOST=\$SERVICE_HOST
87 RABBIT_HOST=\$SERVICE_HOST
88 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
89 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
90 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
91
92 MYSQL_PASSWORD=mysql
93 RABBIT_PASSWORD=rabbit
94 SERVICE_TOKEN=service
95 SERVICE_PASSWORD=admin
96 ADMIN_PASSWORD=admin
97
98 ODL_PORT=8080
99 ODL_MODE=externalodl
100 ODL_PORT_BINDING_CONTROLLER=${ODL_ML2_PORT_BINDING}
101
102 LIBVIRT_TYPE=qemu
103 ODL_MGR_IP=${MGRIP}
104
105 NEUTRON_LBAAS_SERVICE_PROVIDERV2=${LBAAS_SERVICE_PROVIDER} # Only relevant if neutron-lbaas plugin is enabled
106 EOF
107
108 if [ "${ENABLE_NETWORKING_L2GW}" == "yes" ]; then
109 cat >> ${local_conf_file_name} << EOF
110
111 enable_plugin networking-l2gw ${NETWORKING_L2GW_DRIVER} ${ODL_ML2_BRANCH}
112 NETWORKING_L2GW_SERVICE_DRIVER=L2GW:OpenDaylight:networking_odl.l2gateway.driver.OpenDaylightL2gwDriver:default
113 ENABLED_SERVICES+=,neutron,q-svc,nova,q-meta
114
115 EOF
116 fi
117
118 if [ "${ODL_ML2_DRIVER_VERSION}" == "v2" ]; then
119     echo "ODL_V2DRIVER=True" >> ${local_conf_file_name}
120 fi
121
122 echo "ODL_OVS_MANAGERS=${ODL_OVS_MANAGERS}" >> ${local_conf_file_name}
123
124 # if we are using the old netvirt impl, as determined by the feature name
125 # odl-ovsdb-openstack (note: new impl is odl-netvirt-openstack) then we
126 # want ODL_L3 to be True.  New impl wants it False
127 if [[ ${CONTROLLERFEATURES} == *"odl-ovsdb-openstack"* ]]; then
128     ODL_L3=True
129 else
130     ODL_L3=False
131 fi
132
133 # if we are using the new netvirt impl, as determined by the feature name
134 # odl-netvirt-openstack (note: old impl is odl-ovsdb-openstack) then we
135 # want PROVIDER_MAPPINGS to be used -- this should be fixed if we want to support
136 # external networks in legacy netvirt
137 if [[ ${CONTROLLERFEATURES} == *"odl-netvirt-openstack"* ]]; then
138   ODL_PROVIDER_MAPPINGS="\${PUBLIC_PHYSICAL_NETWORK}:${PUBLIC_BRIDGE}"
139 else
140   ODL_PROVIDER_MAPPINGS=
141 fi
142
143 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
144 cat >> ${local_conf_file_name} << EOF
145 PUBLIC_BRIDGE=${PUBLIC_BRIDGE}
146 PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK}
147 ML2_VLAN_RANGES=${PUBLIC_PHYSICAL_NETWORK}
148 ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS}
149
150 disable_service q-l3
151 PUBLIC_INTERFACE=br100
152 EOF
153
154 if [ -z ${DISABLE_ODL_L3_PLUGIN} ] || [ "${DISABLE_ODL_L3_PLUGIN}" == "no" ]; then
155 if [ "${ODL_ML2_BRANCH}" == "stable/mitaka" ]; then
156 cat >> ${local_conf_file_name} << EOF
157 Q_L3_ENABLED=True
158 ODL_L3=${ODL_L3}
159 [[post-config|\$NEUTRON_CONF]]
160 [DEFAULT]
161 service_plugins = networking_odl.l3.l3_odl.OpenDaylightL3RouterPlugin
162
163 EOF
164 fi #check for ODL_ML2_BRANCH
165 fi #check for DISABLE_ODL_L3_PLUGIN
166
167 fi #ODL_ENABLE_L3_FWD check
168
169 cat >> ${local_conf_file_name} << EOF
170 [[post-config|/etc/neutron/plugins/ml2/ml2_conf.ini]]
171 [agent]
172 minimize_polling=True
173
174 [ml2]
175 # Needed for VLAN provider tests - because our provider networks are always encapsulated in VXLAN (br-phys1)
176 # MTU(1440) + VXLAN(50) + VLAN(4) = 1494 < MTU eth0/br-phys1(1500)
177 physical_network_mtus = ${PUBLIC_PHYSICAL_NETWORK}:1440
178 path_mtu = 1490
179
180 [[post-config|/etc/neutron/dhcp_agent.ini]]
181 [DEFAULT]
182 force_metadata = True
183 enable_isolated_metadata = True
184
185 [[post-config|/etc/nova/nova.conf]]
186 [DEFAULT]
187 force_config_drive = False
188
189 EOF
190
191 echo "local.conf Created...."
192 cat ${local_conf_file_name}
193 }
194
195 function create_compute_node_local_conf {
196 HOSTIP=$1
197 SERVICEHOST=$2
198 MGRIP=$3
199 ODL_OVS_MANAGERS="$4"
200 #Needs to be removed
201 if [ "${ODL_ML2_BRANCH}" != "stable/ocata" ]; then
202    RECLONE=no
203 else
204    RECLONE=yes
205 fi
206 if [ "${OPENSTACK_BRANCH}" == "master" ] || [ "${OPENSTACK_BRANCH}" == "stable/ocata" ]; then # Ocata+
207     # placement is mandatory for nova since Ocata, note that this requires controller to enable placement-api
208     ENABLED_SERVICES="n-cpu,placement-client"
209 else
210     ENABLED_SERVICES="n-cpu"
211 fi
212
213 local_conf_file_name=${WORKSPACE}/local.conf_compute_${HOSTIP}
214 cat > ${local_conf_file_name} << EOF
215 [[local|localrc]]
216 LOGFILE=stack.sh.log
217 LOG_COLOR=False
218 SCREEN_LOGDIR=/opt/stack/data/log
219 RECLONE=${RECLONE}
220
221 NOVA_VNC_ENABLED=True
222 MULTI_HOST=1
223 ENABLED_SERVICES=${ENABLED_SERVICES}
224 HOST_IP=${HOSTIP}
225 SERVICE_HOST=${SERVICEHOST}
226
227 Q_PLUGIN=ml2
228 ENABLE_TENANT_TUNNELS=True
229 Q_ML2_TENANT_NETWORK_TYPE=vxlan
230
231 Q_HOST=\$SERVICE_HOST
232 MYSQL_HOST=\$SERVICE_HOST
233 RABBIT_HOST=\$SERVICE_HOST
234 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
235 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
236 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
237
238 MYSQL_PASSWORD=mysql
239 RABBIT_PASSWORD=rabbit
240 SERVICE_TOKEN=service
241 SERVICE_PASSWORD=admin
242 ADMIN_PASSWORD=admin
243
244 ODL_MODE=compute
245 ODL_PORT_BINDING_CONTROLLER=${ODL_ML2_PORT_BINDING}
246 LIBVIRT_TYPE=qemu
247 ODL_MGR_IP=${MGRIP}
248 EOF
249
250 if [[ "${ENABLE_OS_PLUGINS}" =~ networking-odl ]]; then
251 cat >> ${local_conf_file_name} << EOF
252 enable_plugin networking-odl ${ODL_ML2_DRIVER_REPO} ${ODL_ML2_BRANCH}
253 EOF
254 fi
255
256 echo "ODL_OVS_MANAGERS=${ODL_OVS_MANAGERS}" >> ${local_conf_file_name}
257
258 # if we are using the new netvirt impl, as determined by the feature name
259 # odl-netvirt-openstack (note: old impl is odl-ovsdb-openstack) then we
260 # want PROVIDER_MAPPINGS to be used -- this should be fixed if we want to support
261 # external networks in legacy netvirt
262 if [[ ${CONTROLLERFEATURES} == *"odl-netvirt-openstack"* ]]; then
263   ODL_PROVIDER_MAPPINGS="\${PUBLIC_PHYSICAL_NETWORK}:${PUBLIC_BRIDGE}"
264 else
265   ODL_PROVIDER_MAPPINGS=
266 fi
267
268 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
269 cat >> ${local_conf_file_name} << EOF
270 # Uncomment lines below if odl-compute is to be used for l3 forwarding
271 Q_L3_ENABLED=True
272 ODL_L3=${ODL_L3}
273 PUBLIC_INTERFACE=br100 # FIXME do we use br100 at all?
274 PUBLIC_BRIDGE=${PUBLIC_BRIDGE}
275 PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK}
276 ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS}
277 EOF
278 fi
279 echo "local.conf Created...."
280 cat ${local_conf_file_name}
281 }
282
283 function configure_haproxy_for_neutron_requests () {
284 MGRIP=$1
285 ODL_IPS=(${2//,/ })
286
287 cat > ${WORKSPACE}/install_ha_proxy.sh<< EOF
288 sudo systemctl stop firewalld
289 sudo yum -y install policycoreutils-python haproxy
290 EOF
291
292 cat > ${WORKSPACE}/haproxy.cfg << EOF
293 global
294   daemon
295   group  haproxy
296   log  /dev/log local0
297   maxconn  20480
298   pidfile  /tmp/haproxy.pid
299   user  haproxy
300
301 defaults
302   log  global
303   maxconn  4096
304   mode  tcp
305   retries  3
306   timeout  http-request 10s
307   timeout  queue 1m
308   timeout  connect 10s
309   timeout  client 1m
310   timeout  server 1m
311   timeout  check 10s
312
313 listen opendaylight
314   bind ${MGRIP}:8080
315   balance source
316 EOF
317
318 odlindex=1
319 for odlip in ${ODL_IPS[*]}
320 do
321 cat >> ${WORKSPACE}/haproxy.cfg << EOF
322   server controller-${odlindex} ${odlip}:8080 check fall 5 inter 2000 rise 2
323 EOF
324 odlindex=$((odlindex+1))
325 done
326
327 cat >> ${WORKSPACE}/haproxy.cfg << EOF
328 listen opendaylight_rest
329   bind ${MGRIP}:8181
330   balance source
331 EOF
332
333 odlindex=1
334 for odlip in ${ODL_IPS[*]}
335 do
336 cat >> ${WORKSPACE}/haproxy.cfg << EOF
337   server controller-rest-${odlindex} ${odlip}:8181 check fall 5 inter 2000 rise 2
338 EOF
339 odlindex=$((odlindex+1))
340 done
341
342 echo "Dump haproxy.cfg"
343 cat ${WORKSPACE}/haproxy.cfg
344
345 cat > ${WORKSPACE}/deploy_ha_proxy.sh<< EOF
346 sudo chown haproxy:haproxy /tmp/haproxy.cfg
347 sudo sed -i 's/\\/etc\\/haproxy\\/haproxy.cfg/\\/tmp\\/haproxy.cfg/g' /usr/lib/systemd/system/haproxy.service
348 sudo /usr/sbin/semanage permissive -a haproxy_t
349 sudo systemctl restart haproxy
350 sleep 3
351 sudo netstat -tunpl
352 sudo systemctl status haproxy
353 true
354 EOF
355 scp ${WORKSPACE}/install_ha_proxy.sh ${MGRIP}:/tmp
356 ${SSH} ${MGRIP} "sudo bash /tmp/install_ha_proxy.sh"
357 scp ${WORKSPACE}/haproxy.cfg ${MGRIP}:/tmp
358 scp ${WORKSPACE}/deploy_ha_proxy.sh ${MGRIP}:/tmp
359 ${SSH} ${MGRIP} "sudo bash /tmp/deploy_ha_proxy.sh"
360 }
361
362 function collect_logs_and_exit () {
363 set +e  # We do not want to create red dot just because something went wrong while fetching logs.
364 for i in `seq 1 ${NUM_ODL_SYSTEM}`
365 do
366     CONTROLLERIP=ODL_SYSTEM_${i}_IP
367     echo "killing karaf process..."
368     ${SSH} "${!CONTROLLERIP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
369 done
370
371 cat > extra_debug.sh << EOF
372 echo -e "/usr/sbin/lsmod | /usr/bin/grep openvswitch\n"
373 /usr/sbin/lsmod | /usr/bin/grep openvswitch
374 echo -e "\ngrep ct_ /var/log/openvswitch/ovs-vswitchd.log\n"
375 grep ct_ /var/log/openvswitch/ovs-vswitchd.log
376 EOF
377
378 sleep 5
379 # FIXME: Do not create .tar and gzip before copying.
380 for i in `seq 1 ${NUM_ODL_SYSTEM}`
381 do
382     CONTROLLERIP=ODL_SYSTEM_${i}_IP
383     ${SSH} "${!CONTROLLERIP}"  "cp -r /tmp/${BUNDLEFOLDER}/data/log /tmp/odl_log"
384     ${SSH} "${!CONTROLLERIP}"  "tar -cf /tmp/odl${i}_karaf.log.tar /tmp/odl_log/*"
385     scp "${!CONTROLLERIP}:/tmp/odl${i}_karaf.log.tar" "${WORKSPACE}/odl${i}_karaf.log.tar"
386     tar -xvf ${WORKSPACE}/odl${i}_karaf.log.tar -C . --strip-components 2 --transform s/karaf/odl${i}_karaf/g
387     grep "ROBOT MESSAGE\| ERROR " odl${i}_karaf.log > odl${i}_err.log
388     grep "ROBOT MESSAGE\|Exception" odl${i}_karaf.log > odl${i}_exception.log
389     grep "ROBOT MESSAGE\| ERROR \| WARN \|Exception" odl${i}_karaf.log > odl${i}_err_warn_exception.log
390     rm ${WORKSPACE}/odl${i}_karaf.log.tar
391 done
392
393 # Since this log collection work is happening before the archive build macro which also
394 # creates the ${WORKSPACE}/archives dir, we have to do it here first.  The mkdir in the
395 # archives build step will essentially be a noop.
396 mkdir -p ${WORKSPACE}/archives
397
398 # Control Node
399 for i in `seq 1 ${NUM_OPENSTACK_CONTROL_NODES}`
400 do
401     OS_CTRL_IP=OPENSTACK_CONTROL_NODE_${i}_IP
402     OS_CTRL_FOLDER="control_${i}"
403     mkdir -p ${OS_CTRL_FOLDER}
404     scp ${!OS_CTRL_IP}:/opt/stack/devstack/nohup.out ${OS_CTRL_FOLDER}/stack.log
405     scp ${!OS_CTRL_IP}:/var/log/openvswitch/ovs-vswitchd.log ${OS_CTRL_FOLDER}/ovs-vswitchd.log
406     scp ${!OS_CTRL_IP}:/etc/neutron/neutron.conf ${OS_CTRL_FOLDER}/neutron.conf
407     scp ${!OS_CTRL_IP}:/etc/nova/nova.conf ${OS_CTRL_FOLDER}/nova.conf
408     rsync -avhe ssh ${!OS_CTRL_IP}:/opt/stack/logs/* ${OS_CTRL_FOLDER} # rsync to prevent copying of symbolic links
409     scp extra_debug.sh ${!OS_CTRL_IP}:/tmp
410     ${SSH} ${!OS_CTRL_IP} "bash /tmp/extra_debug.sh > /tmp/extra_debug.log"
411     scp ${!OS_CTRL_IP}:/tmp/extra_debug.log ${OS_CTRL_FOLDER}/extra_debug.log
412     scp ${!OS_CTRL_IP}:/tmp/*.xz ${OS_CTRL_FOLDER}/
413     mv local.conf_control_${!OS_CTRL_IP} ${OS_CTRL_FOLDER}/local.conf
414     mv ${OS_CTRL_FOLDER} ${WORKSPACE}/archives/
415 done
416
417 # Compute Nodes
418 for i in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`
419 do
420     OSIP=OPENSTACK_COMPUTE_NODE_${i}_IP
421     OS_COMPUTE_FOLDER="compute_${i}"
422     mkdir -p ${OS_COMPUTE_FOLDER}
423     scp ${!OSIP}:/opt/stack/devstack/nohup.out ${OS_COMPUTE_FOLDER}/stack.log
424     scp ${!OSIP}:/var/log/openvswitch/ovs-vswitchd.log ${OS_COMPUTE_FOLDER}/ovs-vswitchd.log
425     scp ${!OSIP}:/etc/nova/nova.conf ${OS_COMPUTE_FOLDER}/nova.conf
426     rsync -avhe ssh ${!OSIP}:/opt/stack/logs/* ${OS_COMPUTE_FOLDER} # rsync to prevent copying of symbolic links
427     scp extra_debug.sh ${!OSIP}:/tmp
428     ${SSH} ${!OSIP} "bash /tmp/extra_debug.sh > /tmp/extra_debug.log"
429     scp ${!OSIP}:/tmp/extra_debug.log ${OS_COMPUTE_FOLDER}/extra_debug.log
430     scp ${!OSIP}:/tmp/*.xz ${OS_COMPUTE_FOLDER}/
431     mv local.conf_compute_${!OSIP} ${OS_COMPUTE_FOLDER}/local.conf
432     mv ${OS_COMPUTE_FOLDER} ${WORKSPACE}/archives/
433 done
434
435 ls local.conf* | xargs -I % mv % %.log
436
437 # Tempest
438 DEVSTACK_TEMPEST_DIR="/opt/stack/tempest"
439 if $(ssh ${OPENSTACK_CONTROL_NODE_1_IP} "sudo sh -c '[ -f ${DEVSTACK_TEMPEST_DIR}/.testrepository/0 ]'"); then # if Tempest results exist
440     ssh ${OPENSTACK_CONTROL_NODE_1_IP} "for I in \$(sudo ls ${DEVSTACK_TEMPEST_DIR}/.testrepository/ | grep -E '^[0-9]+$'); do sudo sh -c \"${DEVSTACK_TEMPEST_DIR}/.tox/tempest/bin/subunit-1to2 < ${DEVSTACK_TEMPEST_DIR}/.testrepository/\${I} >> ${DEVSTACK_TEMPEST_DIR}/subunit_log.txt\"; done"
441     ssh ${OPENSTACK_CONTROL_NODE_1_IP} "sudo sh -c '${DEVSTACK_TEMPEST_DIR}/.tox/tempest/bin/python ${DEVSTACK_TEMPEST_DIR}/.tox/tempest/lib/python2.7/site-packages/os_testr/subunit2html.py ${DEVSTACK_TEMPEST_DIR}/subunit_log.txt ${DEVSTACK_TEMPEST_DIR}/tempest_results.html'"
442     TEMPEST_LOGS_DIR=${WORKSPACE}/archives/tempest
443     mkdir -p ${TEMPEST_LOGS_DIR}
444     scp ${OPENSTACK_CONTROL_NODE_1_IP}:${DEVSTACK_TEMPEST_DIR}/tempest_results.html ${TEMPEST_LOGS_DIR}
445     scp ${OPENSTACK_CONTROL_NODE_1_IP}:${DEVSTACK_TEMPEST_DIR}/tempest.log ${TEMPEST_LOGS_DIR}
446     mv ${WORKSPACE}/tempest_output* ${TEMPEST_LOGS_DIR}
447 fi
448 }
449
450 cat > ${WORKSPACE}/disable_firewall.sh << EOF
451 sudo systemctl stop firewalld
452 sudo systemctl stop iptables
453 true
454 EOF
455
456 cat > ${WORKSPACE}/get_devstack.sh << EOF
457 sudo systemctl stop firewalld
458 sudo yum install bridge-utils -y
459 sudo systemctl stop  NetworkManager
460 #Disable NetworkManager and kill dhclient and dnsmasq
461 sudo systemctl stop NetworkManager
462 sudo killall dhclient
463 sudo killall dnsmasq
464 #Workaround for mysql failure
465 echo "127.0.0.1    localhost \${HOSTNAME}" > /tmp/hosts
466 echo "::1   localhost  \${HOSTNAME}" >> /tmp/hosts
467 sudo mv /tmp/hosts /etc/hosts
468 sudo /usr/sbin/brctl addbr br100
469 #sudo ifconfig eth0 mtu 2000
470 sudo mkdir /opt/stack
471 sudo chmod 777 /opt/stack
472 cd /opt/stack
473 git clone https://git.openstack.org/openstack-dev/devstack
474 cd devstack
475 git checkout $OPENSTACK_BRANCH
476 EOF
477
478 [ "$NUM_OPENSTACK_SITES" ] || NUM_OPENSTACK_SITES=1
479 compute_index=1
480 odl_index=1
481 os_node_list=()
482 os_interval=$(( ${NUM_OPENSTACK_SYSTEM} / ${NUM_OPENSTACK_SITES} ))
483 ha_proxy_index=${os_interval}
484
485 cat > "${WORKSPACE}/manual_install_package.sh" << EOF
486 cd /opt/stack
487 git clone "\$1"
488 cd "\$2"
489 git checkout "\$3"
490 sudo python setup.py install
491 EOF
492
493 for i in `seq 1 ${NUM_OPENSTACK_SITES}`
494 do
495     if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
496         echo "Configure HAProxy"
497         ODL_HAPROXYIP_PARAM=OPENSTACK_HAPROXY_${i}_IP
498         ha_proxy_index=$(( $ha_proxy_index + $os_interval ))
499         odl_index=$(((i - 1) * 3 + 1))
500         ODL_IP_PARAM1=ODL_SYSTEM_$((odl_index++))_IP
501         ODL_IP_PARAM2=ODL_SYSTEM_$((odl_index++))_IP
502         ODL_IP_PARAM3=ODL_SYSTEM_$((odl_index++))_IP
503         ODLMGRIP[$i]=${!ODL_HAPROXYIP_PARAM} # ODL Northbound uses HAProxy VIP
504         ODL_OVS_MGRS[$i]="${!ODL_IP_PARAM1},${!ODL_IP_PARAM2},${!ODL_IP_PARAM3}" # OVSDB connects to all ODL IPs
505
506         configure_haproxy_for_neutron_requests ${!ODL_HAPROXYIP_PARAM} "${ODL_OVS_MGRS[$i]}"
507     else
508         ODL_IP_PARAM=ODL_SYSTEM_${i}_IP
509         ODL_OVS_MGRS[$i]="${!ODL_IP_PARAM}" # ODL Northbound uses ODL IP
510         ODLMGRIP[$i]=${!ODL_IP_PARAM} # OVSDB connects to ODL IP
511     fi
512 done
513
514 for i in `seq 1 ${NUM_OPENSTACK_CONTROL_NODES}`
515 do
516     echo "Stack the Control Node"
517     CONTROLIP=OPENSTACK_CONTROL_NODE_${i}_IP
518     scp ${WORKSPACE}/get_devstack.sh ${!CONTROLIP}:/tmp
519     ${SSH} ${!CONTROLIP} "bash /tmp/get_devstack.sh"
520     create_control_node_local_conf ${!CONTROLIP} ${ODLMGRIP[$i]} "${ODL_OVS_MGRS[$i]}"
521     scp ${WORKSPACE}/local.conf_control_${!CONTROLIP} ${!CONTROLIP}:/opt/stack/devstack/local.conf
522     if [ "${ODL_ML2_BRANCH}" == "stable/mitaka" ]; then
523         # Workaround for problems with latest versions/specified versions in requirements of openstack
524         # Openstacksdk,libvirt-python -> the current version does not work with  Mitaka diue to some requirements
525         # conflict and breaks when trying to stack
526         # paramiko -> Problems with tempest tests due to paramiko incompatibility with pycrypto.
527         # the problem has been solved with  version 1.17. If the latest version of paramiko is used, it causes
528         # other timeout problems
529         ssh ${!CONTROLIP} "cd /opt/stack; git clone https://git.openstack.org/openstack/requirements; cd requirements; git checkout stable/mitaka; sed -i /openstacksdk/d upper-constraints.txt; sed -i /libvirt-python/d upper-constraints.txt; sed -i /paramiko/d upper-constraints.txt"
530         scp "${WORKSPACE}/manual_install_package.sh"  "${!CONTROLIP}:/tmp"
531         ssh ${!CONTROLIP} "sudo pip install deprecation"
532         # Fix for recent requirements update  in the  master branch of the sdk.The section must be replaced with a better fix.
533         ssh "${!CONTROLIP}" "sh /tmp/manual_install_package.sh https://github.com/openstack/python-openstacksdk python-openstacksdk 0.9.14"
534         ssh "${!CONTROLIP}" "sh /tmp/manual_install_package.sh https://github.com/paramiko/paramiko paramiko 1.17"
535     fi
536     ssh ${!CONTROLIP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
537     ssh ${!CONTROLIP} "ps -ef | grep stack.sh"
538     ssh ${!CONTROLIP} "ls -lrt /opt/stack/devstack/nohup.out"
539     os_node_list+=(${!CONTROLIP})
540
541     #Workaround for stable/newton jobs
542     if [ "${ODL_ML2_BRANCH}" == "stable/newton" ]; then
543         ssh ${!CONTROLIP} "cd /opt/stack; git clone https://git.openstack.org/openstack/requirements; cd requirements; git checkout stable/newton; sed -i /appdirs/d upper-constraints.txt"
544     fi
545 done
546
547 for i in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`
548 do
549     echo "Stack the Compute Node"
550     NUM_COMPUTES_PER_SITE=$((NUM_OPENSTACK_COMPUTE_NODES / NUM_OPENSTACK_SITES))
551     SITE_INDEX=$((((i - 1) / NUM_COMPUTES_PER_SITE) + 1)) # We need the site index to infer the control node IP for this compute
552     COMPUTEIP=OPENSTACK_COMPUTE_NODE_${i}_IP
553     CONTROLIP=OPENSTACK_CONTROL_NODE_${SITE_INDEX}_IP
554     scp ${WORKSPACE}/get_devstack.sh  ${!COMPUTEIP}:/tmp
555     ${SSH} ${!COMPUTEIP} "bash /tmp/get_devstack.sh"
556     create_compute_node_local_conf ${!COMPUTEIP} ${!CONTROLIP} ${ODLMGRIP[$SITE_INDEX]} "${ODL_OVS_MGRS[$SITE_INDEX]}"
557     scp ${WORKSPACE}/local.conf_compute_${!COMPUTEIP} ${!COMPUTEIP}:/opt/stack/devstack/local.conf
558     if [ "${ODL_ML2_BRANCH}" == "stable/mitaka" ]; then
559         ssh ${!COMPUTEIP} "cd /opt/stack; git clone https://git.openstack.org/openstack/requirements; cd requirements; git checkout stable/mitaka; sed -i /libvirt-python/d upper-constraints.txt"
560     fi
561     ssh ${!COMPUTEIP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
562     ssh ${!COMPUTEIP} "ps -ef | grep stack.sh"
563     os_node_list+=(${!COMPUTEIP})
564 done
565
566 echo ${os_node_list[*]}
567
568 cat > ${WORKSPACE}/check_stacking.sh << EOF
569 > /tmp/stack_progress
570 ps -ef | grep "stack.sh" | grep -v grep
571 ret=\$?
572 if [ \${ret} -eq 1 ]; then
573   grep "This is your host IP address:" /opt/stack/devstack/nohup.out
574   if [ \$? -eq 0 ]; then
575      echo "Stacking Complete" > /tmp/stack_progress
576   else
577      echo "Stacking Failed" > /tmp/stack_progress
578   fi
579 elif [ \${ret} -eq 0 ]; then
580   echo "Still Stacking" > /tmp/stack_progress
581 fi
582 EOF
583
584 #the checking is repeated for an hour
585 iteration=0
586 in_progress=1
587 while [ ${in_progress} -eq 1 ]; do
588 iteration=$(($iteration + 1))
589 for index in ${!os_node_list[@]}
590 do
591 echo "Check the status of stacking in ${os_node_list[index]}"
592 scp ${WORKSPACE}/check_stacking.sh  ${os_node_list[index]}:/tmp
593 ${SSH} ${os_node_list[index]} "bash /tmp/check_stacking.sh"
594 scp ${os_node_list[index]}:/tmp/stack_progress .
595 #debug
596 cat stack_progress
597 stacking_status=`cat stack_progress`
598 if [ "$stacking_status" == "Still Stacking" ]; then
599   continue
600 elif [ "$stacking_status" == "Stacking Failed" ]; then
601   collect_logs_and_exit
602   exit 1
603 elif [ "$stacking_status" == "Stacking Complete" ]; then
604   unset os_node_list[index]
605   if  [ ${#os_node_list[@]} -eq 0 ]; then
606      in_progress=0
607   fi
608 fi
609 done
610  echo "sleep for a minute before the next check"
611  sleep 60
612  if [ ${iteration} -eq 60 ]; then
613   collect_logs_and_exit
614   exit 1
615  fi
616 done
617
618 NUM_COMPUTES_PER_SITE=$((NUM_OPENSTACK_COMPUTE_NODES / NUM_OPENSTACK_SITES))
619 for i in `seq 1 ${NUM_OPENSTACK_SITES}`
620 do
621     echo "Configure the Control Node"
622     CONTROLIP=OPENSTACK_CONTROL_NODE_${i}_IP
623
624     #Need to disable firewalld and iptables in control node
625     echo "Stop Firewall in Control Node for compute nodes to be able to reach the ports and add to hypervisor-list"
626     scp ${WORKSPACE}/disable_firewall.sh ${!CONTROLIP}:/tmp
627     ${SSH} ${!CONTROLIP} "sudo bash /tmp/disable_firewall.sh"
628
629     echo "sleep for 60s and print hypervisor-list"
630     sleep 60
631     ${SSH} ${!CONTROLIP} "cd /opt/stack/devstack; source openrc admin admin; nova hypervisor-list"
632     # in the case that we are doing openstack (control + compute) all in one node, then the number of hypervisors
633     # will be the same as the number of openstack systems. However, if we are doing multinode openstack then the
634     # assumption is we have a single control node and the rest are compute nodes, so the number of expected hypervisors
635     # is one less than the total number of openstack systems
636     if [ $((NUM_OPENSTACK_SYSTEM / NUM_OPENSTACK_SITES - 1)) -eq 1 ]; then
637         expected_num_hypervisors=1
638     else
639         expected_num_hypervisors=${NUM_COMPUTES_PER_SITE}
640     fi
641     num_hypervisors=$(${SSH} ${!CONTROLIP} "cd /opt/stack/devstack; source openrc admin admin; openstack hypervisor list -f value | wc -l" | tail -1 | tr -d "\r")
642     if ! [ "${num_hypervisors}" ] || ! [ ${num_hypervisors} -eq ${expected_num_hypervisors} ]; then
643         echo "Error: Only $num_hypervisors hypervisors detected, expected $expected_num_hypervisors"
644         collect_logs_and_exit
645         exit 1
646     fi
647
648     # upgrading pip, urllib3 and httplib2 so that tempest tests can be run on openstack control node
649     # this needs to happen after devstack runs because it seems devstack is pulling in specific versions
650     # of these libs that are not working for tempest.
651     ${SSH} ${!CONTROLIP} "sudo pip install --upgrade pip"
652     ${SSH} ${!CONTROLIP} "sudo pip install urllib3 --upgrade"
653     ${SSH} ${!CONTROLIP} "sudo pip install httplib2 --upgrade"
654
655     # Gather Compute IPs for the site
656     for j in `seq 1 ${NUM_COMPUTES_PER_SITE}`
657     do
658         COMPUTE_INDEX=$(((i-1) * NUM_COMPUTES_PER_SITE + j))
659         IP_VAR=OPENSTACK_COMPUTE_NODE_${COMPUTE_INDEX}_IP
660         COMPUTE_IPS[$((j-1))]=${!IP_VAR}
661     done
662
663     # Need to disable firewalld and iptables in compute nodes as well
664     for ip in ${COMPUTE_IPS[*]}
665     do
666         scp ${WORKSPACE}/disable_firewall.sh "${ip}:/tmp"
667         ${SSH} "${ip}" "sudo bash /tmp/disable_firewall.sh"
668     done
669
670     # External Network
671     echo "prepare external networks by adding vxlan tunnels between all nodes on a separate bridge..."
672     # FIXME Should there be a unique gateway IP and devstack index for each site?
673     devstack_index=1
674     for ip in ${!CONTROLIP} ${COMPUTE_IPS[*]}
675     do
676         # FIXME - Workaround, ODL (new netvirt) currently adds PUBLIC_BRIDGE as a port in br-int since it doesn't see such a bridge existing when we stack
677         ${SSH} $ip "sudo ovs-vsctl --if-exists del-port br-int $PUBLIC_BRIDGE"
678         ${SSH} $ip "sudo ovs-vsctl --may-exist add-br $PUBLIC_BRIDGE -- set bridge $PUBLIC_BRIDGE other-config:disable-in-band=true other_config:hwaddr=f6:00:00:ff:01:0$((devstack_index++))"
679     done
680
681     # ipsec support
682     if [ "${IPSEC_VXLAN_TUNNELS_ENABLED}" == "yes" ]; then
683         ALL_NODES=(${!CONTROLIP} ${COMPUTE_IPS[*]})
684         for ((inx_ip1=0; inx_ip1<$((${#ALL_NODES[@]} - 1)); inx_ip1++))
685         do
686             for ((inx_ip2=$((inx_ip1 + 1)); inx_ip2<${#ALL_NODES[@]}; inx_ip2++))
687             do
688                 KEY1=0x$(dd if=/dev/urandom count=32 bs=1 2> /dev/null| xxd -p -c 64)
689                 KEY2=0x$(dd if=/dev/urandom count=32 bs=1 2> /dev/null| xxd -p -c 64)
690                 ID=0x$(dd if=/dev/urandom count=4 bs=1 2> /dev/null| xxd -p -c 8)
691                 ip1=${ALL_NODES[$inx_ip1]}
692                 ip2=${ALL_NODES[$inx_ip2]}
693                 ${SSH} $ip1 "sudo ip xfrm state add src $ip1 dst $ip2 proto esp spi $ID reqid $ID mode transport auth sha256 $KEY1 enc aes $KEY2"
694                 ${SSH} $ip1 "sudo ip xfrm state add src $ip2 dst $ip1 proto esp spi $ID reqid $ID mode transport auth sha256 $KEY1 enc aes $KEY2"
695                 ${SSH} $ip1 "sudo ip xfrm policy add src $ip1 dst $ip2 proto udp dir out tmpl src $ip1 dst $ip2 proto esp reqid $ID mode transport"
696                 ${SSH} $ip1 "sudo ip xfrm policy add src $ip2 dst $ip1 proto udp dir in tmpl src $ip2 dst $ip1 proto esp reqid $ID mode transport"
697
698                 ${SSH} $ip2 "sudo ip xfrm state add src $ip2 dst $ip1 proto esp spi $ID reqid $ID mode transport auth sha256 $KEY1 enc aes $KEY2"
699                 ${SSH} $ip2 "sudo ip xfrm state add src $ip1 dst $ip2 proto esp spi $ID reqid $ID mode transport auth sha256 $KEY1 enc aes $KEY2"
700                 ${SSH} $ip2 "sudo ip xfrm policy add src $ip2 dst $ip1 proto udp dir out tmpl src $ip2 dst $ip1 proto esp reqid $ID mode transport"
701                 ${SSH} $ip2 "sudo ip xfrm policy add src $ip1 dst $ip2 proto udp dir in tmpl src $ip1 dst $ip2 proto esp reqid $ID mode transport"
702             done
703         done
704
705         for ip in ${!CONTROLIP} ${COMPUTE_IPS[*]}
706         do
707             echo "ip xfrm configuration for node $ip:"
708             ${SSH} $ip "sudo ip xfrm policy list"
709             ${SSH} $ip "sudo ip xfrm state list"
710         done
711     fi
712
713     # Control Node - PUBLIC_BRIDGE will act as the external router
714     GATEWAY_IP="10.10.10.250" # FIXME this should be a parameter, also shared with integration-test
715     GATEWAY_VLAN_ID=167
716     if [[ ${CONTROLLERFEATURES} == *"odl-ovsdb-openstack"* ]]; then
717         ${SSH} ${!CONTROLIP} "sudo ifconfig ${PUBLIC_BRIDGE} up ${GATEWAY_IP}/24"
718     else
719         ${SSH} ${!CONTROLIP} "sudo ip link add link ${PUBLIC_BRIDGE} name ${PUBLIC_BRIDGE}.${GATEWAY_VLAN_ID} type vlan id ${GATEWAY_VLAN_ID}"
720         ${SSH} ${!CONTROLIP} "sudo ifconfig ${PUBLIC_BRIDGE} up"
721         ${SSH} ${!CONTROLIP} "sudo ifconfig ${PUBLIC_BRIDGE}.${GATEWAY_VLAN_ID} up ${GATEWAY_IP}/24"
722     fi
723
724     # Computes
725     compute_index=1
726     for compute_ip in ${COMPUTE_IPS[*]}
727     do
728         # Tunnel from controller to compute
729         COMPUTEPORT=compute$(( compute_index++ ))_vxlan
730         ${SSH} ${!CONTROLIP} "sudo ovs-vsctl add-port $PUBLIC_BRIDGE $COMPUTEPORT -- set interface $COMPUTEPORT type=vxlan options:local_ip="${!CONTROLIP}" options:remote_ip="$compute_ip" options:dst_port=9876 options:key=flow"
731         # Tunnel from compute to controller
732         CONTROLPORT="control_vxlan"
733         ${SSH} $compute_ip "sudo ovs-vsctl add-port $PUBLIC_BRIDGE $CONTROLPORT -- set interface $CONTROLPORT type=vxlan options:local_ip="$compute_ip" options:remote_ip="${!CONTROLIP}" options:dst_port=9876 options:key=flow"
734     done
735 done
736
737 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
738     odlmgrip=OPENSTACK_HAPROXY_1_IP
739     HA_PROXY_IP=${!odlmgrip}
740     HA_PROXY_1_IP=${!odlmgrip}
741     odlmgrip2=OPENSTACK_HAPROXY_2_IP
742     HA_PROXY_2_IP=${!odlmgrip2}
743     odlmgrip3=OPENSTACK_HAPROXY_1_IP
744     HA_PROXY_3_IP=${!odlmgrip3}
745 else
746     HA_PROXY_IP=${ODL_SYSTEM_IP}
747     HA_PROXY_1_IP=${ODL_SYSTEM_1_IP}
748     HA_PROXY_2_IP=${ODL_SYSTEM_2_IP}
749     HA_PROXY_3_IP=${ODL_SYSTEM_3_IP}
750 fi
751
752 echo "Locating test plan to use..."
753 testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
754 if [ ! -f "${testplan_filepath}" ]; then
755     testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
756 fi
757
758 echo "Changing the testplan path..."
759 cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
760 cat testplan.txt
761
762 SUITES=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
763
764 #FIXME currently support only 1 site
765 echo "Starting Robot test suites ${SUITES} ..."
766 # please add pybot -v arguments on a single line and alphabetized
767 pybot -N ${TESTPLAN} --removekeywords wuks -c critical -e exclude \
768     -v BUNDLEFOLDER:${BUNDLEFOLDER} \
769     -v BUNDLE_URL:${ACTUALBUNDLEURL} \
770     -v CONTROLLER_USER:${USER} \
771     -v DEVSTACK_DEPLOY_PATH:/opt/stack/devstack \
772     -v HA_PROXY_IP:${HA_PROXY_IP} \
773     -v HA_PROXY_1_IP:${HA_PROXY_1_IP} \
774     -v HA_PROXY_2_IP:${HA_PROXY_2_IP} \
775     -v HA_PROXY_3_IP:${HA_PROXY_3_IP} \
776     -v JDKVERSION:${JDKVERSION} \
777     -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
778     -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} \
779     -v NUM_OPENSTACK_SITES:${NUM_OPENSTACK_SITES} \
780     -v NUM_OS_SYSTEM:${NUM_OPENSTACK_SYSTEM} \
781     -v NUM_TOOLS_SYSTEM:${NUM_TOOLS_SYSTEM} \
782     -v ODL_STREAM:${DISTROSTREAM} \
783     -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} \
784     -v ODL_SYSTEM_1_IP:${ODL_SYSTEM_1_IP} \
785     -v ODL_SYSTEM_2_IP:${ODL_SYSTEM_2_IP} \
786     -v ODL_SYSTEM_3_IP:${ODL_SYSTEM_3_IP} \
787     -v ODL_SYSTEM_4_IP:${ODL_SYSTEM_4_IP} \
788     -v ODL_SYSTEM_5_IP:${ODL_SYSTEM_5_IP} \
789     -v ODL_SYSTEM_6_IP:${ODL_SYSTEM_6_IP} \
790     -v ODL_SYSTEM_7_IP:${ODL_SYSTEM_7_IP} \
791     -v ODL_SYSTEM_8_IP:${ODL_SYSTEM_8_IP} \
792     -v ODL_SYSTEM_9_IP:${ODL_SYSTEM_9_IP} \
793     -v OS_CONTROL_NODE_IP:${OPENSTACK_CONTROL_NODE_1_IP} \
794     -v OS_CONTROL_NODE_1_IP:${OPENSTACK_CONTROL_NODE_1_IP} \
795     -v OS_CONTROL_NODE_2_IP:${OPENSTACK_CONTROL_NODE_2_IP} \
796     -v OS_CONTROL_NODE_3_IP:${OPENSTACK_CONTROL_NODE_3_IP} \
797     -v OPENSTACK_BRANCH:${OPENSTACK_BRANCH} \
798     -v OS_COMPUTE_1_IP:${OPENSTACK_COMPUTE_NODE_1_IP} \
799     -v OS_COMPUTE_2_IP:${OPENSTACK_COMPUTE_NODE_2_IP} \
800     -v OS_COMPUTE_3_IP:${OPENSTACK_COMPUTE_NODE_3_IP} \
801     -v OS_COMPUTE_4_IP:${OPENSTACK_COMPUTE_NODE_4_IP} \
802     -v OS_COMPUTE_5_IP:${OPENSTACK_COMPUTE_NODE_5_IP} \
803     -v OS_COMPUTE_6_IP:${OPENSTACK_COMPUTE_NODE_6_IP} \
804     -v OS_USER:${USER} \
805     -v PUBLIC_PHYSICAL_NETWORK:${PUBLIC_PHYSICAL_NETWORK} \
806     -v SECURITY_GROUP_MODE:${SECURITY_GROUP_MODE} \
807     -v TOOLS_SYSTEM_IP:${TOOLS_SYSTEM_1_IP} \
808     -v TOOLS_SYSTEM_1_IP:${TOOLS_SYSTEM_1_IP} \
809     -v TOOLS_SYSTEM_2_IP:${TOOLS_SYSTEM_2_IP} \
810     -v USER_HOME:${HOME} \
811     -v WORKSPACE:/tmp \
812     ${TESTOPTIONS} ${SUITES} || true
813
814 echo "Examining the files in data/log and checking filesize"
815 ssh ${ODL_SYSTEM_IP} "ls -altr /tmp/${BUNDLEFOLDER}/data/log/"
816 ssh ${ODL_SYSTEM_IP} "du -hs /tmp/${BUNDLEFOLDER}/data/log/*"
817
818 echo "Tests Executed"
819 collect_logs_and_exit
820
821 true  # perhaps Jenkins is testing last exit code
822 # vim: ts=4 sw=4 sts=4 et ft=sh :