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