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