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