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