Disables ODL clustering for FDIO+ODL scenarios
[apex.git] / lib / overcloud-deploy-functions.sh
1 #!/usr/bin/env bash
2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 ##preping it for deployment and launch the deploy
12 ##params: none
13 function overcloud_deploy {
14   local num_compute_nodes
15   local num_control_nodes
16   local dpdk_cores pmd_cores socket_mem ovs_dpdk_perf_flag ovs_option_heat_arr
17   declare -A ovs_option_heat_arr
18
19   ovs_option_heat_arr['dpdk_cores']=OvsDpdkCoreList
20   ovs_option_heat_arr['pmd_cores']=PmdCoreList
21   ovs_option_heat_arr['socket_memory']=OvsDpdkSocketMemory
22
23   # OPNFV Default Environment and Network settings
24   DEPLOY_OPTIONS+=" -e ${ENV_FILE}"
25   DEPLOY_OPTIONS+=" -e network-environment.yaml"
26
27   # Custom Deploy Environment Templates
28   if [[ "${#deploy_options_array[@]}" -eq 0 || "${deploy_options_array['sdn_controller']}" == 'opendaylight' ]]; then
29     if [ "${deploy_options_array['sfc']}" == 'True' ]; then
30       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sfc.yaml"
31     elif [ "${deploy_options_array['vpn']}" == 'True' ]; then
32       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-bgpvpn.yaml"
33       if [ "${deploy_options_array['gluon']}" == 'True' ]; then
34         DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/services/gluon.yaml"
35       fi
36     elif [ "${deploy_options_array['vpp']}" == 'True' ]; then
37       if [ "${deploy_options_array['sdn_l3']}" == "True" ]; then
38         DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-honeycomb.yaml"
39       else
40         DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-honeycomb-l2.yaml"
41       fi
42     else
43       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-l3.yaml"
44     fi
45     SDN_IMAGE=opendaylight
46   elif [ "${deploy_options_array['sdn_controller']}" == 'opendaylight-external' ]; then
47     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight-external.yaml"
48     SDN_IMAGE=opendaylight
49   elif [ "${deploy_options_array['sdn_controller']}" == 'onos' ]; then
50     echo -e "${red}ERROR: ONOS is unsupported in Danube...exiting${reset}"
51     exit 1
52     #if [ "${deploy_options_array['sfc']}" == 'True' ]; then
53     #  DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos_sfc.yaml"
54     #else
55     #  DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos.yaml"
56     #fi
57     #SDN_IMAGE=onos
58   elif [ "${deploy_options_array['sdn_controller']}" == 'opencontrail' ]; then
59     echo -e "${red}ERROR: OpenContrail is currently unsupported...exiting${reset}"
60     exit 1
61   elif [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
62     echo -e "${blue}INFO: SDN Controller disabled...will deploy nosdn scenario${reset}"
63     if [ "${deploy_options_array['vpp']}" == 'True' ]; then
64       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-ml2-vpp.yaml"
65     elif [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
66       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-ovs-dpdk.yaml"
67     fi
68     SDN_IMAGE=opendaylight
69   else
70     echo "${red}Invalid sdn_controller: ${deploy_options_array['sdn_controller']}${reset}"
71     echo "${red}Valid choices are opendaylight, opendaylight-external, onos, opencontrail, False, or null${reset}"
72     exit 1
73   fi
74
75   # Enable Tacker
76   if [ "${deploy_options_array['tacker']}" == 'True' ]; then
77     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/enable_tacker.yaml"
78   fi
79
80   # Enable Congress
81   if [ "${deploy_options_array['congress']}" == 'True' ]; then
82     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/enable_congress.yaml"
83   fi
84
85   # Enable Real Time Kernel (kvm4nfv)
86   if [ "${deploy_options_array['rt_kvm']}" == 'True' ]; then
87     DEPLOY_OPTIONS+=" -e /home/stack/enable_rt_kvm.yaml"
88   fi
89
90   # Make sure the correct overcloud image is available
91   if [ ! -f $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
92       echo "${red} $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute your deployment."
93       echo "Please install the opnfv-apex package to provide this overcloud image for deployment.${reset}"
94       exit 1
95   fi
96
97   echo "Copying overcloud image to Undercloud"
98   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f overcloud-full.qcow2"
99   scp ${SSH_OPTIONS[@]} $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 "stack@$UNDERCLOUD":overcloud-full.qcow2
100
101   # disable neutron openvswitch agent from starting
102   if [[ -n "${deploy_options_array['sdn_controller']}" && "${deploy_options_array['sdn_controller']}" != 'False' ]]; then
103       echo -e "${blue}INFO: Disabling neutron-openvswitch-agent from systemd${reset}"
104       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
105       LIBGUESTFS_BACKEND=direct virt-customize --run-command "rm -f /etc/systemd/system/multi-user.target.wants/neutron-openvswitch-agent.service" \
106                                                --run-command "rm -f /usr/lib/systemd/system/neutron-openvswitch-agent.service" \
107                                                -a overcloud-full.qcow2
108 EOI
109   fi
110
111   if [ "${deploy_options_array['vpn']}" == 'True' ]; then
112       echo -e "${blue}INFO: Enabling ZRPC and Quagga${reset}"
113       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
114       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y install /root/quagga/*.rpm" \
115                                                --run-command "systemctl enable zrpcd" \
116                                                -a overcloud-full.qcow2
117 EOI
118   fi
119
120   # Install ovs-dpdk inside the overcloud image if it is enabled.
121   if [[ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' || "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
122     # install dpdk packages before ovs
123     echo -e "${blue}INFO: Enabling kernel modules for dpdk inside overcloud image${reset}"
124
125     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
126       cat << EOF > vfio_pci.modules
127 #!/bin/bash
128 exec /sbin/modprobe vfio_pci >/dev/null 2>&1
129 EOF
130
131       cat << EOF > uio_pci_generic.modules
132 #!/bin/bash
133 exec /sbin/modprobe uio_pci_generic >/dev/null 2>&1
134 EOF
135
136       LIBGUESTFS_BACKEND=direct virt-customize --upload vfio_pci.modules:/etc/sysconfig/modules/ \
137                                                --upload uio_pci_generic.modules:/etc/sysconfig/modules/ \
138                                                --run-command "chmod 0755 /etc/sysconfig/modules/vfio_pci.modules" \
139                                                --run-command "chmod 0755 /etc/sysconfig/modules/uio_pci_generic.modules" \
140                                                -a overcloud-full.qcow2
141
142       if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
143         sed -i "/OS::TripleO::ComputeExtraConfigPre:/c\  OS::TripleO::ComputeExtraConfigPre: ./ovs-dpdk-preconfig.yaml" network-environment.yaml
144       fi
145
146 EOI
147
148   elif [ "${deploy_options_array['dataplane']}" != 'ovs' ]; then
149     echo "${red}${deploy_options_array['dataplane']} not supported${reset}"
150     exit 1
151   fi
152
153   if [ "$debug" == 'TRUE' ]; then
154     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex"
155   fi
156
157   # upgrade ovs into ovs 2.5.90 with NSH function if SFC is enabled
158   if [[ "${deploy_options_array['sfc']}" == 'True' && "${deploy_options_array['dataplane']}" == 'ovs' ]]; then
159     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
160          LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum install -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_kmod_rpm_name}" \
161                                                   --run-command "yum upgrade -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_rpm_name}" \
162                                                   -a overcloud-full.qcow2
163 EOI
164   fi
165
166   # Patch neutron with using OVS external interface for router and add generic linux NS interface driver
167   if [[ "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
168     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
169       LIBGUESTFS_BACKEND=direct virt-customize --run-command "cd /usr/lib/python2.7/site-packages/ && patch -p1 < neutron-patch-NSDriver.patch" \
170                                                -a overcloud-full.qcow2
171 EOI
172
173     # Disable clustering for ODL FDIO HA scenarios
174     if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' ]]; then
175       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
176       LIBGUESTFS_BACKEND=direct virt-customize --run-command "cd /etc/puppet/modules/tripleo/ && patch -p1 < disable_odl_clustering.patch" \
177                                                -a overcloud-full.qcow2
178 EOI
179     fi
180
181     # Configure routing node for odl_l3-fdio
182     if [[ "${deploy_options_array['sdn_l3']}" == 'True' ]]; then
183       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
184         sed -i "/opendaylight::vpp_routing_node:/c\    opendaylight::vpp_routing_node: ${deploy_options_array['odl_vpp_routing_node']}.${domain_name}" ${ENV_FILE}
185 EOI
186     fi
187   fi
188
189   if [ -n "${deploy_options_array['performance']}" ]; then
190     ovs_dpdk_perf_flag="False"
191     for option in "${performance_options[@]}" ; do
192       arr=($option)
193       # use compute's kernel settings for all nodes for now.
194       if [ "${arr[0]}" == "Compute" ] && [ "${arr[1]}" == "kernel" ]; then
195         kernel_args+=" ${arr[2]}=${arr[3]}"
196       fi
197       if [ "${arr[0]}" == "Compute" ] && [ "${arr[1]}" == "ovs" ]; then
198          eval "${arr[2]}=${arr[3]}"
199          ovs_dpdk_perf_flag="True"
200       fi
201     done
202
203     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
204       sed -i "/ComputeKernelArgs:/c\  ComputeKernelArgs: '$kernel_args'" ${ENV_FILE}
205       sed -i "$ a\resource_registry:\n  OS::TripleO::NodeUserData: first-boot.yaml" ${ENV_FILE}
206       sed -i "/NovaSchedulerDefaultFilters:/c\  NovaSchedulerDefaultFilters: 'RamFilter,ComputeFilter,AvailabilityZoneFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,NUMATopologyFilter'" ${ENV_FILE}
207 EOI
208
209     if [[ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' && "$ovs_dpdk_perf_flag" == "True" ]]; then
210       for ovs_option in ${!ovs_option_heat_arr[@]}; do
211         if [ -n "${!ovs_option}" ]; then
212           ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
213             sed -i "/${ovs_option_heat_arr[$ovs_option]}:/c\  ${ovs_option_heat_arr[$ovs_option]}: ${!ovs_option}" ${ENV_FILE}
214 EOI
215         fi
216       done
217     fi
218   fi
219
220   if [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
221     if [ "${deploy_options_array['dataplane']}" == "fdio" ]; then
222       if [ "$tenant_nic_mapping_controller_members" == "$tenant_nic_mapping_compute_members" ]; then
223         ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
224           sed -i "/NeutronVPPAgentPhysnets:/c\  NeutronVPPAgentPhysnets: 'datacentre:${tenant_nic_mapping_controller_members}'" ${ENV_FILE}
225 EOI
226       else
227         echo -e "${red}Compute and Controller must use the same tenant nic name, please modify network setting file.${reset}"
228         exit 1
229       fi
230     fi
231   fi
232
233   # Set ODL version accordingly
234   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && -n "${deploy_options_array['odl_version']}" ]]; then
235     case "${deploy_options_array['odl_version']}" in
236       beryllium) odl_version=''
237               ;;
238       boron)  odl_version='boron'
239               ;;
240       carbon) odl_version='master'
241               ;;
242       *) echo -e "${red}Invalid ODL version ${deploy_options_array['odl_version']}.  Please use 'carbon' or 'boron' values.${reset}"
243          exit 1
244          ;;
245     esac
246
247     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
248       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
249                                                --run-command "yum -y install /root/${odl_version}/*" \
250                                                -a overcloud-full.qcow2
251 EOI
252   fi
253
254   # Override ODL if FDIO and ODL L2
255   if [[ "${deploy_options_array['vpp']}" == 'True' && "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "${deploy_options_array['sdn_l3']}" == "False" ]]; then
256     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
257          LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
258                                                   --run-command "yum -y install /root/fdio_l2/opendaylight*.rpm" \
259                                                   -a overcloud-full.qcow2
260 EOI
261   fi
262
263   # check if ceph should be enabled
264   if [ "${deploy_options_array['ceph']}" == 'True' ]; then
265     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
266   fi
267
268   # get number of nodes available in inventory
269   num_control_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:control /home/stack/instackenv.json")
270   num_compute_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:compute /home/stack/instackenv.json")
271
272   # check if HA is enabled
273   if [[ "$ha_enabled" == "True" ]]; then
274     if [ "$num_control_nodes" -lt 3 ]; then
275       echo -e "${red}ERROR: Number of control nodes in inventory is less than 3 and HA is enabled: ${num_control_nodes}. Check your inventory file.${reset}"
276       exit 1
277     else
278      DEPLOY_OPTIONS+=" --control-scale ${num_control_nodes}"
279      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
280      echo -e "${blue}INFO: Number of control nodes set for deployment: ${num_control_nodes}${reset}"
281     fi
282   else
283     if [ "$num_control_nodes" -lt 1 ]; then
284       echo -e "${red}ERROR: Number of control nodes in inventory is less than 1: ${num_control_nodes}. Check your inventory file.${reset}"
285       exit 1
286     fi
287   fi
288
289   if [ "$num_compute_nodes" -le 0 ]; then
290     echo -e "${red}ERROR: Invalid number of compute nodes: ${num_compute_nodes}. Check your inventory file.${reset}"
291     exit 1
292   else
293     echo -e "${blue}INFO: Number of compute nodes set for deployment: ${num_compute_nodes}${reset}"
294     DEPLOY_OPTIONS+=" --compute-scale ${num_compute_nodes}"
295   fi
296
297   DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
298
299   DEPLOY_OPTIONS+=" --control-flavor control --compute-flavor compute"
300   if [[ "$virtual" == "TRUE" ]]; then
301      DEPLOY_OPTIONS+=" -e virtual-environment.yaml"
302   fi
303
304   echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
305
306   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
307 # Create a key for use by nova for live migration
308 echo "Creating nova SSH key for nova resize support"
309 ssh-keygen -f nova_id_rsa -b 1024 -P ""
310 public_key=\'\$(cat nova_id_rsa.pub | cut -d ' ' -f 2)\'
311 sed -i "s#replace_public_key:#key: \$public_key#g" ${ENV_FILE}
312 python -c 'open("opnfv-environment-new.yaml", "w").write((open("${ENV_FILE}").read().replace("replace_private_key:", "key: \"" + "".join(open("nova_id_rsa").readlines()).replace("\\n","\\\n") + "\"")))'
313 mv -f opnfv-environment-new.yaml ${ENV_FILE}
314
315 source stackrc
316 set -o errexit
317 # Workaround for APEX-207 where sometimes swift proxy is down
318 if ! sudo systemctl status openstack-swift-proxy > /dev/null; then
319   sudo systemctl restart openstack-swift-proxy
320 fi
321 echo "Uploading overcloud glance images"
322 openstack overcloud image upload
323
324 echo "Configuring undercloud and discovering nodes"
325 openstack baremetal import --json instackenv.json
326
327 if [[ -z "$virtual" ]]; then
328   openstack baremetal introspection bulk start
329   if [[ -n "$root_disk_list" ]]; then
330     openstack baremetal configure boot --root-device=${root_disk_list}
331   else
332     openstack baremetal configure boot
333   fi
334 else
335   openstack baremetal configure boot
336 fi
337
338 echo "Configuring flavors"
339 for flavor in baremetal control compute; do
340   echo -e "${blue}INFO: Updating flavor: \${flavor}${reset}"
341   if openstack flavor list | grep \${flavor}; then
342     openstack flavor delete \${flavor}
343   fi
344   openstack flavor create --id auto --ram 4096 --disk 39 --vcpus 1 \${flavor}
345   if ! openstack flavor list | grep \${flavor}; then
346     echo -e "${red}ERROR: Unable to create flavor \${flavor}${reset}"
347   fi
348 done
349 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" baremetal
350 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="control" control
351 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="compute" compute
352 echo "Configuring nameserver on ctlplane network"
353 dns_server_ext=''
354 for dns_server in ${dns_servers}; do
355   dns_server_ext="\${dns_server_ext} --dns-nameserver \${dns_server}"
356 done
357 neutron subnet-update \$(neutron subnet-list | grep -Ev "id|tenant|external|storage" | grep -v \\\\-\\\\- | awk {'print \$2'}) \${dns_server_ext}
358 sed -i '/CloudDomain:/c\  CloudDomain: '${domain_name} ${ENV_FILE}
359 echo "Executing overcloud deployment, this should run for an extended period without output."
360 sleep 60 #wait for Hypervisor stats to check-in to nova
361 # save deploy command so it can be used for debugging
362 cat > deploy_command << EOF
363 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
364 EOF
365 EOI
366
367   if [ "$interactive" == "TRUE" ]; then
368     if ! prompt_user "Overcloud Deployment"; then
369       echo -e "${blue}INFO: User requests exit${reset}"
370       exit 0
371     fi
372   fi
373
374   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
375 source stackrc
376 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
377 if ! openstack stack list | grep CREATE_COMPLETE 1>/dev/null; then
378   $(typeset -f debug_stack)
379   debug_stack
380   exit 1
381 fi
382 EOI
383
384   # Configure DPDK and restart ovs agent after bringing up br-phy
385   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
386     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI || (echo "DPDK config failed, exiting..."; exit 1)
387 source stackrc
388 set -o errexit
389 for node in \$(nova list | grep novacompute | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
390 echo "Checking DPDK status and bringing up br-phy on \$node"
391 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
392 set -o errexit
393 sudo dpdk-devbind -s
394 sudo ifup br-phy
395 if [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
396   echo "Restarting openvswitch agent to pick up VXLAN tunneling"
397   sudo systemctl restart neutron-openvswitch-agent
398 fi
399 EOF
400 done
401 EOI
402   fi
403
404   if [ "$debug" == 'TRUE' ]; then
405       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
406 source overcloudrc
407 echo "Keystone Endpoint List:"
408 openstack endpoint list
409 echo "Keystone Service List"
410 openstack service list
411 EOI
412   fi
413 }