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