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