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