Merge "Do not print stack list"
[releng/builder.git] / jjb / integration / include-raw-integration-deploy-openstack-run-test.sh
1 #@IgnoreInspection BashAddShebang
2 # Activate robotframework virtualenv
3 # ${ROBOT_VENV} comes from the include-raw-integration-install-robotframework.sh
4 # script.
5 source ${ROBOT_VENV}/bin/activate
6
7 # TODO: remove this work to run changes.py if/when it's moved higher up to be visible at the Robot level
8 echo "showing recent changes that made it in to the distribution used by this job"
9 pip install --upgrade urllib3
10 python ${WORKSPACE}/test/tools/distchanges/changes.py -d /tmp/distribution_folder \
11                   -u ${ACTUALBUNDLEURL} -b ${DISTROBRANCH} \
12                   -r ssh://jenkins-${SILO}@git.opendaylight.org:29418 || true
13
14 echo "#################################################"
15 echo "##         Deploy Openstack 3-node             ##"
16 echo "#################################################"
17
18
19 SSH="ssh -t -t"
20
21 function create_control_node_local_conf {
22 HOSTIP=$1
23 MGRIP=$2
24 ODL_OVS_MANAGERS="$3"
25 #Needs to be removed
26 if [ "${ODL_ML2_BRANCH}" != "stable/ocata" ]; then
27    RECLONE=no
28 else
29    RECLONE=yes
30 fi
31 local_conf_file_name=${WORKSPACE}/local.conf_control_${HOSTIP}
32 cat > ${local_conf_file_name} << EOF
33 [[local|localrc]]
34 LOGFILE=stack.sh.log
35 SCREEN_LOGDIR=/opt/stack/data/log
36 LOG_COLOR=False
37 RECLONE=${RECLONE}
38 EOF
39
40 IFS=,
41 for service_name in ${DISABLE_OS_SERVICES}
42 do
43 cat >> ${local_conf_file_name} << EOF
44 disable_service ${service_name}
45 EOF
46 done
47 for service_name in ${ENABLE_OS_SERVICES}
48 do
49 cat >> ${local_conf_file_name} << EOF
50 enable_service ${service_name}
51 EOF
52 done
53 for plugin_name in ${ENABLE_OS_PLUGINS}
54 do
55 if [ "$plugin_name" == "networking-odl" ]; then
56     ENABLE_PLUGIN_ARGS="${ODL_ML2_DRIVER_REPO} ${ODL_ML2_BRANCH}"
57 elif [ "$plugin_name" == "kuryr-kubernetes" ]; then
58     ENABLE_PLUGIN_ARGS="${DEVSTACK_KUBERNETES_PLUGIN_REPO} master" # note: kuryr-kubernetes only exists in master at the moment
59 elif [ "$plugin_name" == "neutron-lbaas" ]; then
60     ENABLE_PLUGIN_ARGS="${DEVSTACK_LBAAS_PLUGIN_REPO} ${OPENSTACK_BRANCH}"
61 else
62     echo "Error: Invalid plugin $plugin_name, unsupported"
63     continue
64 fi
65 cat >> ${local_conf_file_name} << EOF
66 enable_plugin ${plugin_name} ${ENABLE_PLUGIN_ARGS}
67 EOF
68 done
69 unset IFS
70 if [ "${OPENSTACK_BRANCH}" == "master" ] || [ "${OPENSTACK_BRANCH}" == "stable/ocata" ]; then # Ocata+
71     # placement is mandatory for nova since Ocata, note that this requires computes to enable placement-client
72     # this should be moved into enabled_services for each job (but only for Ocata)
73     echo "enable_service placement-api" >> ${local_conf_file_name}
74 fi
75 cat >> ${local_conf_file_name} << EOF
76 HOST_IP=${HOSTIP}
77 SERVICE_HOST=\$HOST_IP
78
79 NEUTRON_CREATE_INITIAL_NETWORKS=${CREATE_INITIAL_NETWORKS}
80 Q_PLUGIN=ml2
81 Q_ML2_TENANT_NETWORK_TYPE=${TENANT_NETWORK_TYPE}
82 Q_OVS_USE_VETH=True
83
84 ENABLE_TENANT_TUNNELS=True
85
86 MYSQL_HOST=\$SERVICE_HOST
87 RABBIT_HOST=\$SERVICE_HOST
88 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
89 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
90 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
91
92 MYSQL_PASSWORD=mysql
93 RABBIT_PASSWORD=rabbit
94 SERVICE_TOKEN=service
95 SERVICE_PASSWORD=admin
96 ADMIN_PASSWORD=admin
97
98 ODL_PORT=8080
99 ODL_MODE=externalodl
100 ODL_PORT_BINDING_CONTROLLER=${ODL_ML2_PORT_BINDING}
101
102 LIBVIRT_TYPE=qemu
103 ODL_MGR_IP=${MGRIP}
104
105 NEUTRON_LBAAS_SERVICE_PROVIDERV2=${LBAAS_SERVICE_PROVIDER} # Only relevant if neutron-lbaas plugin is enabled
106 EOF
107
108 if [ "${ENABLE_NETWORKING_L2GW}" == "yes" ]; then
109 cat >> ${local_conf_file_name} << EOF
110
111 enable_plugin networking-l2gw ${NETWORKING_L2GW_DRIVER} ${ODL_ML2_BRANCH}
112 NETWORKING_L2GW_SERVICE_DRIVER=L2GW:OpenDaylight:networking_odl.l2gateway.driver.OpenDaylightL2gwDriver:default
113 ENABLED_SERVICES+=,neutron,q-svc,nova,q-meta
114
115 EOF
116 fi
117
118 if [ "${ODL_ML2_DRIVER_VERSION}" == "v2" ]; then
119     echo "ODL_V2DRIVER=True" >> ${local_conf_file_name}
120 fi
121
122 echo "ODL_OVS_MANAGERS=${ODL_OVS_MANAGERS}" >> ${local_conf_file_name}
123
124 # if we are using the old netvirt impl, as determined by the feature name
125 # odl-ovsdb-openstack (note: new impl is odl-netvirt-openstack) then we
126 # want ODL_L3 to be True.  New impl wants it False
127 if [[ ${CONTROLLERFEATURES} == *"odl-ovsdb-openstack"* ]]; then
128     ODL_L3=True
129 else
130     ODL_L3=False
131 fi
132
133 # if we are using the new netvirt impl, as determined by the feature name
134 # odl-netvirt-openstack (note: old impl is odl-ovsdb-openstack) then we
135 # want PROVIDER_MAPPINGS to be used -- this should be fixed if we want to support
136 # external networks in legacy netvirt
137 if [[ ${CONTROLLERFEATURES} == *"odl-netvirt-openstack"* ]]; then
138   ODL_PROVIDER_MAPPINGS="\${PUBLIC_PHYSICAL_NETWORK}:${PUBLIC_BRIDGE}"
139 else
140   ODL_PROVIDER_MAPPINGS=
141 fi
142
143 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
144 cat >> ${local_conf_file_name} << EOF
145 PUBLIC_BRIDGE=${PUBLIC_BRIDGE}
146 PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK}
147 ML2_VLAN_RANGES=${PUBLIC_PHYSICAL_NETWORK}
148 ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS}
149
150 disable_service q-l3
151 PUBLIC_INTERFACE=br100
152 EOF
153
154 if [ -z ${DISABLE_ODL_L3_PLUGIN} ] || [ "${DISABLE_ODL_L3_PLUGIN}" == "no" ]; then
155 if [ "${ODL_ML2_BRANCH}" == "stable/mitaka" ]; then
156 cat >> ${local_conf_file_name} << EOF
157 Q_L3_ENABLED=True
158 ODL_L3=${ODL_L3}
159 [[post-config|\$NEUTRON_CONF]]
160 [DEFAULT]
161 service_plugins = networking_odl.l3.l3_odl.OpenDaylightL3RouterPlugin
162
163 EOF
164 fi #check for ODL_ML2_BRANCH
165 fi #check for DISABLE_ODL_L3_PLUGIN
166
167 fi #ODL_ENABLE_L3_FWD check
168
169 cat >> ${local_conf_file_name} << EOF
170 [[post-config|/etc/neutron/plugins/ml2/ml2_conf.ini]]
171 [agent]
172 minimize_polling=True
173
174 [ml2]
175 # Needed for VLAN provider tests - because our provider networks are always encapsulated in VXLAN (br-phys1)
176 # MTU(1440) + VXLAN(50) + VLAN(4) = 1494 < MTU eth0/br-phys1(1500)
177 physical_network_mtus = ${PUBLIC_PHYSICAL_NETWORK}:1440
178 path_mtu = 1490
179
180 [[post-config|/etc/neutron/dhcp_agent.ini]]
181 [DEFAULT]
182 force_metadata = True
183 enable_isolated_metadata = True
184
185 [[post-config|/etc/nova/nova.conf]]
186 [DEFAULT]
187 force_config_drive = False
188
189 EOF
190
191 echo "local.conf Created...."
192 cat ${local_conf_file_name}
193 }
194
195 function create_compute_node_local_conf {
196 HOSTIP=$1
197 SERVICEHOST=$2
198 MGRIP=$3
199 ODL_OVS_MANAGERS="$4"
200 #Needs to be removed
201 if [ "${ODL_ML2_BRANCH}" != "stable/ocata" ]; then
202    RECLONE=no
203 else
204    RECLONE=yes
205 fi
206 if [ "${OPENSTACK_BRANCH}" == "master" ] || [ "${OPENSTACK_BRANCH}" == "stable/ocata" ]; then # Ocata+
207     # placement is mandatory for nova since Ocata, note that this requires controller to enable placement-api
208     ENABLED_SERVICES="n-cpu,placement-client"
209 else
210     ENABLED_SERVICES="n-cpu"
211 fi
212
213 local_conf_file_name=${WORKSPACE}/local.conf_compute_${HOSTIP}
214 cat > ${local_conf_file_name} << EOF
215 [[local|localrc]]
216 LOGFILE=stack.sh.log
217 LOG_COLOR=False
218 SCREEN_LOGDIR=/opt/stack/data/log
219 RECLONE=${RECLONE}
220
221 NOVA_VNC_ENABLED=True
222 MULTI_HOST=1
223 ENABLED_SERVICES=${ENABLED_SERVICES}
224 HOST_IP=${HOSTIP}
225 SERVICE_HOST=${SERVICEHOST}
226
227 Q_PLUGIN=ml2
228 ENABLE_TENANT_TUNNELS=True
229 Q_ML2_TENANT_NETWORK_TYPE=vxlan
230
231 Q_HOST=\$SERVICE_HOST
232 MYSQL_HOST=\$SERVICE_HOST
233 RABBIT_HOST=\$SERVICE_HOST
234 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
235 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
236 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
237
238 MYSQL_PASSWORD=mysql
239 RABBIT_PASSWORD=rabbit
240 SERVICE_TOKEN=service
241 SERVICE_PASSWORD=admin
242 ADMIN_PASSWORD=admin
243
244 ODL_MODE=compute
245 ODL_PORT_BINDING_CONTROLLER=${ODL_ML2_PORT_BINDING}
246 LIBVIRT_TYPE=qemu
247 ODL_MGR_IP=${MGRIP}
248 EOF
249
250 if [[ "${ENABLE_OS_PLUGINS}" =~ networking-odl ]]; then
251 cat >> ${local_conf_file_name} << EOF
252 enable_plugin networking-odl ${ODL_ML2_DRIVER_REPO} ${ODL_ML2_BRANCH}
253 EOF
254 fi
255
256 echo "ODL_OVS_MANAGERS=${ODL_OVS_MANAGERS}" >> ${local_conf_file_name}
257
258 # if we are using the new netvirt impl, as determined by the feature name
259 # odl-netvirt-openstack (note: old impl is odl-ovsdb-openstack) then we
260 # want PROVIDER_MAPPINGS to be used -- this should be fixed if we want to support
261 # external networks in legacy netvirt
262 if [[ ${CONTROLLERFEATURES} == *"odl-netvirt-openstack"* ]]; then
263   ODL_PROVIDER_MAPPINGS="\${PUBLIC_PHYSICAL_NETWORK}:${PUBLIC_BRIDGE}"
264 else
265   ODL_PROVIDER_MAPPINGS=
266 fi
267
268 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
269 cat >> ${local_conf_file_name} << EOF
270 # Uncomment lines below if odl-compute is to be used for l3 forwarding
271 Q_L3_ENABLED=True
272 ODL_L3=${ODL_L3}
273 PUBLIC_INTERFACE=br100 # FIXME do we use br100 at all?
274 PUBLIC_BRIDGE=${PUBLIC_BRIDGE}
275 PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK}
276 ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS}
277 EOF
278 fi
279 echo "local.conf Created...."
280 cat ${local_conf_file_name}
281 }
282
283 function configure_haproxy_for_neutron_requests () {
284 MGRIP=$1
285 ODL_IPS=(${2//,/ })
286
287 cat > ${WORKSPACE}/install_ha_proxy.sh<< EOF
288 sudo systemctl stop firewalld
289 sudo yum -y install policycoreutils-python haproxy
290 EOF
291
292 cat > ${WORKSPACE}/haproxy.cfg << EOF
293 global
294   daemon
295   group  haproxy
296   log  /dev/log local0
297   maxconn  20480
298   pidfile  /tmp/haproxy.pid
299   user  haproxy
300
301 defaults
302   log  global
303   maxconn  4096
304   mode  tcp
305   retries  3
306   timeout  http-request 10s
307   timeout  queue 1m
308   timeout  connect 10s
309   timeout  client 1m
310   timeout  server 1m
311   timeout  check 10s
312
313 listen opendaylight
314   bind ${MGRIP}:8080
315   balance source
316 EOF
317
318 odlindex=1
319 for odlip in ${ODL_IPS[*]}
320 do
321 cat >> ${WORKSPACE}/haproxy.cfg << EOF
322   server controller-${odlindex} ${odlip}:8080 check fall 5 inter 2000 rise 2
323 EOF
324 odlindex=$((odlindex+1))
325 done
326
327 cat >> ${WORKSPACE}/haproxy.cfg << EOF
328 listen opendaylight_rest
329   bind ${MGRIP}:8181
330   balance source
331 EOF
332
333 odlindex=1
334 for odlip in ${ODL_IPS[*]}
335 do
336 cat >> ${WORKSPACE}/haproxy.cfg << EOF
337   server controller-rest-${odlindex} ${odlip}:8181 check fall 5 inter 2000 rise 2
338 EOF
339 odlindex=$((odlindex+1))
340 done
341
342 echo "Dump haproxy.cfg"
343 cat ${WORKSPACE}/haproxy.cfg
344
345 cat > ${WORKSPACE}/deploy_ha_proxy.sh<< EOF
346 sudo chown haproxy:haproxy /tmp/haproxy.cfg
347 sudo sed -i 's/\\/etc\\/haproxy\\/haproxy.cfg/\\/tmp\\/haproxy.cfg/g' /usr/lib/systemd/system/haproxy.service
348 sudo /usr/sbin/semanage permissive -a haproxy_t
349 sudo systemctl restart haproxy
350 sleep 3
351 sudo netstat -tunpl
352 sudo systemctl status haproxy
353 true
354 EOF
355 scp ${WORKSPACE}/install_ha_proxy.sh ${MGRIP}:/tmp
356 ${SSH} ${MGRIP} "sudo bash /tmp/install_ha_proxy.sh"
357 scp ${WORKSPACE}/haproxy.cfg ${MGRIP}:/tmp
358 scp ${WORKSPACE}/deploy_ha_proxy.sh ${MGRIP}:/tmp
359 ${SSH} ${MGRIP} "sudo bash /tmp/deploy_ha_proxy.sh"
360 }
361
362 function collect_logs_and_exit () {
363 set +e  # We do not want to create red dot just because something went wrong while fetching logs.
364 for i in `seq 1 ${NUM_ODL_SYSTEM}`
365 do
366     CONTROLLERIP=ODL_SYSTEM_${i}_IP
367     echo "killing karaf process..."
368     ${SSH} "${!CONTROLLERIP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
369 done
370
371 cat > extra_debug.sh << EOF
372 echo -e "/usr/sbin/lsmod | /usr/bin/grep openvswitch\n"
373 /usr/sbin/lsmod | /usr/bin/grep openvswitch
374 echo -e "\ngrep ct_ /var/log/openvswitch/ovs-vswitchd.log\n"
375 grep ct_ /var/log/openvswitch/ovs-vswitchd.log
376 EOF
377
378 sleep 5
379 # FIXME: Do not create .tar and gzip before copying.
380 for i in `seq 1 ${NUM_ODL_SYSTEM}`
381 do
382     CONTROLLERIP=ODL_SYSTEM_${i}_IP
383     ${SSH} "${!CONTROLLERIP}"  "cp -r /tmp/${BUNDLEFOLDER}/data/log /tmp/odl_log"
384     ${SSH} "${!CONTROLLERIP}"  "tar -cf /tmp/odl${i}_karaf.log.tar /tmp/odl_log/*"
385     scp "${!CONTROLLERIP}:/tmp/odl${i}_karaf.log.tar" "${WORKSPACE}/odl${i}_karaf.log.tar"
386     tar -xvf ${WORKSPACE}/odl${i}_karaf.log.tar -C . --strip-components 2 --transform s/karaf/odl${i}_karaf/g
387     grep "ROBOT MESSAGE\| ERROR " odl${i}_karaf.log > odl${i}_err.log
388     grep "ROBOT MESSAGE\|Exception" odl${i}_karaf.log > odl${i}_exception.log
389     grep "ROBOT MESSAGE\| ERROR \| WARN \|Exception" odl${i}_karaf.log > odl${i}_err_warn_exception.log
390     rm ${WORKSPACE}/odl${i}_karaf.log.tar
391 done
392
393 # Since this log collection work is happening before the archive build macro which also
394 # creates the ${WORKSPACE}/archives dir, we have to do it here first.  The mkdir in the
395 # archives build step will essentially be a noop.
396 mkdir -p ${WORKSPACE}/archives
397
398 # Control Node
399 for i in `seq 1 ${NUM_OPENSTACK_CONTROL_NODES}`
400 do
401     OS_CTRL_IP=OPENSTACK_CONTROL_NODE_${i}_IP
402     OS_CTRL_FOLDER="control_${i}"
403     mkdir -p ${OS_CTRL_FOLDER}
404     scp ${!OS_CTRL_IP}:/opt/stack/devstack/nohup.out ${OS_CTRL_FOLDER}/stack.log
405     scp ${!OS_CTRL_IP}:/var/log/openvswitch/ovs-vswitchd.log ${OS_CTRL_FOLDER}/ovs-vswitchd.log
406     scp ${!OS_CTRL_IP}:/etc/neutron/neutron.conf ${OS_CTRL_FOLDER}/neutron.conf
407     scp ${!OS_CTRL_IP}:/etc/nova/nova.conf ${OS_CTRL_FOLDER}/nova.conf
408     rsync -avhe ssh ${!OS_CTRL_IP}:/opt/stack/logs/* ${OS_CTRL_FOLDER} # rsync to prevent copying of symbolic links
409     scp extra_debug.sh ${!OS_CTRL_IP}:/tmp
410     ${SSH} ${!OS_CTRL_IP} "bash /tmp/extra_debug.sh > /tmp/extra_debug.log"
411     scp ${!OS_CTRL_IP}:/tmp/extra_debug.log ${OS_CTRL_FOLDER}/extra_debug.log
412     scp ${!OS_CTRL_IP}:/opt/stack/devstack/local.conf ${OS_CTRL_FOLDER}/local.conf
413     mv ${OS_CTRL_FOLDER} ${WORKSPACE}/archives/
414 done
415
416 # Compute Nodes
417 for i in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`
418 do
419     OSIP=OPENSTACK_COMPUTE_NODE_${i}_IP
420     OS_COMPUTE_FOLDER="compute_${i}"
421     mkdir -p ${OS_COMPUTE_FOLDER}
422     scp ${!OSIP}:/opt/stack/devstack/nohup.out ${OS_COMPUTE_FOLDER}/stack.log
423     scp ${!OSIP}:/var/log/openvswitch/ovs-vswitchd.log ${OS_COMPUTE_FOLDER}/ovs-vswitchd.log
424     scp ${!OSIP}:/etc/nova/nova.conf ${OS_COMPUTE_FOLDER}/nova.conf
425     rsync -avhe ssh ${!OSIP}:/opt/stack/logs/* ${OS_COMPUTE_FOLDER} # rsync to prevent copying of symbolic links
426     scp extra_debug.sh ${!OSIP}:/tmp
427     ${SSH} ${!OSIP} "bash /tmp/extra_debug.sh > /tmp/extra_debug.log"
428     scp ${!OSIP}:/tmp/extra_debug.log ${OS_COMPUTE_FOLDER}/extra_debug.log
429     mv local.conf_compute_${!OSIP} ${OS_COMPUTE_FOLDER}/local.conf
430     mv ${OS_COMPUTE_FOLDER} ${WORKSPACE}/archives/
431 done
432
433 ls local.conf* | xargs -I % mv % %.log
434
435 # Tempest
436 DEVSTACK_TEMPEST_DIR="/opt/stack/tempest"
437 if $(ssh ${OPENSTACK_CONTROL_NODE_1_IP} "sudo sh -c '[ -f ${DEVSTACK_TEMPEST_DIR}/.testrepository/0 ]'"); then # if Tempest results exist
438     ssh ${OPENSTACK_CONTROL_NODE_1_IP} "for I in \$(sudo ls ${DEVSTACK_TEMPEST_DIR}/.testrepository/ | grep -E '^[0-9]+$'); do sudo sh -c \"${DEVSTACK_TEMPEST_DIR}/.tox/tempest/bin/subunit-1to2 < ${DEVSTACK_TEMPEST_DIR}/.testrepository/\${I} >> ${DEVSTACK_TEMPEST_DIR}/subunit_log.txt\"; done"
439     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'"
440     TEMPEST_LOGS_DIR=${WORKSPACE}/archives/tempest
441     mkdir -p ${TEMPEST_LOGS_DIR}
442     scp ${OPENSTACK_CONTROL_NODE_1_IP}:${DEVSTACK_TEMPEST_DIR}/tempest_results.html ${TEMPEST_LOGS_DIR}
443     scp ${OPENSTACK_CONTROL_NODE_1_IP}:${DEVSTACK_TEMPEST_DIR}/tempest.log ${TEMPEST_LOGS_DIR}
444     mv ${WORKSPACE}/tempest_output* ${TEMPEST_LOGS_DIR}
445 fi
446 }
447
448 cat > ${WORKSPACE}/disable_firewall.sh << EOF
449 sudo systemctl stop firewalld
450 sudo systemctl stop iptables
451 true
452 EOF
453
454 cat > ${WORKSPACE}/get_devstack.sh << EOF
455 sudo systemctl stop firewalld
456 sudo yum install bridge-utils -y
457 sudo systemctl stop  NetworkManager
458 #Disable NetworkManager and kill dhclient and dnsmasq
459 sudo systemctl stop NetworkManager
460 sudo killall dhclient
461 sudo killall dnsmasq
462 #Workaround for mysql failure
463 echo "127.0.0.1    localhost \${HOSTNAME}" > /tmp/hosts
464 echo "::1   localhost  \${HOSTNAME}" >> /tmp/hosts
465 sudo mv /tmp/hosts /etc/hosts
466 sudo /usr/sbin/brctl addbr br100
467 #sudo ifconfig eth0 mtu 2000
468 sudo mkdir /opt/stack
469 sudo chmod 777 /opt/stack
470 cd /opt/stack
471 git clone https://git.openstack.org/openstack-dev/devstack
472 cd devstack
473 git checkout $OPENSTACK_BRANCH
474 EOF
475
476 [ "$NUM_OPENSTACK_SITES" ] || NUM_OPENSTACK_SITES=1
477 compute_index=1
478 odl_index=1
479 os_node_list=()
480 os_interval=$(( ${NUM_OPENSTACK_SYSTEM} / ${NUM_OPENSTACK_SITES} ))
481 ha_proxy_index=${os_interval}
482
483 cat > "${WORKSPACE}/manual_install_package.sh" << EOF
484 cd /opt/stack
485 git clone "\$1"
486 cd "\$2"
487 git checkout "\$3"
488 sudo python setup.py install
489 EOF
490
491 for i in `seq 1 ${NUM_OPENSTACK_SITES}`
492 do
493     if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
494         echo "Configure HAProxy"
495         ODL_HAPROXYIP_PARAM=OPENSTACK_HAPROXY_${i}_IP
496         ha_proxy_index=$(( $ha_proxy_index + $os_interval ))
497         odl_index=$(((i - 1) * 3 + 1))
498         ODL_IP_PARAM1=ODL_SYSTEM_$((odl_index++))_IP
499         ODL_IP_PARAM2=ODL_SYSTEM_$((odl_index++))_IP
500         ODL_IP_PARAM3=ODL_SYSTEM_$((odl_index++))_IP
501         ODLMGRIP[$i]=${!ODL_HAPROXYIP_PARAM} # ODL Northbound uses HAProxy VIP
502         ODL_OVS_MGRS[$i]="${!ODL_IP_PARAM1},${!ODL_IP_PARAM2},${!ODL_IP_PARAM3}" # OVSDB connects to all ODL IPs
503
504         configure_haproxy_for_neutron_requests ${!ODL_HAPROXYIP_PARAM} "${ODL_OVS_MGRS[$i]}"
505     else
506         ODL_IP_PARAM=ODL_SYSTEM_${i}_IP
507         ODL_OVS_MGRS[$i]="${!ODL_IP_PARAM}" # ODL Northbound uses ODL IP
508         ODLMGRIP[$i]=${!ODL_IP_PARAM} # OVSDB connects to ODL IP
509     fi
510 done
511
512 for i in `seq 1 ${NUM_OPENSTACK_CONTROL_NODES}`
513 do
514     echo "Stack the Control Node"
515     CONTROLIP=OPENSTACK_CONTROL_NODE_${i}_IP
516     scp ${WORKSPACE}/get_devstack.sh ${!CONTROLIP}:/tmp
517     ${SSH} ${!CONTROLIP} "bash /tmp/get_devstack.sh"
518     create_control_node_local_conf ${!CONTROLIP} ${ODLMGRIP[$i]} "${ODL_OVS_MGRS[$i]}"
519     scp ${WORKSPACE}/local.conf_control_${!CONTROLIP} ${!CONTROLIP}:/opt/stack/devstack/local.conf
520     if [ "${ODL_ML2_BRANCH}" == "stable/mitaka" ]; then
521         # Workaround for problems with latest versions/specified versions in requirements of openstack
522         # Openstacksdk,libvirt-python -> the current version does not work with  Mitaka diue to some requirements
523         # conflict and breaks when trying to stack
524         # paramiko -> Problems with tempest tests due to paramiko incompatibility with pycrypto.
525         # the problem has been solved with  version 1.17. If the latest version of paramiko is used, it causes
526         # other timeout problems
527         ssh ${!CONTROLIP} "cd /opt/stack; git clone https://git.openstack.org/openstack/requirements; cd requirements; git checkout stable/mitaka; sed -i /openstacksdk/d upper-constraints.txt; sed -i /libvirt-python/d upper-constraints.txt; sed -i /paramiko/d upper-constraints.txt"
528         scp "${WORKSPACE}/manual_install_package.sh"  "${!CONTROLIP}:/tmp"
529         ssh ${!CONTROLIP} "sudo pip install deprecation"
530         # Fix for recent requirements update  in the  master branch of the sdk.The section must be replaced with a better fix.
531         ssh "${!CONTROLIP}" "sh /tmp/manual_install_package.sh https://github.com/openstack/python-openstacksdk python-openstacksdk 0.9.14"
532         ssh "${!CONTROLIP}" "sh /tmp/manual_install_package.sh https://github.com/paramiko/paramiko paramiko 1.17"
533     fi
534     ssh ${!CONTROLIP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
535     ssh ${!CONTROLIP} "ps -ef | grep stack.sh"
536     ssh ${!CONTROLIP} "ls -lrt /opt/stack/devstack/nohup.out"
537     os_node_list+=(${!CONTROLIP})
538
539     #Workaround for stable/newton jobs
540     if [ "${ODL_ML2_BRANCH}" == "stable/newton" ]; then
541         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"
542     fi
543 done
544
545 for i in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`
546 do
547     echo "Stack the Compute Node"
548     NUM_COMPUTES_PER_SITE=$((NUM_OPENSTACK_COMPUTE_NODES / NUM_OPENSTACK_SITES))
549     SITE_INDEX=$((((i - 1) / NUM_COMPUTES_PER_SITE) + 1)) # We need the site index to infer the control node IP for this compute
550     COMPUTEIP=OPENSTACK_COMPUTE_NODE_${i}_IP
551     CONTROLIP=OPENSTACK_CONTROL_NODE_${SITE_INDEX}_IP
552     scp ${WORKSPACE}/get_devstack.sh  ${!COMPUTEIP}:/tmp
553     ${SSH} ${!COMPUTEIP} "bash /tmp/get_devstack.sh"
554     create_compute_node_local_conf ${!COMPUTEIP} ${!CONTROLIP} ${ODLMGRIP[$SITE_INDEX]} "${ODL_OVS_MGRS[$SITE_INDEX]}"
555     scp ${WORKSPACE}/local.conf_compute_${!COMPUTEIP} ${!COMPUTEIP}:/opt/stack/devstack/local.conf
556     if [ "${ODL_ML2_BRANCH}" == "stable/mitaka" ]; then
557         ssh ${!COMPUTEIP} "cd /opt/stack; git clone https://git.openstack.org/openstack/requirements; cd requirements; git checkout stable/mitaka; sed -i /libvirt-python/d upper-constraints.txt"
558     fi
559     ssh ${!COMPUTEIP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
560     ssh ${!COMPUTEIP} "ps -ef | grep stack.sh"
561     os_node_list+=(${!COMPUTEIP})
562 done
563
564 echo ${os_node_list[*]}
565
566 cat > ${WORKSPACE}/check_stacking.sh << EOF
567 > /tmp/stack_progress
568 ps -ef | grep "stack.sh" | grep -v grep
569 ret=\$?
570 if [ \${ret} -eq 1 ]; then
571   grep "This is your host IP address:" /opt/stack/devstack/nohup.out
572   if [ \$? -eq 0 ]; then
573      echo "Stacking Complete" > /tmp/stack_progress
574   else
575      echo "Stacking Failed" > /tmp/stack_progress
576   fi
577 elif [ \${ret} -eq 0 ]; then
578   echo "Still Stacking" > /tmp/stack_progress
579 fi
580 EOF
581
582 #the checking is repeated for an hour
583 iteration=0
584 in_progress=1
585 while [ ${in_progress} -eq 1 ]; do
586 iteration=$(($iteration + 1))
587 for index in ${!os_node_list[@]}
588 do
589 echo "Check the status of stacking in ${os_node_list[index]}"
590 scp ${WORKSPACE}/check_stacking.sh  ${os_node_list[index]}:/tmp
591 ${SSH} ${os_node_list[index]} "bash /tmp/check_stacking.sh"
592 scp ${os_node_list[index]}:/tmp/stack_progress .
593 #debug
594 cat stack_progress
595 stacking_status=`cat stack_progress`
596 if [ "$stacking_status" == "Still Stacking" ]; then
597   continue
598 elif [ "$stacking_status" == "Stacking Failed" ]; then
599   collect_logs_and_exit
600   exit 1
601 elif [ "$stacking_status" == "Stacking Complete" ]; then
602   unset os_node_list[index]
603   if  [ ${#os_node_list[@]} -eq 0 ]; then
604      in_progress=0
605   fi
606 fi
607 done
608  echo "sleep for a minute before the next check"
609  sleep 60
610  if [ ${iteration} -eq 60 ]; then
611   collect_logs_and_exit
612   exit 1
613  fi
614 done
615
616 NUM_COMPUTES_PER_SITE=$((NUM_OPENSTACK_COMPUTE_NODES / NUM_OPENSTACK_SITES))
617 for i in `seq 1 ${NUM_OPENSTACK_SITES}`
618 do
619     echo "Configure the Control Node"
620     CONTROLIP=OPENSTACK_CONTROL_NODE_${i}_IP
621
622     #Need to disable firewalld and iptables in control node
623     echo "Stop Firewall in Control Node for compute nodes to be able to reach the ports and add to hypervisor-list"
624     scp ${WORKSPACE}/disable_firewall.sh ${!CONTROLIP}:/tmp
625     ${SSH} ${!CONTROLIP} "sudo bash /tmp/disable_firewall.sh"
626
627     echo "sleep for 60s and print hypervisor-list"
628     sleep 60
629     ${SSH} ${!CONTROLIP} "cd /opt/stack/devstack; source openrc admin admin; nova hypervisor-list"
630     # in the case that we are doing openstack (control + compute) all in one node, then the number of hypervisors
631     # will be the same as the number of openstack systems. However, if we are doing multinode openstack then the
632     # assumption is we have a single control node and the rest are compute nodes, so the number of expected hypervisors
633     # is one less than the total number of openstack systems
634     if [ $((NUM_OPENSTACK_SYSTEM / NUM_OPENSTACK_SITES - 1)) -eq 1 ]; then
635         expected_num_hypervisors=1
636     else
637         expected_num_hypervisors=${NUM_COMPUTES_PER_SITE}
638     fi
639     num_hypervisors=$(${SSH} ${!CONTROLIP} "cd /opt/stack/devstack; source openrc admin admin; openstack hypervisor list -f value | wc -l" | tail -1 | tr -d "\r")
640     if ! [ "${num_hypervisors}" ] || ! [ ${num_hypervisors} -eq ${expected_num_hypervisors} ]; then
641         echo "Error: Only $num_hypervisors hypervisors detected, expected $expected_num_hypervisors"
642         collect_logs_and_exit
643         exit 1
644     fi
645
646     # upgrading pip, urllib3 and httplib2 so that tempest tests can be run on openstack control node
647     # this needs to happen after devstack runs because it seems devstack is pulling in specific versions
648     # of these libs that are not working for tempest.
649     ${SSH} ${!CONTROLIP} "sudo pip install --upgrade pip"
650     ${SSH} ${!CONTROLIP} "sudo pip install urllib3 --upgrade"
651     ${SSH} ${!CONTROLIP} "sudo pip install httplib2 --upgrade"
652
653     # Gather Compute IPs for the site
654     for j in `seq 1 ${NUM_COMPUTES_PER_SITE}`
655     do
656         COMPUTE_INDEX=$(((i-1) * NUM_COMPUTES_PER_SITE + j))
657         IP_VAR=OPENSTACK_COMPUTE_NODE_${COMPUTE_INDEX}_IP
658         COMPUTE_IPS[$((j-1))]=${!IP_VAR}
659     done
660
661     # Need to disable firewalld and iptables in compute nodes as well
662     for ip in ${COMPUTE_IPS[*]}
663     do
664         scp ${WORKSPACE}/disable_firewall.sh "${ip}:/tmp"
665         ${SSH} "${ip}" "sudo bash /tmp/disable_firewall.sh"
666     done
667
668     # External Network
669     echo "prepare external networks by adding vxlan tunnels between all nodes on a separate bridge..."
670     # FIXME Should there be a unique gateway IP and devstack index for each site?
671     devstack_index=1
672     for ip in ${!CONTROLIP} ${COMPUTE_IPS[*]}
673     do
674         # 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
675         ${SSH} $ip "sudo ovs-vsctl --if-exists del-port br-int $PUBLIC_BRIDGE"
676         ${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++))"
677     done
678
679     # ipsec support
680     if [ "${IPSEC_VXLAN_TUNNELS_ENABLED}" == "yes" ]; then
681         ALL_NODES=(${!CONTROLIP} ${COMPUTE_IPS[*]})
682         for ((inx_ip1=0; inx_ip1<$((${#ALL_NODES[@]} - 1)); inx_ip1++))
683         do
684             for ((inx_ip2=$((inx_ip1 + 1)); inx_ip2<${#ALL_NODES[@]}; inx_ip2++))
685             do
686                 KEY1=0x$(dd if=/dev/urandom count=32 bs=1 2> /dev/null| xxd -p -c 64)
687                 KEY2=0x$(dd if=/dev/urandom count=32 bs=1 2> /dev/null| xxd -p -c 64)
688                 ID=0x$(dd if=/dev/urandom count=4 bs=1 2> /dev/null| xxd -p -c 8)
689                 ip1=${ALL_NODES[$inx_ip1]}
690                 ip2=${ALL_NODES[$inx_ip2]}
691                 ${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"
692                 ${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"
693                 ${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"
694                 ${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"
695
696                 ${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"
697                 ${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"
698                 ${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"
699                 ${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"
700             done
701         done
702
703         for ip in ${!CONTROLIP} ${COMPUTE_IPS[*]}
704         do
705             echo "ip xfrm configuration for node $ip:"
706             ${SSH} $ip "sudo ip xfrm policy list"
707             ${SSH} $ip "sudo ip xfrm state list"
708         done
709     fi
710
711     # Control Node - PUBLIC_BRIDGE will act as the external router
712     GATEWAY_IP="10.10.10.250" # FIXME this should be a parameter, also shared with integration-test
713     GATEWAY_VLAN_ID=167
714     ${SSH} ${!CONTROLIP} "sudo ip link add link ${PUBLIC_BRIDGE} name ${PUBLIC_BRIDGE}.${GATEWAY_VLAN_ID} type vlan id ${GATEWAY_VLAN_ID}"
715     ${SSH} ${!CONTROLIP} "sudo ifconfig ${PUBLIC_BRIDGE} up"
716     ${SSH} ${!CONTROLIP} "sudo ifconfig ${PUBLIC_BRIDGE}.${GATEWAY_VLAN_ID} up ${GATEWAY_IP}/24"
717
718     # Computes
719     compute_index=1
720     for compute_ip in ${COMPUTE_IPS[*]}
721     do
722         # Tunnel from controller to compute
723         COMPUTEPORT=compute$(( compute_index++ ))_vxlan
724         ${SSH} ${!CONTROLIP} "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"
725         # Tunnel from compute to controller
726         CONTROLPORT="control_vxlan"
727         ${SSH} $compute_ip "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"
728     done
729 done
730
731 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
732     odlmgrip=OPENSTACK_HAPROXY_1_IP
733     HA_PROXY_IP=${!odlmgrip}
734     HA_PROXY_1_IP=${!odlmgrip}
735     odlmgrip2=OPENSTACK_HAPROXY_2_IP
736     HA_PROXY_2_IP=${!odlmgrip2}
737     odlmgrip3=OPENSTACK_HAPROXY_1_IP
738     HA_PROXY_3_IP=${!odlmgrip3}
739 else
740     HA_PROXY_IP=${ODL_SYSTEM_IP}
741     HA_PROXY_1_IP=${ODL_SYSTEM_1_IP}
742     HA_PROXY_2_IP=${ODL_SYSTEM_2_IP}
743     HA_PROXY_3_IP=${ODL_SYSTEM_3_IP}
744 fi
745
746 echo "Locating test plan to use..."
747 testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
748 if [ ! -f "${testplan_filepath}" ]; then
749     testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
750 fi
751
752 echo "Changing the testplan path..."
753 cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
754 cat testplan.txt
755
756 SUITES=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
757
758 #FIXME currently support only 1 site
759 echo "Starting Robot test suites ${SUITES} ..."
760 # please add pybot -v arguments on a single line and alphabetized
761 pybot -N ${TESTPLAN} --removekeywords wuks -c critical -e exclude \
762     -v BUNDLEFOLDER:${BUNDLEFOLDER} \
763     -v BUNDLE_URL:${ACTUALBUNDLEURL} \
764     -v CONTROLLER_USER:${USER} \
765     -v DEVSTACK_DEPLOY_PATH:/opt/stack/devstack \
766     -v HA_PROXY_IP:${HA_PROXY_IP} \
767     -v HA_PROXY_1_IP:${HA_PROXY_1_IP} \
768     -v HA_PROXY_2_IP:${HA_PROXY_2_IP} \
769     -v HA_PROXY_3_IP:${HA_PROXY_3_IP} \
770     -v JDKVERSION:${JDKVERSION} \
771     -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
772     -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} \
773     -v NUM_OPENSTACK_SITES:${NUM_OPENSTACK_SITES} \
774     -v NUM_OS_SYSTEM:${NUM_OPENSTACK_SYSTEM} \
775     -v NUM_TOOLS_SYSTEM:${NUM_TOOLS_SYSTEM} \
776     -v ODL_STREAM:${DISTROSTREAM} \
777     -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} \
778     -v ODL_SYSTEM_1_IP:${ODL_SYSTEM_1_IP} \
779     -v ODL_SYSTEM_2_IP:${ODL_SYSTEM_2_IP} \
780     -v ODL_SYSTEM_3_IP:${ODL_SYSTEM_3_IP} \
781     -v ODL_SYSTEM_4_IP:${ODL_SYSTEM_4_IP} \
782     -v ODL_SYSTEM_5_IP:${ODL_SYSTEM_5_IP} \
783     -v ODL_SYSTEM_6_IP:${ODL_SYSTEM_6_IP} \
784     -v ODL_SYSTEM_7_IP:${ODL_SYSTEM_7_IP} \
785     -v ODL_SYSTEM_8_IP:${ODL_SYSTEM_8_IP} \
786     -v ODL_SYSTEM_9_IP:${ODL_SYSTEM_9_IP} \
787     -v OS_CONTROL_NODE_IP:${OPENSTACK_CONTROL_NODE_1_IP} \
788     -v OS_CONTROL_NODE_1_IP:${OPENSTACK_CONTROL_NODE_1_IP} \
789     -v OS_CONTROL_NODE_2_IP:${OPENSTACK_CONTROL_NODE_2_IP} \
790     -v OS_CONTROL_NODE_3_IP:${OPENSTACK_CONTROL_NODE_3_IP} \
791     -v OPENSTACK_BRANCH:${OPENSTACK_BRANCH} \
792     -v OS_COMPUTE_1_IP:${OPENSTACK_COMPUTE_NODE_1_IP} \
793     -v OS_COMPUTE_2_IP:${OPENSTACK_COMPUTE_NODE_2_IP} \
794     -v OS_COMPUTE_3_IP:${OPENSTACK_COMPUTE_NODE_3_IP} \
795     -v OS_COMPUTE_4_IP:${OPENSTACK_COMPUTE_NODE_4_IP} \
796     -v OS_COMPUTE_5_IP:${OPENSTACK_COMPUTE_NODE_5_IP} \
797     -v OS_COMPUTE_6_IP:${OPENSTACK_COMPUTE_NODE_6_IP} \
798     -v OS_USER:${USER} \
799     -v PUBLIC_PHYSICAL_NETWORK:${PUBLIC_PHYSICAL_NETWORK} \
800     -v SECURITY_GROUP_MODE:${SECURITY_GROUP_MODE} \
801     -v TOOLS_SYSTEM_IP:${TOOLS_SYSTEM_1_IP} \
802     -v TOOLS_SYSTEM_1_IP:${TOOLS_SYSTEM_1_IP} \
803     -v TOOLS_SYSTEM_2_IP:${TOOLS_SYSTEM_2_IP} \
804     -v USER_HOME:${HOME} \
805     -v WORKSPACE:/tmp \
806     ${TESTOPTIONS} ${SUITES} || true
807
808 echo "Examining the files in data/log and checking filesize"
809 ssh ${ODL_SYSTEM_IP} "ls -altr /tmp/${BUNDLEFOLDER}/data/log/"
810 ssh ${ODL_SYSTEM_IP} "du -hs /tmp/${BUNDLEFOLDER}/data/log/*"
811
812 echo "Tests Executed"
813 collect_logs_and_exit
814
815 true  # perhaps Jenkins is testing last exit code
816 # vim: ts=4 sw=4 sts=4 et ft=sh :