Merge "Revert "Install odl-mdsal-trace in netvirt oxygen csit""
[releng/builder.git] / jjb / integration / integration-deploy-openstack-run-test.sh
1 #!/bin/bash
2 # Activate robotframework virtualenv
3 # ${ROBOT_VENV} comes from the integration-install-robotframework.sh
4 # script.
5 # shellcheck source=${ROBOT_VENV}/bin/activate disable=SC1091
6 source ${ROBOT_VENV}/bin/activate
7 PYTHON="${ROBOT_VENV}/bin/python"
8 SSH="ssh -t -t"
9 ADMIN_PASSWORD="admin"
10 OPENSTACK_MASTER_CLIENTS_VERSION="pike"
11
12 # TODO: remove this work to run changes.py if/when it's moved higher up to be visible at the Robot level
13 echo "showing recent changes that made it in to the distribution used by this job"
14 $PYTHON -m pip install --upgrade urllib3
15 python ${WORKSPACE}/test/tools/distchanges/changes.py -d /tmp/distribution_folder \
16                   -u ${ACTUAL_BUNDLE_URL} -b ${DISTROBRANCH} \
17                   -r ssh://jenkins-${SILO}@git.opendaylight.org:29418 || true
18 cat << EOF
19 #################################################
20 ##         Deploy Openstack 3-node             ##
21 #################################################
22 EOF
23
24 # Catch command errors and collect logs.
25 # This ensures logs are collected when script commands fail rather than simply exiting.
26 function trap_handler() {
27     local prog="$0"
28     local lastline="$1"
29     local lasterr="$2"
30     echo "trap_hanlder: ${prog}: line ${lastline}: exit status of last command: ${lasterr}"
31     echo "trap_handler: command: ${BASH_COMMAND}"
32     collect_logs
33     exit 1
34 } # trap_handler()
35
36 trap 'trap_handler ${LINENO} ${$?}' ERR
37
38 function print_job_parameters() {
39     cat << EOF
40
41 Job parameters:
42 DISTROBRANCH: ${DISTROBRANCH}
43 DISTROSTREAM: ${DISTROSTREAM}
44 BUNDLE_URL: ${BUNDLE_URL}
45 CONTROLLERFEATURES: ${CONTROLLERFEATURES}
46 CONTROLLERDEBUGMAP: ${CONTROLLERDEBUGMAP}
47 TESTPLAN: ${TESTPLAN}
48 SUITES: ${SUITES}
49 PATCHREFSPEC: ${PATCHREFSPEC}
50 OPENSTACK_BRANCH: ${OPENSTACK_BRANCH}
51 DEVSTACK_HASH: ${DEVSTACK_HASH}
52 ODL_ML2_DRIVER_REPO: ${ODL_ML2_DRIVER_REPO}
53 ODL_ML2_BRANCH: ${ODL_ML2_BRANCH}
54 ODL_ML2_DRIVER_VERSION: ${ODL_ML2_DRIVER_VERSION}
55 ODL_ML2_PORT_BINDING: ${ODL_ML2_PORT_BINDING}
56 DEVSTACK_KUBERNETES_PLUGIN_REPO: ${DEVSTACK_KUBERNETES_PLUGIN_REPO}
57 DEVSTACK_LBAAS_PLUGIN_REPO: ${DEVSTACK_LBAAS_PLUGIN_REPO}
58 DEVSTACK_NETWORKING_SFC_PLUGIN_REPO: ${DEVSTACK_NETWORKING_SFC_PLUGIN_REPO}
59 ODL_ENABLE_L3_FWD: ${ODL_ENABLE_L3_FWD}
60 IPSEC_VXLAN_TUNNELS_ENABLED: ${IPSEC_VXLAN_TUNNELS_ENABLED}
61 PUBLIC_BRIDGE: ${PUBLIC_BRIDGE}
62 ENABLE_HAPROXY_FOR_NEUTRON: ${ENABLE_HAPROXY_FOR_NEUTRON}
63 ENABLE_OS_SERVICES: ${ENABLE_OS_SERVICES}
64 ENABLE_OS_COMPUTE_SERVICES: ${ENABLE_OS_COMPUTE_SERVICES}
65 ENABLE_OS_NETWORK_SERVICES: ${ENABLE_OS_NETWORK_SERVICES}
66 ENABLE_OS_PLUGINS: ${ENABLE_OS_PLUGINS}
67 DISABLE_OS_SERVICES: ${DISABLE_OS_SERVICES}
68 TENANT_NETWORK_TYPE: ${TENANT_NETWORK_TYPE}
69 SECURITY_GROUP_MODE: ${SECURITY_GROUP_MODE}
70 PUBLIC_PHYSICAL_NETWORK: ${PUBLIC_PHYSICAL_NETWORK}
71 ENABLE_NETWORKING_L2GW: ${ENABLE_NETWORKING_L2GW}
72 CREATE_INITIAL_NETWORKS: ${CREATE_INITIAL_NETWORKS}
73 LBAAS_SERVICE_PROVIDER: ${LBAAS_SERVICE_PROVIDER}
74 NUM_OPENSTACK_SITES: ${NUM_OPENSTACK_SITES}
75 ODL_SFC_DRIVER: ${ODL_SFC_DRIVER}
76 ODL_SNAT_MODE: ${ODL_SNAT_MODE}
77
78 EOF
79 }
80
81 print_job_parameters
82
83 function create_etc_hosts() {
84     NODE_IP=$1
85     CTRL_IP=$2
86     : > ${WORKSPACE}/hosts_file
87     for iter in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`
88     do
89         COMPUTE_IP=OPENSTACK_COMPUTE_NODE_${iter}_IP
90         if [ "${!COMPUTE_IP}" == "${NODE_IP}" ]; then
91            CONTROL_HNAME=$(${SSH}  ${CTRL_IP}  "hostname")
92            echo "${CTRL_IP}   ${CONTROL_HNAME}" >> ${WORKSPACE}/hosts_file
93         else
94            COMPUTE_HNAME=$(${SSH}  ${!COMPUTE_IP}  "hostname")
95            echo "${!COMPUTE_IP}   ${COMPUTE_HNAME}" >> ${WORKSPACE}/hosts_file
96         fi
97     done
98
99     echo "Created the hosts file for ${NODE_IP}:"
100     cat ${WORKSPACE}/hosts_file
101 } # create_etc_hosts()
102
103 #function to install Openstack Clients for Testing
104 #This will pull the latest versions compatiable with the
105 # openstack release
106 function install_openstack_clients_in_robot_vm() {
107     packages=("python-novaclient" "python-neutronclient" "python-openstackclient")
108     for plugin_name in ${ENABLE_OS_PLUGINS}; do
109         if [ "$plugin_name" == "networking-sfc" ]; then
110             packages+=("networking-sfc")
111         fi
112     done
113     openstack_version=$(echo ${OPENSTACK_BRANCH} | cut -d/ -f2)
114     #If the job tests "master", we will use the clients from previous released stable version to avoid failures
115     if [ "${openstack_version}" == "master" ]; then
116        openstack_version=${OPENSTACK_MASTER_CLIENTS_VERSION}
117     fi
118     for package in ${packages[*]}; do
119        echo "Get the current support version of the package ${package}"
120        wget https://raw.githubusercontent.com/openstack/requirements/stable/${openstack_version}/upper-constraints.txt -O /tmp/constraints.txt 2>/dev/null
121        echo "$PYTHON -m pip install --upgrade --no-deps ${package} --no-cache-dir -c /tmp/constraints.txt"
122        $PYTHON -m pip install --upgrade --no-deps ${package} --no-cache-dir -c /tmp/constraints.txt
123        echo "$PYTHON -m pip install ${package} --no-cache-dir -c /tmp/constraints.txt"
124        $PYTHON -m pip install ${package} --no-cache-dir -c /tmp/constraints.txt
125     done
126
127     if [ "${ENABLE_NETWORKING_L2GW}" == "yes" ]; then
128         #networking-l2gw is not officially available in any release yet. Gettting the latest stable version.
129         $PYTHON -m pip install networking-l2gw==11.0.0
130     fi
131 }
132
133
134
135 # convert commas in csv strings to spaces (ssv)
136 function csv2ssv() {
137     local csv=$1
138     if [ -n "${csv}" ]; then
139         ssv=$(echo ${csv} | sed 's/,/ /g' | sed 's/\ \ */\ /g')
140     fi
141
142     echo "${ssv}"
143 } # csv2ssv
144
145 function is_openstack_feature_enabled() {
146     local feature=$1
147     for enabled_feature in $(csv2ssv ${ENABLE_OS_SERVICES})
148     do
149         if [ "${enabled_feature}" == "${feature}" ]; then
150            echo 1
151            return
152         fi
153     done
154     echo 0
155 }
156
157 function fix_libvirt_version_n_cpu_ocata() {
158     local ip=$1
159     ${SSH} ${ip} "
160         cd /opt/stack;
161         git clone https://git.openstack.org/openstack/requirements;
162         cd requirements;
163         git checkout stable/ocata;
164         sed -i s/libvirt-python===2.5.0/libvirt-python===3.2.0/ upper-constraints.txt
165    "
166 }
167
168 # Add enable_services and disable_services to the local.conf
169 function add_os_services() {
170     local core_services=$1
171     local enable_services=$2
172     local disable_services=$3
173     local local_conf_file_name=$4
174     local enable_network_services=$5
175
176     cat >> ${local_conf_file_name} << EOF
177 enable_service $(csv2ssv "${core_services}")
178 EOF
179     if [ -n "${enable_services}" ]; then
180         cat >> ${local_conf_file_name} << EOF
181 enable_service $(csv2ssv "${enable_services}")
182 EOF
183     fi
184     if [ -n "${disable_services}" ]; then
185         cat >> ${local_conf_file_name} << EOF
186 disable_service $(csv2ssv "${disable_services}")
187 EOF
188     fi
189     if [ -n "${enable_network_services}" ]; then
190         cat >> ${local_conf_file_name} << EOF
191 enable_service $(csv2ssv "${enable_network_services}")
192 EOF
193     fi
194 }
195
196 function create_control_node_local_conf() {
197     HOSTIP=$1
198     MGRIP=$2
199     ODL_OVS_MANAGERS="$3"
200
201     local_conf_file_name=${WORKSPACE}/local.conf_control_${HOSTIP}
202     cat > ${local_conf_file_name} << EOF
203 [[local|localrc]]
204 LOGFILE=stack.sh.log
205 USE_SCREEN=True
206 SCREEN_LOGDIR=/opt/stack/data/log
207 LOG_COLOR=False
208 RECLONE=${RECLONE}
209
210 disable_all_services
211 EOF
212
213     add_os_services "${CORE_OS_CONTROL_SERVICES}" "${ENABLE_OS_SERVICES}" "${DISABLE_OS_SERVICES}" "${local_conf_file_name}" "${ENABLE_OS_NETWORK_SERVICES}"
214
215     cat >> ${local_conf_file_name} << EOF
216
217 HOST_IP=${HOSTIP}
218 SERVICE_HOST=\$HOST_IP
219 Q_ML2_TENANT_NETWORK_TYPE=${TENANT_NETWORK_TYPE}
220 NEUTRON_CREATE_INITIAL_NETWORKS=${CREATE_INITIAL_NETWORKS}
221
222 ODL_MODE=manual
223 ODL_MGR_IP=${MGRIP}
224 ODL_PORT=${ODL_PORT}
225 ODL_PORT_BINDING_CONTROLLER=${ODL_ML2_PORT_BINDING}
226 ODL_OVS_MANAGERS=${ODL_OVS_MANAGERS}
227
228 MYSQL_HOST=\$SERVICE_HOST
229 RABBIT_HOST=\$SERVICE_HOST
230 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
231 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
232 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
233
234 ADMIN_PASSWORD=${ADMIN_PASSWORD}
235 DATABASE_PASSWORD=${ADMIN_PASSWORD}
236 RABBIT_PASSWORD=${ADMIN_PASSWORD}
237 SERVICE_TOKEN=${ADMIN_PASSWORD}
238 SERVICE_PASSWORD=${ADMIN_PASSWORD}
239
240 NEUTRON_LBAAS_SERVICE_PROVIDERV2=${LBAAS_SERVICE_PROVIDER} # Only relevant if neutron-lbaas plugin is enabled
241 NEUTRON_SFC_DRIVERS=${ODL_SFC_DRIVER} # Only relevant if networking-sfc plugin is enabled
242 NEUTRON_FLOWCLASSIFIER_DRIVERS=${ODL_SFC_DRIVER} # Only relevant if networking-sfc plugin is enabled
243 ETCD_PORT=2379
244 EOF
245     if [ "${TENANT_NETWORK_TYPE}" == "local" ]; then
246         cat >> ${local_conf_file_name} << EOF
247 ENABLE_TENANT_TUNNELS=false
248 EOF
249     fi
250
251     if [ "${ODL_ML2_DRIVER_VERSION}" == "v2" ]; then
252         echo "ODL_V2DRIVER=True" >> ${local_conf_file_name}
253     fi
254
255     IFS=,
256     for plugin_name in ${ENABLE_OS_PLUGINS}; do
257         if [ "$plugin_name" == "networking-odl" ]; then
258             ENABLE_PLUGIN_ARGS="${ODL_ML2_DRIVER_REPO} ${ODL_ML2_BRANCH}"
259         elif [ "$plugin_name" == "kuryr-kubernetes" ]; then
260             ENABLE_PLUGIN_ARGS="${DEVSTACK_KUBERNETES_PLUGIN_REPO} master" # note: kuryr-kubernetes only exists in master at the moment
261         elif [ "$plugin_name" == "neutron-lbaas" ]; then
262             ENABLE_PLUGIN_ARGS="${DEVSTACK_LBAAS_PLUGIN_REPO} ${OPENSTACK_BRANCH}"
263             IS_LBAAS_PLUGIN_ENABLED="yes"
264         elif [ "$plugin_name" == "networking-sfc" ]; then
265             ENABLE_PLUGIN_ARGS="${DEVSTACK_NETWORKING_SFC_PLUGIN_REPO} ${OPENSTACK_BRANCH}"
266         else
267             echo "Error: Invalid plugin $plugin_name, unsupported"
268             continue
269         fi
270         cat >> ${local_conf_file_name} << EOF
271
272 enable_plugin ${plugin_name} ${ENABLE_PLUGIN_ARGS}
273 EOF
274     done
275     unset IFS
276
277     if [ "${ENABLE_NETWORKING_L2GW}" == "yes" ]; then
278         cat >> ${local_conf_file_name} << EOF
279
280 #enable_plugin networking-l2gw ${NETWORKING_L2GW_DRIVER} ${ODL_ML2_BRANCH}
281 # Need this until patch https://review.openstack.org/#/c/546994/2 is merged
282 enable_plugin networking-l2gw https://github.com/vpickard/networking-l2gw queens-pluginFix
283 NETWORKING_L2GW_SERVICE_DRIVER=L2GW:OpenDaylight:networking_odl.l2gateway.driver_v2.OpenDaylightL2gwDriver:default
284 EOF
285     fi
286
287     if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
288         cat >> ${local_conf_file_name} << EOF
289
290 PUBLIC_BRIDGE=${PUBLIC_BRIDGE}
291 PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK}
292 ML2_VLAN_RANGES=${PUBLIC_PHYSICAL_NETWORK}
293 ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS}
294 EOF
295
296         if [ "${ODL_ML2_DRIVER_VERSION}" == "v2" ]; then
297            SERVICE_PLUGINS="odl-router_v2"
298         else
299            SERVICE_PLUGINS="odl-router"
300         fi
301         if [ "${ENABLE_NETWORKING_L2GW}" == "yes" ]; then
302             SERVICE_PLUGINS+=", networking_l2gw.services.l2gateway.plugin.L2GatewayPlugin"
303         fi
304         if [ "${IS_LBAAS_PLUGIN_ENABLED}" == "yes" ]; then
305             SERVICE_PLUGINS+=", lbaasv2"
306         fi
307     fi #check for ODL_ENABLE_L3_FWD
308
309     cat >> ${local_conf_file_name} << EOF
310
311 [[post-config|\$NEUTRON_CONF]]
312 [DEFAULT]
313 service_plugins = ${SERVICE_PLUGINS}
314
315 [[post-config|/etc/neutron/plugins/ml2/ml2_conf.ini]]
316 [agent]
317 minimize_polling=True
318
319 [ml2]
320 # Needed for VLAN provider tests - because our provider networks are always encapsulated in VXLAN (br-physnet1)
321 # MTU(1400) + VXLAN(50) + VLAN(4) = 1454 < MTU eth0/br-physnet1(1458)
322 physical_network_mtus = ${PUBLIC_PHYSICAL_NETWORK}:1400
323 path_mtu = 1458
324
325 [[post-config|/etc/neutron/dhcp_agent.ini]]
326 [DEFAULT]
327 force_metadata = True
328 enable_isolated_metadata = True
329
330 [[post-config|/etc/nova/nova.conf]]
331 [DEFAULT]
332 force_config_drive = False
333 force_raw_images = False
334
335 [scheduler]
336 discover_hosts_in_cells_interval = 30
337 EOF
338
339     echo "Control local.conf created:"
340     cat ${local_conf_file_name}
341 } # create_control_node_local_conf()
342
343 function create_compute_node_local_conf() {
344     HOSTIP=$1
345     SERVICEHOST=$2
346     MGRIP=$3
347     ODL_OVS_MANAGERS="$4"
348
349     local_conf_file_name=${WORKSPACE}/local.conf_compute_${HOSTIP}
350     cat > ${local_conf_file_name} << EOF
351 [[local|localrc]]
352 LOGFILE=stack.sh.log
353 LOG_COLOR=False
354 USE_SCREEN=True
355 SCREEN_LOGDIR=/opt/stack/data/log
356 RECLONE=${RECLONE}
357
358 disable_all_services
359 EOF
360
361     add_os_services "${CORE_OS_COMPUTE_SERVICES}" "${ENABLE_OS_COMPUTE_SERVICES}" "${DISABLE_OS_SERVICES}" "${local_conf_file_name}"
362
363     cat >> ${local_conf_file_name} << EOF
364 #Added to make Nova wait until nova in control node is ready.
365 NOVA_READY_TIMEOUT=900
366 HOST_IP=${HOSTIP}
367 SERVICE_HOST=${SERVICEHOST}
368 Q_ML2_TENANT_NETWORK_TYPE=${TENANT_NETWORK_TYPE}
369
370 ODL_MODE=manual
371 ODL_MGR_IP=${MGRIP}
372 ODL_PORT=${ODL_PORT}
373 ODL_PORT_BINDING_CONTROLLER=${ODL_ML2_PORT_BINDING}
374 ODL_OVS_MANAGERS=${ODL_OVS_MANAGERS}
375
376 Q_HOST=\$SERVICE_HOST
377 MYSQL_HOST=\$SERVICE_HOST
378 RABBIT_HOST=\$SERVICE_HOST
379 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
380 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
381 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
382
383 ADMIN_PASSWORD=${ADMIN_PASSWORD}
384 DATABASE_PASSWORD=${ADMIN_PASSWORD}
385 RABBIT_PASSWORD=${ADMIN_PASSWORD}
386 SERVICE_TOKEN=${ADMIN_PASSWORD}
387 SERVICE_PASSWORD=${ADMIN_PASSWORD}
388 EOF
389
390     if [[ "${ENABLE_OS_PLUGINS}" =~ networking-odl ]]; then
391         cat >> ${local_conf_file_name} << EOF
392
393 enable_plugin networking-odl ${ODL_ML2_DRIVER_REPO} ${ODL_ML2_BRANCH}
394 EOF
395     fi
396
397     if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
398         cat >> ${local_conf_file_name} << EOF
399
400 PUBLIC_BRIDGE=${PUBLIC_BRIDGE}
401 PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK}
402 ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS}
403 Q_L3_ENABLED=True
404 ODL_L3=${ODL_L3}
405 EOF
406     fi
407
408     cat >> ${local_conf_file_name} << EOF
409
410 [[post-config|/etc/nova/nova.conf]]
411 [api]
412 auth_strategy = keystone
413 [DEFAULT]
414 use_neutron = True
415 force_raw_images = False
416 EOF
417
418     echo "Compute local.conf created:"
419     cat ${local_conf_file_name}
420 } # create_compute_node_local_conf()
421
422 function configure_haproxy_for_neutron_requests() {
423     MGRIP=$1
424     # shellcheck disable=SC2206
425     ODL_IPS=(${2//,/ })
426
427     cat > ${WORKSPACE}/install_ha_proxy.sh<< EOF
428 sudo systemctl stop firewalld
429 sudo yum -y install policycoreutils-python haproxy
430 EOF
431
432 cat > ${WORKSPACE}/haproxy.cfg << EOF
433 global
434   daemon
435   group  haproxy
436   log  /dev/log local0
437   maxconn  20480
438   pidfile  /tmp/haproxy.pid
439   user  haproxy
440
441 defaults
442   log  global
443   maxconn  4096
444   mode  tcp
445   retries  3
446   timeout  http-request 10s
447   timeout  queue 1m
448   timeout  connect 10s
449   timeout  client 1m
450   timeout  server 1m
451   timeout  check 10s
452
453 listen opendaylight
454   bind ${MGRIP}:8080
455   balance source
456 EOF
457
458     odlindex=1
459     for odlip in ${ODL_IPS[*]}; do
460         cat >> ${WORKSPACE}/haproxy.cfg << EOF
461   server controller-${odlindex} ${odlip}:8080 check fall 5 inter 2000 rise 2
462 EOF
463         odlindex=$((odlindex+1))
464     done
465
466     cat >> ${WORKSPACE}/haproxy.cfg << EOF
467 listen opendaylight_rest
468   bind ${MGRIP}:8181
469   balance source
470 EOF
471
472     odlindex=1
473     for odlip in ${ODL_IPS[*]}; do
474         cat >> ${WORKSPACE}/haproxy.cfg << EOF
475   server controller-rest-${odlindex} ${odlip}:8181 check fall 5 inter 2000 rise 2
476 EOF
477         odlindex=$((odlindex+1))
478     done
479
480     echo "Dump haproxy.cfg"
481     cat ${WORKSPACE}/haproxy.cfg
482
483     cat > ${WORKSPACE}/deploy_ha_proxy.sh<< EOF
484 sudo chown haproxy:haproxy /tmp/haproxy.cfg
485 sudo sed -i 's/\\/etc\\/haproxy\\/haproxy.cfg/\\/tmp\\/haproxy.cfg/g' /usr/lib/systemd/system/haproxy.service
486 sudo /usr/sbin/semanage permissive -a haproxy_t
487 sudo systemctl restart haproxy
488 sleep 3
489 sudo netstat -tunpl
490 sudo systemctl status haproxy
491 true
492 EOF
493
494     scp ${WORKSPACE}/install_ha_proxy.sh ${MGRIP}:/tmp
495     ${SSH} ${MGRIP} "sudo bash /tmp/install_ha_proxy.sh"
496     scp ${WORKSPACE}/haproxy.cfg ${MGRIP}:/tmp
497     scp ${WORKSPACE}/deploy_ha_proxy.sh ${MGRIP}:/tmp
498     ${SSH} ${MGRIP} "sudo bash /tmp/deploy_ha_proxy.sh"
499 } # configure_haproxy_for_neutron_requests()
500
501 # Collect the list of files on the hosts
502 function collect_files () {
503     local -r ip=$1
504     local -r folder=$2
505     finddir=/tmp/finder
506     ${SSH} ${ip} "mkdir -p ${finddir}"
507     ${SSH} ${ip} "sudo find /etc > ${finddir}/find.etc.txt"
508     ${SSH} ${ip} "sudo find /opt/stack > ${finddir}/find.opt.stack.txt"
509     ${SSH} ${ip} "sudo find /var > ${finddir}/find2.txt"
510     ${SSH} ${ip} "sudo find /var > ${finddir}/find.var.txt"
511     ${SSH} ${ip} "sudo tar -cf - -C /tmp finder | xz -T 0 > /tmp/find.tar.xz"
512     scp ${ip}:/tmp/find.tar.xz ${folder}
513     mkdir -p ${finddir}
514     rsync --rsync-path="sudo rsync" --list-only -arvhe ssh ${ip}:/etc/ > ${finddir}/rsync.etc.txt
515     rsync --rsync-path="sudo rsync" --list-only -arvhe ssh ${ip}:/opt/stack/ > ${finddir}/rsync.opt.stack.txt
516     rsync --rsync-path="sudo rsync" --list-only -arvhe ssh ${ip}:/var/ > ${finddir}/rsync.var.txt
517     tar -cf - -C /tmp finder | xz -T 0 > /tmp/rsync.tar.xz
518     cp /tmp/rsync.tar.xz ${folder}
519 }
520
521 function collect_logs () {
522     set +e  # We do not want to create red dot just because something went wrong while fetching logs.
523
524     cat > extra_debug.sh << EOF
525 echo -e "/usr/sbin/lsmod | /usr/bin/grep openvswitch\n"
526 /usr/sbin/lsmod | /usr/bin/grep openvswitch
527 echo -e "\ngrep ct_ /var/log/openvswitch/ovs-vswitchd.log\n"
528 grep "Datapath supports" /var/log/openvswitch/ovs-vswitchd.log
529 echo -e "\nsudo netstat -punta\n"
530 sudo netstat -punta
531 echo -e "\nsudo getenforce\n"
532 sudo getenforce
533 echo -e "\nsudo systemctl status httpd\n"
534 sudo systemctl status httpd
535 echo -e "\nenv\n"
536 env
537 source /opt/stack/devstack/openrc admin admin
538 echo -e "\nenv after openrc\n"
539 env
540 echo -e "\nsudo du -hs /opt/stack"
541 sudo du -hs /opt/stack
542 echo -e "\nsudo mount"
543 sudo mount
544 echo -e "\ndmesg -T > /tmp/dmesg.log"
545 dmesg -T > /tmp/dmesg.log
546 echo -e "\njournalctl > /tmp/journalctl.log\n"
547 sudo journalctl > /tmp/journalctl.log
548 echo -e "\novsdb-tool -mm show-log > /tmp/ovsdb-tool.log"
549 ovsdb-tool -mm show-log > /tmp/ovsdb-tool.log
550 EOF
551
552     # Since this log collection work is happening before the archive build macro which also
553     # creates the ${WORKSPACE}/archives dir, we have to do it here first.  The mkdir in the
554     # archives build step will essentially be a noop.
555     mkdir -p ${WORKSPACE}/archives
556
557     mv /tmp/changes.txt ${WORKSPACE}/archives
558
559     sleep 5
560     # FIXME: Do not create .tar and gzip before copying.
561     for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
562         CONTROLLERIP=ODL_SYSTEM_${i}_IP
563         echo "collect_logs: for opendaylight controller ip: ${!CONTROLLERIP}"
564         NODE_FOLDER="odl_${i}"
565         mkdir -p ${NODE_FOLDER}
566         echo "Lets's take the karaf thread dump again..."
567         ssh ${!CONTROLLERIP} "sudo ps aux" > ${WORKSPACE}/ps_after.log
568         pid=$(grep org.apache.karaf.main.Main ${WORKSPACE}/ps_after.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
569         echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"
570         ssh ${!CONTROLLERIP} "jstack ${pid}" > ${WORKSPACE}/karaf_${i}_${pid}_threads_after.log || true
571         echo "killing karaf process..."
572         ${SSH} "${!CONTROLLERIP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
573         ${SSH} ${!CONTROLLERIP} "sudo journalctl > /tmp/journalctl.log"
574         scp ${!CONTROLLERIP}:/tmp/journalctl.log ${NODE_FOLDER}
575         ${SSH} ${!CONTROLLERIP} "dmesg -T > /tmp/dmesg.log"
576         scp ${!CONTROLLERIP}:/tmp/dmesg.log ${NODE_FOLDER}
577         ${SSH} ${!CONTROLLERIP} "tar -cf - -C /tmp/${BUNDLEFOLDER} etc | xz -T 0 > /tmp/etc.tar.xz"
578         scp ${!CONTROLLERIP}:/tmp/etc.tar.xz ${NODE_FOLDER}
579         ${SSH} ${!CONTROLLERIP} "cp -r /tmp/${BUNDLEFOLDER}/data/log /tmp/odl_log"
580         ${SSH} ${!CONTROLLERIP} "tar -cf /tmp/odl${i}_karaf.log.tar /tmp/odl_log/*"
581         scp ${!CONTROLLERIP}:/tmp/odl${i}_karaf.log.tar ${NODE_FOLDER}
582         ${SSH} ${!CONTROLLERIP} "tar -cf /tmp/odl${i}_zrpcd.log.tar /tmp/zrpcd.init.log"
583         scp ${!CONTROLLERIP}:/tmp/odl${i}_zrpcd.log.tar ${NODE_FOLDER}
584         tar -xvf ${NODE_FOLDER}/odl${i}_karaf.log.tar -C ${NODE_FOLDER} --strip-components 2 --transform s/karaf/odl${i}_karaf/g
585         grep "ROBOT MESSAGE\| ERROR " ${NODE_FOLDER}/odl${i}_karaf.log > ${NODE_FOLDER}/odl${i}_err.log
586         grep "ROBOT MESSAGE\| ERROR \| WARN \|Exception" \
587             ${NODE_FOLDER}/odl${i}_karaf.log > ${NODE_FOLDER}/odl${i}_err_warn_exception.log
588         # Print ROBOT lines and print Exception lines. For exception lines also print the previous line for context
589         sed -n -e '/ROBOT MESSAGE/P' -e '$!N;/Exception/P;D' ${NODE_FOLDER}/odl${i}_karaf.log > ${NODE_FOLDER}/odl${i}_exception.log
590         rm ${NODE_FOLDER}/odl${i}_karaf.log.tar
591         mv *_threads* ${NODE_FOLDER}
592         mv ps_* ${NODE_FOLDER}
593         mv ${NODE_FOLDER} ${WORKSPACE}/archives/
594     done
595
596     print_job_parameters > ${WORKSPACE}/archives/params.txt
597
598     # Control Node
599     for i in `seq 1 ${NUM_OPENSTACK_CONTROL_NODES}`; do
600         OSIP=OPENSTACK_CONTROL_NODE_${i}_IP
601         echo "collect_logs: for openstack control node ip: ${!OSIP}"
602         NODE_FOLDER="control_${i}"
603         mkdir -p ${NODE_FOLDER}
604         scp extra_debug.sh ${!OSIP}:/tmp
605         ${SSH} ${!OSIP} "bash /tmp/extra_debug.sh > /tmp/extra_debug.log"
606         scp ${!OSIP}:/etc/dnsmasq.conf ${NODE_FOLDER}
607         scp ${!OSIP}:/etc/keystone/keystone.conf ${NODE_FOLDER}
608         scp ${!OSIP}:/etc/keystone/keystone-uwsgi-admin.ini ${NODE_FOLDER}
609         scp ${!OSIP}:/etc/keystone/keystone-uwsgi-public.ini ${NODE_FOLDER}
610         scp ${!OSIP}:/etc/kuryr/kuryr.conf ${NODE_FOLDER}
611         scp ${!OSIP}:/etc/neutron/dhcp_agent.ini ${NODE_FOLDER}
612         scp ${!OSIP}:/etc/neutron/metadata_agent.ini ${NODE_FOLDER}
613         scp ${!OSIP}:/etc/neutron/neutron.conf ${NODE_FOLDER}
614         scp ${!OSIP}:/etc/neutron/neutron_lbaas.conf ${NODE_FOLDER}
615         scp ${!OSIP}:/etc/neutron/plugins/ml2/ml2_conf.ini ${NODE_FOLDER}
616         scp ${!OSIP}:/etc/neutron/services/loadbalancer/haproxy/lbaas_agent.ini ${NODE_FOLDER}
617         scp ${!OSIP}:/etc/nova/nova.conf ${NODE_FOLDER}
618         scp ${!OSIP}:/etc/nova/nova-api-uwsgi.ini ${NODE_FOLDER}
619         scp ${!OSIP}:/etc/nova/nova_cell1.conf ${NODE_FOLDER}
620         scp ${!OSIP}:/etc/nova/nova-cpu.conf ${NODE_FOLDER}
621         scp ${!OSIP}:/etc/nova/placement-uwsgi.ini ${NODE_FOLDER}
622         scp ${!OSIP}:/etc/openstack/clouds.yaml ${NODE_FOLDER}
623         scp ${!OSIP}:/opt/stack/devstack/.stackenv ${NODE_FOLDER}
624         scp ${!OSIP}:/opt/stack/devstack/nohup.out ${NODE_FOLDER}/stack.log
625         scp ${!OSIP}:/opt/stack/devstack/openrc ${NODE_FOLDER}
626         scp ${!OSIP}:/opt/stack/requirements/upper-constraints.txt ${NODE_FOLDER}
627         scp ${!OSIP}:/opt/stack/tempest/etc/tempest.conf ${NODE_FOLDER}
628         scp ${!OSIP}:/tmp/*.xz ${NODE_FOLDER}
629         scp ${!OSIP}:/tmp/dmesg.log ${NODE_FOLDER}
630         scp ${!OSIP}:/tmp/extra_debug.log ${NODE_FOLDER}
631         scp ${!OSIP}:/tmp/get_devstack.sh.txt ${NODE_FOLDER}
632         scp ${!OSIP}:/tmp/journalctl.log ${NODE_FOLDER}
633         scp ${!OSIP}:/tmp/ovsdb-tool.log ${NODE_FOLDER}
634         scp ${!OSIP}:/var/log/openvswitch/ovs-vswitchd.log ${NODE_FOLDER}
635         scp ${!OSIP}:/var/log/openvswitch/ovsdb-server.log ${NODE_FOLDER}
636         collect_files "${!OSIP}" "${NODE_FOLDER}"
637         ${SSH} ${!OSIP} "sudo tar -cf - -C /var/log rabbitmq | xz -T 0 > /tmp/rabbitmq.tar.xz "
638         scp ${!OSIP}:/tmp/rabbitmq.tar.xz ${NODE_FOLDER}
639         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/etc/hosts ${NODE_FOLDER}
640         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/usr/lib/systemd/system/haproxy.service ${NODE_FOLDER}
641         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/var/log/audit/audit.log ${NODE_FOLDER}
642         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/var/log/httpd/keystone_access.log ${NODE_FOLDER}
643         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/var/log/httpd/keystone.log ${NODE_FOLDER}
644         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/var/log/messages ${NODE_FOLDER}
645         rsync -avhe ssh ${!OSIP}:/opt/stack/logs/* ${NODE_FOLDER} # rsync to prevent copying of symbolic links
646         mv local.conf_control_${!OSIP} ${NODE_FOLDER}/local.conf
647         # qdhcp files are created by robot tests and copied into /tmp/qdhcp during the test
648         tar -cf - -C /tmp qdhcp | xz -T 0 > /tmp/qdhcp.tar.xz
649         mv /tmp/qdhcp.tar.xz ${NODE_FOLDER}
650         mv ${NODE_FOLDER} ${WORKSPACE}/archives/
651     done
652
653     # Compute Nodes
654     for i in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`; do
655         OSIP=OPENSTACK_COMPUTE_NODE_${i}_IP
656         echo "collect_logs: for openstack compute node ip: ${!OSIP}"
657         NODE_FOLDER="compute_${i}"
658         mkdir -p ${NODE_FOLDER}
659         scp extra_debug.sh ${!OSIP}:/tmp
660         ${SSH} ${!OSIP} "bash /tmp/extra_debug.sh > /tmp/extra_debug.log"
661         scp ${!OSIP}:/etc/nova/nova.conf ${NODE_FOLDER}
662         scp ${!OSIP}:/etc/nova/nova-cpu.conf ${NODE_FOLDER}
663         scp ${!OSIP}:/etc/openstack/clouds.yaml ${NODE_FOLDER}
664         scp ${!OSIP}:/opt/stack/devstack/.stackenv ${NODE_FOLDER}
665         scp ${!OSIP}:/opt/stack/devstack/nohup.out ${NODE_FOLDER}/stack.log
666         scp ${!OSIP}:/opt/stack/devstack/openrc ${NODE_FOLDER}
667         scp ${!OSIP}:/opt/stack/requirements/upper-constraints.txt ${NODE_FOLDER}
668         scp ${!OSIP}:/tmp/*.xz ${NODE_FOLDER}/
669         scp ${!OSIP}:/tmp/dmesg.log ${NODE_FOLDER}
670         scp ${!OSIP}:/tmp/extra_debug.log ${NODE_FOLDER}
671         scp ${!OSIP}:/tmp/get_devstack.sh.txt ${NODE_FOLDER}
672         scp ${!OSIP}:/tmp/journalctl.log ${NODE_FOLDER}
673         scp ${!OSIP}:/tmp/ovsdb-tool.log ${NODE_FOLDER}
674         scp ${!OSIP}:/var/log/openvswitch/ovs-vswitchd.log ${NODE_FOLDER}
675         scp ${!OSIP}:/var/log/openvswitch/ovsdb-server.log ${NODE_FOLDER}
676         collect_files "${!OSIP}" "${NODE_FOLDER}"
677         ${SSH} ${!OSIP} "sudo tar -cf - -C /var/log libvirt | xz -T 0 > /tmp/libvirt.tar.xz "
678         scp ${!OSIP}:/tmp/libvirt.tar.xz ${NODE_FOLDER}
679         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/etc/hosts ${NODE_FOLDER}
680         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/var/log/audit/audit.log ${NODE_FOLDER}
681         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/var/log/messages ${NODE_FOLDER}
682         rsync --rsync-path="sudo rsync" -avhe ssh ${!OSIP}:/var/log/nova-agent.log ${NODE_FOLDER}
683         rsync -avhe ssh ${!OSIP}:/opt/stack/logs/* ${NODE_FOLDER} # rsync to prevent copying of symbolic links
684         mv local.conf_compute_${!OSIP} ${NODE_FOLDER}/local.conf
685         mv ${NODE_FOLDER} ${WORKSPACE}/archives/
686     done
687
688     # Tempest
689     DEVSTACK_TEMPEST_DIR="/opt/stack/tempest"
690     TESTREPO=".stestr"
691     TEMPEST_LOGS_DIR=${WORKSPACE}/archives/tempest
692     # Look for tempest test results in the $TESTREPO dir and copy if found
693     if ${SSH} ${OPENSTACK_CONTROL_NODE_1_IP} "sudo sh -c '[ -f ${DEVSTACK_TEMPEST_DIR}/${TESTREPO}/0 ]'"; then
694         ${SSH} ${OPENSTACK_CONTROL_NODE_1_IP} "for I in \$(sudo ls ${DEVSTACK_TEMPEST_DIR}/${TESTREPO}/ | grep -E '^[0-9]+$'); do sudo sh -c \"${DEVSTACK_TEMPEST_DIR}/.tox/tempest/bin/subunit-1to2 < ${DEVSTACK_TEMPEST_DIR}/${TESTREPO}/\${I} >> ${DEVSTACK_TEMPEST_DIR}/subunit_log.txt\"; done"
695         ${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'"
696         mkdir -p ${TEMPEST_LOGS_DIR}
697         scp ${OPENSTACK_CONTROL_NODE_1_IP}:${DEVSTACK_TEMPEST_DIR}/tempest_results.html ${TEMPEST_LOGS_DIR}
698         scp ${OPENSTACK_CONTROL_NODE_1_IP}:${DEVSTACK_TEMPEST_DIR}/tempest.log ${TEMPEST_LOGS_DIR}
699         if [ "$(echo ${OPENSTACK_BRANCH} | cut -d/ -f2)" != "master" ]; then
700            mv ${WORKSPACE}/tempest_output* ${TEMPEST_LOGS_DIR}
701         fi
702     else
703         echo "tempest results not found in ${DEVSTACK_TEMPEST_DIR}/${TESTREPO}/0"
704     fi
705 } # collect_logs()
706
707 # Following three functions are debugging helpers when debugging devstack changes.
708 # Keeping them for now so we can simply call them when needed.
709 ctrlhn=""
710 comp1hn=""
711 comp2hn=""
712 function get_hostnames () {
713     set +e
714     local ctrlip=${OPENSTACK_CONTROL_NODE_1_IP}
715     local comp1ip=${OPENSTACK_COMPUTE_NODE_1_IP}
716     local comp2ip=${OPENSTACK_COMPUTE_NODE_2_IP}
717     ctrlhn=$(${SSH} ${ctrlip} "hostname")
718     comp1hn=$(${SSH} ${comp1ip} "hostname")
719     comp2hn=$(${SSH} ${comp2ip} "hostname")
720     echo "hostnames: ${ctrlhn}, ${comp1hn}, ${comp2hn}"
721     set -e
722 }
723
724 function check_firewall() {
725     set +e
726     echo $-
727     local ctrlip=${OPENSTACK_CONTROL_NODE_1_IP}
728     local comp1ip=${OPENSTACK_COMPUTE_NODE_1_IP}
729     local comp2ip=${OPENSTACK_COMPUTE_NODE_2_IP}
730
731     echo "check_firewall on control"
732     ${SSH} ${ctrlip} "
733         sudo systemctl status firewalld
734         sudo systemctl -l status iptables
735         sudo iptables --line-numbers -nvL
736     " || true
737     echo "check_firewall on compute 1"
738     ${SSH} ${comp1ip} "
739         sudo systemctl status firewalld
740         sudo systemctl -l status iptables
741         sudo iptables --line-numbers -nvL
742     " || true
743     echo "check_firewall on compute 2"
744     ${SSH} ${comp2ip} "
745         sudo systemctl status firewalld
746         sudo systemctl -l status iptables
747         sudo iptables --line-numbers -nvL
748     " || true
749 }
750
751 function get_service () {
752     set +e
753     local iter=$1
754     #local idx=$2
755     local ctrlip=${OPENSTACK_CONTROL_NODE_1_IP}
756     local comp1ip=${OPENSTACK_COMPUTE_NODE_1_IP}
757
758     #if [ ${idx} -eq 1 ]; then
759         if [ ${iter} -eq 1 ] || [ ${iter} -gt 16 ]; then
760             curl http://${ctrlip}:5000
761             curl http://${ctrlip}:35357
762             curl http://${ctrlip}/identity
763             ${SSH} ${ctrlip} "
764                 source /opt/stack/devstack/openrc admin admin;
765                 env
766                 openstack configuration show --unmask;
767                 openstack service list
768                 openstack --os-cloud devstack-admin --os-region RegionOne compute service list
769                 openstack hypervisor list;
770             " || true
771             check_firewall
772         fi
773     #fi
774     set -e
775 }
776
777 # Check if rabbitmq is ready by looking for a pid in it's status.
778 # The function returns the status of the grep command which callers can check.
779 function is_rabbitmq_ready() {
780     local -r ip=$1
781     rm -f rabbit.txt
782     ${SSH} ${ip} "sudo rabbitmqctl list_vhosts" > rabbit.txt
783     grep nova_cell1 rabbit.txt
784 }
785
786 # retry the given command ($3) until success for a number of iterations ($1)
787 # sleeping ($2) between tries.
788 function retry() {
789     local -r -i max_tries=${1}
790     local -r -i sleep_time=${2}
791     local -r cmd=${3}
792     local -i retries=1
793     local -i rc=1
794     while true; do
795         echo "retry ${cmd}: attempt: ${retries}"
796         ${cmd}
797         rc=$?
798         if ((${rc} == 0)); then
799             break;
800         else
801             if ((${retries} == ${max_tries})); then
802                 break
803             else
804                 ((retries++))
805                 sleep ${sleep_time}
806             fi
807         fi
808     done
809     return ${rc}
810 }
811
812 # if we are using the new netvirt impl, as determined by the feature name
813 # odl-netvirt-openstack (note: old impl is odl-ovsdb-openstack) then we
814 # want PROVIDER_MAPPINGS to be used -- this should be fixed if we want to support
815 # external networks in legacy netvirt
816 if [[ ${CONTROLLERFEATURES} == *"odl-netvirt-openstack"* ]]; then
817   ODL_PROVIDER_MAPPINGS="\${PUBLIC_PHYSICAL_NETWORK}:${PUBLIC_BRIDGE}"
818 else
819   ODL_PROVIDER_MAPPINGS=
820 fi
821
822 # if we are using the old netvirt impl, as determined by the feature name
823 # odl-ovsdb-openstack (note: new impl is odl-netvirt-openstack) then we
824 # want ODL_L3 to be True.  New impl wants it False
825 if [[ ${CONTROLLERFEATURES} == *"odl-ovsdb-openstack"* ]]; then
826     ODL_L3=True
827 else
828     ODL_L3=False
829 fi
830
831 RECLONE=False
832 ODL_PORT=8181
833
834 # Always compare the lists below against the devstack upstream ENABLED_SERVICES in
835 # https://github.com/openstack-dev/devstack/blob/master/stackrc#L52
836 # ODL CSIT does not use vnc, cinder, q-agt, q-l3 or horizon so they are not included below.
837 # collect performance stats
838 CORE_OS_CONTROL_SERVICES="dstat"
839 # Glance
840 CORE_OS_CONTROL_SERVICES+=",g-api,g-reg"
841 # Keystone
842 CORE_OS_CONTROL_SERVICES+=",key"
843 # Nova - services to support libvirt
844 CORE_OS_CONTROL_SERVICES+=",n-api,n-api-meta,n-cauth,n-cond,n-crt,n-obj,n-sch"
845 # ODL - services to connect to ODL
846 CORE_OS_CONTROL_SERVICES+=",odl-compute,odl-neutron"
847 # Additional services
848 CORE_OS_CONTROL_SERVICES+=",mysql,rabbit"
849
850 # collect performance stats
851 CORE_OS_COMPUTE_SERVICES="dstat"
852 # computes only need nova and odl
853 CORE_OS_COMPUTE_SERVICES+=",n-cpu,odl-compute"
854
855 cat > ${WORKSPACE}/disable_firewall.sh << EOF
856 sudo systemctl stop firewalld
857 # Open these ports to match the tutorial vms
858 # http/https (80/443), samba (445), netbios (137,138,139)
859 sudo iptables -I INPUT -p tcp -m multiport --dports 80,443,139,445 -j ACCEPT
860 sudo iptables -I INPUT -p udp -m multiport --dports 137,138 -j ACCEPT
861 # OpenStack services as well as vxlan tunnel ports 4789 and 9876
862 # identity public/admin (5000/35357), ampq (5672), vnc (6080), nova (8774), glance (9292), neutron (9696)
863 sudo sudo iptables -I INPUT -p tcp -m multiport --dports 5000,5672,6080,8774,9292,9696,35357 -j ACCEPT
864 sudo sudo iptables -I INPUT -p udp -m multiport --dports 4789,9876 -j ACCEPT
865 sudo iptables-save > /etc/sysconfig/iptables
866 sudo systemctl restart iptables
867 sudo iptables --line-numbers -nvL
868 true
869 EOF
870
871 cat > ${WORKSPACE}/get_devstack.sh << EOF
872 sudo systemctl stop firewalld
873 sudo yum install bridge-utils python-pip -y
874 #sudo systemctl stop  NetworkManager
875 #Disable NetworkManager and kill dhclient and dnsmasq
876 sudo systemctl stop NetworkManager
877 sudo killall dhclient
878 sudo killall dnsmasq
879 #Workaround for mysql failure
880 echo "127.0.0.1   localhost \${HOSTNAME}" >> /tmp/hosts
881 echo "::1         localhost \${HOSTNAME}" >> /tmp/hosts
882 sudo mv /tmp/hosts /etc/hosts
883 sudo mkdir /opt/stack
884 echo "Create RAM disk for /opt/stack"
885 sudo mount -t tmpfs -o size=2G tmpfs /opt/stack
886 sudo chmod 777 /opt/stack
887 cd /opt/stack
888 echo "git clone https://git.openstack.org/openstack-dev/devstack --branch ${OPENSTACK_BRANCH}"
889 git clone https://git.openstack.org/openstack-dev/devstack --branch ${OPENSTACK_BRANCH}
890 cd devstack
891 if [ -n "${DEVSTACK_HASH}" ]; then
892     echo "git checkout ${DEVSTACK_HASH}"
893     git checkout ${DEVSTACK_HASH}
894 fi
895 git --no-pager log --pretty=format:'%h %<(13)%ar%<(13)%cr %<(20,trunc)%an%d %s\n%b' -n20
896 echo "workaround: adjust wait from 60s to 1800s (30m)"
897 sed -i 's/wait_for_compute 60/wait_for_compute 1800/g' /opt/stack/devstack/lib/nova
898 # TODO: modify sleep 1 to sleep 60, search wait_for_compute, then first sleep 1
899 # that would just reduce the number of logs in the compute stack.log
900
901 #Install qemu-img command in Control Node for Pike
902 echo "Install qemu-img application"
903 sudo yum install -y qemu-img
904 EOF
905
906 cat > "${WORKSPACE}/setup_host_cell_mapping.sh" << EOF
907 sudo nova-manage cell_v2 map_cell0
908 sudo nova-manage cell_v2 simple_cell_setup
909 sudo nova-manage db sync
910 sudo nova-manage cell_v2 discover_hosts
911 EOF
912
913 NUM_OPENSTACK_SITES=${NUM_OPENSTACK_SITES:-1}
914 compute_index=1
915 odl_index=1
916 os_node_list=()
917 os_interval=$(( ${NUM_OPENSTACK_SYSTEM} / ${NUM_OPENSTACK_SITES} ))
918 ha_proxy_index=${os_interval}
919
920 for i in `seq 1 ${NUM_OPENSTACK_SITES}`; do
921     if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
922         echo "Configure HAProxy"
923         ODL_HAPROXYIP_PARAM=OPENSTACK_HAPROXY_${i}_IP
924         ha_proxy_index=$(( $ha_proxy_index + $os_interval ))
925         odl_index=$(((i - 1) * 3 + 1))
926         ODL_IP_PARAM1=ODL_SYSTEM_$((odl_index++))_IP
927         ODL_IP_PARAM2=ODL_SYSTEM_$((odl_index++))_IP
928         ODL_IP_PARAM3=ODL_SYSTEM_$((odl_index++))_IP
929         ODLMGRIP[$i]=${!ODL_HAPROXYIP_PARAM} # ODL Northbound uses HAProxy VIP
930         ODL_OVS_MGRS[$i]="${!ODL_IP_PARAM1},${!ODL_IP_PARAM2},${!ODL_IP_PARAM3}" # OVSDB connects to all ODL IPs
931         configure_haproxy_for_neutron_requests ${!ODL_HAPROXYIP_PARAM} "${ODL_OVS_MGRS[$i]}"
932     else
933         ODL_IP_PARAM=ODL_SYSTEM_${i}_IP
934         ODL_OVS_MGRS[$i]="${!ODL_IP_PARAM}" # ODL Northbound uses ODL IP
935         ODLMGRIP[$i]=${!ODL_IP_PARAM} # OVSDB connects to ODL IP
936     fi
937 done
938
939 # Begin stacking the nodes, starting with the controller(s) and then the compute(s)
940
941 for i in `seq 1 ${NUM_OPENSTACK_CONTROL_NODES}`; do
942     CONTROLIP=OPENSTACK_CONTROL_NODE_${i}_IP
943     echo "Configure the stack of the control node ${i} of ${NUM_OPENSTACK_CONTROL_NODES}: ${!CONTROLIP}"
944     scp ${WORKSPACE}/disable_firewall.sh ${!CONTROLIP}:/tmp
945     ${SSH} ${!CONTROLIP} "sudo bash /tmp/disable_firewall.sh"
946     create_etc_hosts ${!CONTROLIP}
947     scp ${WORKSPACE}/hosts_file ${!CONTROLIP}:/tmp/hosts
948     scp ${WORKSPACE}/get_devstack.sh ${!CONTROLIP}:/tmp
949     # devstack Master is yet to migrate fully to lib/neutron, there are some ugly hacks that is
950     # affecting the stacking.
951     #Workaround For Queens, Make the physical Network as physnet1 in lib/neutron
952     #Workaround Comment out creating initial Networks in lib/neutron
953     ${SSH} ${!CONTROLIP} "bash /tmp/get_devstack.sh > /tmp/get_devstack.sh.txt 2>&1"
954     if [ "${ODL_ML2_BRANCH}" == "master" ]; then
955        ssh ${!CONTROLIP} "sed -i 's/flat_networks public/flat_networks public,physnet1/' /opt/stack/devstack/lib/neutron"
956        ssh ${!CONTROLIP} "sed -i '186i iniset \$NEUTRON_CORE_PLUGIN_CONF ml2_type_vlan network_vlan_ranges public:1:4094,physnet1:1:4094' /opt/stack/devstack/lib/neutron"
957     fi
958     if [[ "${ODL_ML2_BRANCH}" == "stable/ocata" && "$(is_openstack_feature_enabled n-cpu)" == "1" ]]; then
959         echo "Updating requirements for ${ODL_ML2_BRANCH}"
960         echo "Workaround for https://review.openstack.org/#/c/491032/"
961         echo "Modify upper-constraints to use libvirt-python 3.2.0"
962         fix_libvirt_version_n_cpu_ocata ${!CONTROLIP}
963     fi
964     create_control_node_local_conf ${!CONTROLIP} ${ODLMGRIP[$i]} "${ODL_OVS_MGRS[$i]}"
965     scp ${WORKSPACE}/local.conf_control_${!CONTROLIP} ${!CONTROLIP}:/opt/stack/devstack/local.conf
966     echo "Stack the control node ${i} of ${NUM_OPENSTACK_CONTROL_NODES}: ${CONTROLIP}"
967     ssh ${!CONTROLIP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
968     ssh ${!CONTROLIP} "ps -ef | grep stack.sh"
969     ssh ${!CONTROLIP} "ls -lrt /opt/stack/devstack/nohup.out"
970     os_node_list+=("${!CONTROLIP}")
971 done
972
973 # This is a backup to the CELLSV2_SETUP=singleconductor workaround. Keeping it here as an easy lookup
974 # if needed.
975 # Let the control node get started to avoid a race condition where the computes start and try to access
976 # the nova_cell1 on the control node before it is created. If that happens, the nova-compute service on the
977 # compute exits and does not attempt to restart.
978 # 180s is chosen because in test runs the control node usually finished in 17-20 minutes and the computes finished
979 # in 17 minutes, so take the max difference of 3 minutes and the jobs should still finish around the same time.
980 # one of the following errors is seen in the compute n-cpu.log:
981 # Unhandled error: NotAllowed: Connection.open: (530) NOT_ALLOWED - access to vhost 'nova_cell1' refused for user 'stackrabbit'
982 # AccessRefused: (0, 0): (403) ACCESS_REFUSED - Login was refused using authentication mechanism AMQPLAIN. For details see the broker logfile.
983 # Compare that timestamp to this log in the control stack.log: sudo rabbitmqctl set_permissions -p nova_cell1 stackrabbit
984 # If the n-cpu.log is earlier than the control stack.log timestamp then the failure condition is likely hit.
985 if [ ${NUM_OPENSTACK_COMPUTE_NODES} -gt 0 ]; then
986     WAIT_FOR_RABBITMQ_MINUTES=60
987     echo "Wait a maximum of ${WAIT_FOR_RABBITMQ_MINUTES}m until rabbitmq is ready to allow the controller to create nova_cell1 before the computes need it"
988     set +e
989     retry ${WAIT_FOR_RABBITMQ_MINUTES} 60 "is_rabbitmq_ready ${OPENSTACK_CONTROL_NODE_1_IP}"
990     rc=$?
991     set -e
992     if ((${rc} == 0)); then
993       echo "rabbitmq is ready, starting ${NUM_OPENSTACK_COMPUTE_NODES} compute(s)"
994     else
995       echo "rabbitmq was not ready in ${WAIT_FOR_RABBITMQ_MINUTES}m"
996       collect_logs
997       exit 1
998     fi
999 fi
1000
1001 for i in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`; do
1002     NUM_COMPUTES_PER_SITE=$((NUM_OPENSTACK_COMPUTE_NODES / NUM_OPENSTACK_SITES))
1003     SITE_INDEX=$((((i - 1) / NUM_COMPUTES_PER_SITE) + 1)) # We need the site index to infer the control node IP for this compute
1004     COMPUTEIP=OPENSTACK_COMPUTE_NODE_${i}_IP
1005     CONTROLIP=OPENSTACK_CONTROL_NODE_${SITE_INDEX}_IP
1006     echo "Configure the stack of the compute node ${i} of ${NUM_OPENSTACK_COMPUTE_NODES}: ${!COMPUTEIP}"
1007     scp ${WORKSPACE}/disable_firewall.sh "${!COMPUTEIP}:/tmp"
1008     ${SSH} "${!COMPUTEIP}" "sudo bash /tmp/disable_firewall.sh"
1009     create_etc_hosts ${!COMPUTEIP} ${!CONTROLIP}
1010     scp ${WORKSPACE}/hosts_file ${!COMPUTEIP}:/tmp/hosts
1011     scp ${WORKSPACE}/get_devstack.sh  ${!COMPUTEIP}:/tmp
1012     ${SSH} ${!COMPUTEIP} "bash /tmp/get_devstack.sh > /tmp/get_devstack.sh.txt 2>&1"
1013     if [ "${ODL_ML2_BRANCH}" == "stable/ocata" ]; then
1014         echo "Updating requirements for ${ODL_ML2_BRANCH}"
1015         echo "Workaround for https://review.openstack.org/#/c/491032/"
1016         echo "Modify upper-constraints to use libvirt-python 3.2.0"
1017         fix_libvirt_version_n_cpu_ocata ${!COMPUTEIP}
1018     fi
1019     create_compute_node_local_conf ${!COMPUTEIP} ${!CONTROLIP} ${ODLMGRIP[$SITE_INDEX]} "${ODL_OVS_MGRS[$SITE_INDEX]}"
1020     scp ${WORKSPACE}/local.conf_compute_${!COMPUTEIP} ${!COMPUTEIP}:/opt/stack/devstack/local.conf
1021     echo "Stack the compute node ${i} of ${NUM_OPENSTACK_COMPUTE_NODES}: ${COMPUTEIP}"
1022     ssh ${!COMPUTEIP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
1023     ssh ${!COMPUTEIP} "ps -ef | grep stack.sh"
1024     os_node_list+=("${!COMPUTEIP}")
1025 done
1026
1027 echo "nodelist: ${os_node_list[*]}"
1028
1029 # This script runs on the openstack nodes. It greps for a string that devstack writes when stacking is complete.
1030 # The script then writes a status depending on the grep output that is later scraped by the robot vm to control
1031 # the status polling.
1032 cat > ${WORKSPACE}/check_stacking.sh << EOF
1033 > /tmp/stack_progress
1034 ps -ef | grep "stack.sh" | grep -v grep
1035 ret=\$?
1036 if [ \${ret} -eq 1 ]; then
1037     grep "This is your host IP address:" /opt/stack/devstack/nohup.out
1038     if [ \$? -eq 0 ]; then
1039         echo "Stacking Complete" > /tmp/stack_progress
1040     else
1041         echo "Stacking Failed" > /tmp/stack_progress
1042     fi
1043 elif [ \${ret} -eq 0 ]; then
1044     echo "Still Stacking" > /tmp/stack_progress
1045 fi
1046 EOF
1047
1048 # devstack debugging
1049 # get_hostnames
1050
1051 # Check if the stacking is finished. Poll all nodes every 60s for one hour.
1052 iteration=0
1053 in_progress=1
1054 while [ ${in_progress} -eq 1 ]; do
1055     iteration=$(($iteration + 1))
1056     for index in "${!os_node_list[@]}"; do
1057         echo "node $index ${os_node_list[index]}: checking stacking status attempt ${iteration} of 60"
1058         scp ${WORKSPACE}/check_stacking.sh  ${os_node_list[index]}:/tmp
1059         ${SSH} ${os_node_list[index]} "bash /tmp/check_stacking.sh"
1060         scp ${os_node_list[index]}:/tmp/stack_progress .
1061         cat stack_progress
1062         stacking_status=`cat stack_progress`
1063         # devstack debugging
1064         # get_service "${iteration}" "${index}"
1065         if [ "$stacking_status" == "Still Stacking" ]; then
1066             continue
1067         elif [ "$stacking_status" == "Stacking Failed" ]; then
1068             echo "node $index ${os_node_list[index]}: stacking has failed"
1069             collect_logs
1070             exit 1
1071         elif [ "$stacking_status" == "Stacking Complete" ]; then
1072             echo "node $index ${os_node_list[index]}: stacking complete"
1073             unset 'os_node_list[index]'
1074             if  [ ${#os_node_list[@]} -eq 0 ]; then
1075                 in_progress=0
1076             fi
1077         fi
1078     done
1079     echo "sleep for a minute before the next check"
1080     sleep 60
1081     if [ ${iteration} -eq 60 ]; then
1082         echo "stacking has failed - took longer than 60m"
1083         collect_logs
1084         exit 1
1085     fi
1086 done
1087
1088 # Further configuration now that stacking is complete.
1089 NUM_COMPUTES_PER_SITE=$((NUM_OPENSTACK_COMPUTE_NODES / NUM_OPENSTACK_SITES))
1090 for i in `seq 1 ${NUM_OPENSTACK_SITES}`; do
1091     echo "Configure the Control Node"
1092     CONTROLIP=OPENSTACK_CONTROL_NODE_${i}_IP
1093     # Gather Compute IPs for the site
1094     for j in `seq 1 ${NUM_COMPUTES_PER_SITE}`; do
1095         COMPUTE_INDEX=$(((i-1) * NUM_COMPUTES_PER_SITE + j))
1096         IP_VAR=OPENSTACK_COMPUTE_NODE_${COMPUTE_INDEX}_IP
1097         COMPUTE_IPS[$((j-1))]=${!IP_VAR}
1098     done
1099
1100     echo "sleep for 60s and print hypervisor-list"
1101     sleep 60
1102     # In Ocata if we do not enable the n-cpu in control node then
1103     # we need to discover hosts manually and ensure that they are mapped to cells.
1104     # reference: https://ask.openstack.org/en/question/102256/how-to-configure-placement-service-for-compute-node-on-ocata/
1105     if [ "${OPENSTACK_BRANCH}" == "stable/ocata" ]; then
1106         scp ${WORKSPACE}/setup_host_cell_mapping.sh  ${!CONTROLIP}:/tmp
1107         ${SSH} ${!CONTROLIP} "sudo bash /tmp/setup_host_cell_mapping.sh"
1108     fi
1109     ${SSH} ${!CONTROLIP} "cd /opt/stack/devstack; source openrc admin admin; nova hypervisor-list"
1110     # in the case that we are doing openstack (control + compute) all in one node, then the number of hypervisors
1111     # will be the same as the number of openstack systems. However, if we are doing multinode openstack then the
1112     # assumption is we have a single control node and the rest are compute nodes, so the number of expected hypervisors
1113     # is one less than the total number of openstack systems
1114     if [ $((NUM_OPENSTACK_SYSTEM / NUM_OPENSTACK_SITES)) -eq 1 ]; then
1115         expected_num_hypervisors=1
1116     else
1117         expected_num_hypervisors=${NUM_COMPUTES_PER_SITE}
1118     fi
1119     num_hypervisors=$(${SSH} ${!CONTROLIP} "cd /opt/stack/devstack; source openrc admin admin; openstack hypervisor list -f value | wc -l" | tail -1 | tr -d "\r")
1120     if ! [ "${num_hypervisors}" ] || ! [ ${num_hypervisors} -eq ${expected_num_hypervisors} ]; then
1121         echo "Error: Only $num_hypervisors hypervisors detected, expected $expected_num_hypervisors"
1122         collect_logs
1123         exit 1
1124     fi
1125
1126     # upgrading pip, urllib3 and httplib2 so that tempest tests can be run on openstack control node
1127     # this needs to happen after devstack runs because it seems devstack is pulling in specific versions
1128     # of these libs that are not working for tempest.
1129     ${SSH} ${!CONTROLIP} "sudo pip install --upgrade pip"
1130     ${SSH} ${!CONTROLIP} "sudo pip install urllib3 --upgrade"
1131     ${SSH} ${!CONTROLIP} "sudo pip install httplib2 --upgrade"
1132
1133     # Gather Compute IPs for the site
1134     for j in `seq 1 ${NUM_COMPUTES_PER_SITE}`; do
1135         COMPUTE_INDEX=$(((i-1) * NUM_COMPUTES_PER_SITE + j))
1136         IP_VAR=OPENSTACK_COMPUTE_NODE_${COMPUTE_INDEX}_IP
1137         COMPUTE_IPS[$((j-1))]=${!IP_VAR}
1138     done
1139
1140     # External Network
1141     echo "prepare external networks by adding vxlan tunnels between all nodes on a separate bridge..."
1142     # FIXME Should there be a unique gateway IP and devstack index for each site?
1143     devstack_index=1
1144     for ip in ${!CONTROLIP} ${COMPUTE_IPS[*]}; do
1145         # 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
1146         ${SSH} $ip "sudo ovs-vsctl --if-exists del-port br-int $PUBLIC_BRIDGE"
1147         ${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++))"
1148     done
1149
1150     # ipsec support
1151     if [ "${IPSEC_VXLAN_TUNNELS_ENABLED}" == "yes" ]; then
1152         # shellcheck disable=SC2206
1153         ALL_NODES=(${!CONTROLIP} ${COMPUTE_IPS[*]})
1154         for ((inx_ip1=0; inx_ip1<$((${#ALL_NODES[@]} - 1)); inx_ip1++)); do
1155             for ((inx_ip2=$((inx_ip1 + 1)); inx_ip2<${#ALL_NODES[@]}; inx_ip2++)); do
1156                 KEY1=0x$(dd if=/dev/urandom count=32 bs=1 2> /dev/null| xxd -p -c 64)
1157                 KEY2=0x$(dd if=/dev/urandom count=32 bs=1 2> /dev/null| xxd -p -c 64)
1158                 ID=0x$(dd if=/dev/urandom count=4 bs=1 2> /dev/null| xxd -p -c 8)
1159                 ip1=${ALL_NODES[$inx_ip1]}
1160                 ip2=${ALL_NODES[$inx_ip2]}
1161                 ${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"
1162                 ${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"
1163                 ${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"
1164                 ${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"
1165
1166                 ${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"
1167                 ${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"
1168                 ${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"
1169                 ${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"
1170             done
1171         done
1172
1173         for ip in ${!CONTROLIP} ${COMPUTE_IPS[*]}; do
1174             echo "ip xfrm configuration for node $ip:"
1175             ${SSH} $ip "sudo ip xfrm policy list"
1176             ${SSH} $ip "sudo ip xfrm state list"
1177         done
1178     fi
1179
1180     # Control Node - PUBLIC_BRIDGE will act as the external router
1181     # Parameter values below are used in integration/test - changing them requires updates in intergration/test as well
1182     EXTNET_GATEWAY_IP="10.10.10.250"
1183     EXTNET_INTERNET_IP="10.9.9.9"
1184     EXTNET_PNF_IP="10.10.10.253"
1185     ${SSH} ${!CONTROLIP} "sudo ifconfig ${PUBLIC_BRIDGE} up ${EXTNET_GATEWAY_IP}/24"
1186
1187     # Control Node - external net PNF simulation
1188     ${SSH} ${!CONTROLIP} "
1189         sudo ip netns add pnf_ns;
1190         sudo ip link add pnf_veth0 type veth peer name pnf_veth1;
1191         sudo ip link set pnf_veth1 netns pnf_ns;
1192         sudo ip link set pnf_veth0 up;
1193         sudo ip netns exec pnf_ns ifconfig pnf_veth1 up ${EXTNET_PNF_IP}/24;
1194         sudo ovs-vsctl add-port ${PUBLIC_BRIDGE} pnf_veth0;
1195     "
1196
1197     # Control Node - external net internet address simulation
1198     ${SSH} ${!CONTROLIP} "
1199         sudo ip tuntap add dev internet_tap mode tap;
1200         sudo ifconfig internet_tap up ${EXTNET_INTERNET_IP}/24;
1201     "
1202
1203     # Computes
1204     compute_index=1
1205     for compute_ip in ${COMPUTE_IPS[*]}; do
1206         # Tunnel from controller to compute
1207         COMPUTEPORT=compute$(( compute_index++ ))_vxlan
1208         ${SSH} ${!CONTROLIP} "
1209             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
1210         "
1211         # Tunnel from compute to controller
1212         CONTROLPORT="control_vxlan"
1213         ${SSH} $compute_ip "
1214             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
1215         "
1216     done
1217 done
1218
1219 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
1220     odlmgrip=OPENSTACK_HAPROXY_1_IP
1221     HA_PROXY_IP=${!odlmgrip}
1222     HA_PROXY_1_IP=${!odlmgrip}
1223     odlmgrip2=OPENSTACK_HAPROXY_2_IP
1224     HA_PROXY_2_IP=${!odlmgrip2}
1225     odlmgrip3=OPENSTACK_HAPROXY_1_IP
1226     HA_PROXY_3_IP=${!odlmgrip3}
1227 else
1228     HA_PROXY_IP=${ODL_SYSTEM_IP}
1229     HA_PROXY_1_IP=${ODL_SYSTEM_1_IP}
1230     HA_PROXY_2_IP=${ODL_SYSTEM_2_IP}
1231     HA_PROXY_3_IP=${ODL_SYSTEM_3_IP}
1232 fi
1233
1234 echo "Locating test plan to use..."
1235 testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
1236 if [ ! -f "${testplan_filepath}" ]; then
1237     testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
1238 fi
1239
1240 echo "Changing the testplan path..."
1241 cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
1242 cat testplan.txt
1243
1244 # Use the testplan if specific SUITES are not defined.
1245 if [ -z "${SUITES}" ]; then
1246     SUITES=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
1247 else
1248     newsuites=""
1249     workpath="${WORKSPACE}/test/csit/suites"
1250     for suite in ${SUITES}; do
1251         fullsuite="${workpath}/${suite}"
1252         if [ -z "${newsuites}" ]; then
1253             newsuites+=${fullsuite}
1254         else
1255             newsuites+=" "${fullsuite}
1256         fi
1257     done
1258     SUITES=${newsuites}
1259 fi
1260
1261 #install all client versions required for this job testing
1262 install_openstack_clients_in_robot_vm
1263
1264 # TODO: run openrc on control node and then scrape the vars from it
1265 # Environment Variables Needed to execute Openstack Client for NetVirt Jobs
1266 cat > /tmp/os_netvirt_client_rc << EOF
1267 export OS_USERNAME=admin
1268 export OS_PASSWORD=admin
1269 export OS_PROJECT_NAME=admin
1270 export OS_USER_DOMAIN_NAME=default
1271 export OS_PROJECT_DOMAIN_NAME=default
1272 export OS_AUTH_URL="http://${!CONTROLIP}/identity"
1273 export OS_IDENTITY_API_VERSION=3
1274 export OS_IMAGE_API_VERSION=2
1275 export OS_TENANT_NAME=admin
1276 unset OS_CLOUD
1277 EOF
1278
1279 source /tmp/os_netvirt_client_rc
1280
1281 echo "Get all versions before executing pybot"
1282 echo "openstack --version"
1283 which openstack
1284 openstack --version
1285 echo "nova --version"
1286 which nova
1287 nova --version
1288 echo "neutron --version"
1289 which neutron
1290 neutron --version
1291
1292 echo "Starting Robot test suites ${SUITES} ..."
1293 # please add pybot -v arguments on a single line and alphabetized
1294 suite_num=0
1295 for suite in ${SUITES}; do
1296     # prepend an incremental counter to the suite name so that the full robot log combining all the suites as is done
1297     # in the rebot step below will list all the suites in chronological order as rebot seems to alphabetize them
1298     let "suite_num = suite_num + 1"
1299     suite_index="$(printf %02d ${suite_num})"
1300     suite_name="$(basename ${suite} | cut -d. -f1)"
1301     log_name="${suite_index}_${suite_name}"
1302     pybot -N ${log_name} \
1303     -c critical -e exclude -e skip_if_${DISTROSTREAM} \
1304     --log log_${log_name}.html --report None --output output_${log_name}.xml \
1305     --removekeywords wuks \
1306     --removekeywords name:SetupUtils.Setup_Utils_For_Setup_And_Teardown \
1307     --removekeywords name:SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing \
1308     --removekeywords name:OpenStackOperations.Add_OVS_Logging_On_All_OpenStack_Nodes \
1309     -v BUNDLEFOLDER:${BUNDLEFOLDER} \
1310     -v BUNDLE_URL:${ACTUAL_BUNDLE_URL} \
1311     -v CONTROLLERFEATURES:"${CONTROLLERFEATURES}" \
1312     -v CONTROLLER_USER:${USER} \
1313     -v DEVSTACK_DEPLOY_PATH:/opt/stack/devstack \
1314     -v HA_PROXY_IP:${HA_PROXY_IP} \
1315     -v HA_PROXY_1_IP:${HA_PROXY_1_IP} \
1316     -v HA_PROXY_2_IP:${HA_PROXY_2_IP} \
1317     -v HA_PROXY_3_IP:${HA_PROXY_3_IP} \
1318     -v JDKVERSION:${JDKVERSION} \
1319     -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
1320     -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} \
1321     -v NUM_OPENSTACK_SITES:${NUM_OPENSTACK_SITES} \
1322     -v NUM_OS_SYSTEM:${NUM_OPENSTACK_SYSTEM} \
1323     -v NUM_TOOLS_SYSTEM:${NUM_TOOLS_SYSTEM} \
1324     -v ODL_SNAT_MODE:${ODL_SNAT_MODE} \
1325     -v ODL_ENABLE_L3_FWD:${ODL_ENABLE_L3_FWD} \
1326     -v ODL_STREAM:${DISTROSTREAM} \
1327     -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} \
1328     -v ODL_SYSTEM_1_IP:${ODL_SYSTEM_1_IP} \
1329     -v ODL_SYSTEM_2_IP:${ODL_SYSTEM_2_IP} \
1330     -v ODL_SYSTEM_3_IP:${ODL_SYSTEM_3_IP} \
1331     -v ODL_SYSTEM_4_IP:${ODL_SYSTEM_4_IP} \
1332     -v ODL_SYSTEM_5_IP:${ODL_SYSTEM_5_IP} \
1333     -v ODL_SYSTEM_6_IP:${ODL_SYSTEM_6_IP} \
1334     -v ODL_SYSTEM_7_IP:${ODL_SYSTEM_7_IP} \
1335     -v ODL_SYSTEM_8_IP:${ODL_SYSTEM_8_IP} \
1336     -v ODL_SYSTEM_9_IP:${ODL_SYSTEM_9_IP} \
1337     -v OS_CONTROL_NODE_IP:${OPENSTACK_CONTROL_NODE_1_IP} \
1338     -v OS_CONTROL_NODE_1_IP:${OPENSTACK_CONTROL_NODE_1_IP} \
1339     -v OS_CONTROL_NODE_2_IP:${OPENSTACK_CONTROL_NODE_2_IP} \
1340     -v OS_CONTROL_NODE_3_IP:${OPENSTACK_CONTROL_NODE_3_IP} \
1341     -v OPENSTACK_BRANCH:${OPENSTACK_BRANCH} \
1342     -v OS_COMPUTE_1_IP:${OPENSTACK_COMPUTE_NODE_1_IP} \
1343     -v OS_COMPUTE_2_IP:${OPENSTACK_COMPUTE_NODE_2_IP} \
1344     -v OS_COMPUTE_3_IP:${OPENSTACK_COMPUTE_NODE_3_IP} \
1345     -v OS_COMPUTE_4_IP:${OPENSTACK_COMPUTE_NODE_4_IP} \
1346     -v OS_COMPUTE_5_IP:${OPENSTACK_COMPUTE_NODE_5_IP} \
1347     -v OS_COMPUTE_6_IP:${OPENSTACK_COMPUTE_NODE_6_IP} \
1348     -v OS_USER:${USER} \
1349     -v PUBLIC_PHYSICAL_NETWORK:${PUBLIC_PHYSICAL_NETWORK} \
1350     -v SECURITY_GROUP_MODE:${SECURITY_GROUP_MODE} \
1351     -v TOOLS_SYSTEM_IP:${TOOLS_SYSTEM_1_IP} \
1352     -v TOOLS_SYSTEM_1_IP:${TOOLS_SYSTEM_1_IP} \
1353     -v TOOLS_SYSTEM_2_IP:${TOOLS_SYSTEM_2_IP} \
1354     -v USER_HOME:${HOME} \
1355     -v WORKSPACE:/tmp \
1356     ${TESTOPTIONS} ${suite} || true
1357 done
1358 #rebot exit codes seem to be different
1359 rebot --output ${WORKSPACE}/output.xml --log log_full.html --report None -N openstack output_*.xml || true
1360
1361 echo "Examining the files in data/log and checking file size"
1362 ssh ${ODL_SYSTEM_IP} "ls -altr /tmp/${BUNDLEFOLDER}/data/log/"
1363 ssh ${ODL_SYSTEM_IP} "du -hs /tmp/${BUNDLEFOLDER}/data/log/*"
1364
1365 echo "Tests Executed"
1366 collect_logs
1367
1368 true  # perhaps Jenkins is testing last exit code
1369 # vim: ts=4 sw=4 sts=4 et ft=sh :