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