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