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