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