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