0c3f9d44c5edaa1185b8af522ab1cdfc29b2308b
[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   if [[ "${#deploy_options_array[@]}" -eq 0 || "${deploy_options_array['sdn_controller']}" == 'opendaylight' ]]; then
15     if [ "${deploy_options_array['sdn_l3']}" == 'True' ]; then
16       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_l3.yaml"
17     elif [ "${deploy_options_array['sfc']}" == 'True' ]; then
18       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sfc.yaml"
19     elif [ "${deploy_options_array['vpn']}" == 'True' ]; then
20       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sdnvpn.yaml"
21     elif [ "${deploy_options_array['vpp']}" == 'True' ]; then
22       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_fdio.yaml"
23     elif [ "${deploy_options_array['vpn']}" == 'true' ]; then
24       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sdnvpn.yaml"
25     else
26       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight.yaml"
27     fi
28     SDN_IMAGE=opendaylight
29     if [ "${deploy_options_array['sfc']}" == 'True' ]; then
30       SDN_IMAGE+=-sfc
31       if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
32           echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute an SFC deployment."
33           echo "Please install the opnfv-apex-opendaylight-sfc package to provide this overcloud image for deployment.${reset}"
34           exit 1
35       fi
36     fi
37   elif [ "${deploy_options_array['sdn_controller']}" == 'opendaylight-external' ]; then
38     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight-external.yaml"
39     SDN_IMAGE=opendaylight
40   elif [ "${deploy_options_array['sdn_controller']}" == 'onos' ]; then
41     if [ "${deploy_options_array['sfc']}" == 'True' ]; then
42       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos_sfc.yaml"
43     else
44       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos.yaml"
45     fi
46     SDN_IMAGE=onos
47   elif [ "${deploy_options_array['sdn_controller']}" == 'opencontrail' ]; then
48     echo -e "${red}ERROR: OpenContrail is currently unsupported...exiting${reset}"
49     exit 1
50   elif [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
51     echo -e "${blue}INFO: SDN Controller disabled...will deploy nosdn scenario${reset}"
52     SDN_IMAGE=opendaylight
53   else
54     echo "${red}Invalid sdn_controller: ${deploy_options_array['sdn_controller']}${reset}"
55     echo "${red}Valid choices are opendaylight, opendaylight-external, onos, opencontrail, False, or null${reset}"
56     exit 1
57   fi
58
59
60
61   # Make sure the correct overcloud image is available
62   if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
63       echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute your deployment."
64       echo "Both ONOS and OpenDaylight are currently deployed from this image."
65       echo "Please install the opnfv-apex package to provide this overcloud image for deployment.${reset}"
66       exit 1
67   fi
68
69   echo "Copying overcloud image to Undercloud"
70   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f overcloud-full.qcow2"
71   scp ${SSH_OPTIONS[@]} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 "stack@$UNDERCLOUD":overcloud-full.qcow2
72
73   # Install ovs-dpdk inside the overcloud image if it is enabled.
74   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
75     # install dpdk packages before ovs
76     echo -e "${blue}INFO: Enabling kernel modules for dpdk inside overcloud image${reset}"
77
78     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
79       cat << EOF > vfio_pci.modules
80 #!/bin/bash
81 exec /sbin/modprobe vfio_pci >/dev/null 2>&1
82 EOF
83
84       cat << EOF > uio_pci_generic.modules
85 #!/bin/bash
86 exec /sbin/modprobe uio_pci_generic >/dev/null 2>&1
87 EOF
88
89       LIBGUESTFS_BACKEND=direct virt-customize --upload vfio_pci.modules:/etc/sysconfig/modules/ \
90                                                --upload uio_pci_generic.modules:/etc/sysconfig/modules/ \
91                                                --run-command "chmod 0755 /etc/sysconfig/modules/vfio_pci.modules" \
92                                                --run-command "chmod 0755 /etc/sysconfig/modules/uio_pci_generic.modules" \
93                                                --run-command "yum install -y /root/dpdk_rpms/*" \
94                                                -a overcloud-full.qcow2
95 EOI
96   elif [ "${deploy_options_array['dataplane']}" != 'ovs' ]; then
97     echo "${red}${deploy_options_array['dataplane']} not supported${reset}"
98     exit 1
99   fi
100
101   # Set ODL version accordingly
102   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "${deploy_options_array['odl_version']}" == 'boron' ]]; then
103     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
104       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
105                                                --run-command "yum -y install /root/boron/*" \
106                                                -a overcloud-full.qcow2
107 EOI
108   fi
109
110   # Add performance deploy options if they have been set
111   if [ ! -z "${deploy_options_array['performance']}" ]; then
112
113     # Remove previous kernel args files per role
114     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Compute-kernel_params.txt"
115     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Controller-kernel_params.txt"
116
117     # Push performance options to subscript to modify per-role images as needed
118     for option in "${performance_options[@]}" ; do
119       echo -e "${blue}Setting performance option $option${reset}"
120       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "bash build_perf_image.sh $option"
121     done
122
123     # Build IPA kernel option ramdisks
124     ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
125 /bin/cp -f /home/stack/ironic-python-agent.initramfs /root/
126 mkdir -p ipa/
127 pushd ipa
128 gunzip -c ../ironic-python-agent.initramfs | cpio -i
129 if [ ! -f /home/stack/Compute-kernel_params.txt ]; then
130   touch /home/stack/Compute-kernel_params.txt
131   chown stack /home/stack/Compute-kernel_params.txt
132 fi
133 /bin/cp -f /home/stack/Compute-kernel_params.txt tmp/kernel_params.txt
134 echo "Compute params set: "
135 cat tmp/kernel_params.txt
136 /bin/cp -f /root/image.py usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.py
137 /bin/cp -f /root/image.pyc usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.pyc
138 find . | cpio -o -H newc | gzip > /home/stack/Compute-ironic-python-agent.initramfs
139 chown stack /home/stack/Compute-ironic-python-agent.initramfs
140 if [ ! -f /home/stack/Controller-kernel_params.txt ]; then
141   touch /home/stack/Controller-kernel_params.txt
142   chown stack /home/stack/Controller-kernel_params.txt
143 fi
144 /bin/cp -f /home/stack/Controller-kernel_params.txt tmp/kernel_params.txt
145 echo "Controller params set: "
146 cat tmp/kernel_params.txt
147 find . | cpio -o -H newc | gzip > /home/stack/Controller-ironic-python-agent.initramfs
148 chown stack /home/stack/Controller-ironic-python-agent.initramfs
149 popd
150 /bin/rm -rf ipa/
151 EOI
152
153     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml"
154   fi
155
156   # make sure ceph is installed
157   DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
158
159   # scale compute nodes according to inventory
160   total_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "cat /home/stack/instackenv.json | grep -c memory")
161
162   # check if HA is enabled
163   if [[ "$ha_enabled" == "True" ]]; then
164      DEPLOY_OPTIONS+=" --control-scale 3"
165      compute_nodes=$((total_nodes - 3))
166      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
167   else
168      compute_nodes=$((total_nodes - 1))
169   fi
170
171   if [ "$compute_nodes" -le 0 ]; then
172     echo -e "${red}ERROR: Invalid number of compute nodes: ${compute_nodes}. Check your inventory file.${reset}"
173     exit 1
174   else
175     echo -e "${blue}INFO: Number of compute nodes set for deployment: ${compute_nodes}${reset}"
176     DEPLOY_OPTIONS+=" --compute-scale ${compute_nodes}"
177   fi
178
179   if [[ "$net_isolation_enabled" == "TRUE" ]]; then
180      #DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.yaml"
181      DEPLOY_OPTIONS+=" -e network-environment.yaml"
182   fi
183
184   if [[ "$ha_enabled" == "True" ]] || [[ "$net_isolation_enabled" == "TRUE" ]]; then
185      DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
186   fi
187
188   DEPLOY_OPTIONS+=" --control-flavor control --compute-flavor compute"
189   if [[ "$virtual" == "TRUE" ]]; then
190      DEPLOY_OPTIONS+=" -e virtual-environment.yaml"
191   fi
192
193   DEPLOY_OPTIONS+=" -e opnfv-environment.yaml"
194
195   echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
196
197   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
198 if [ "$debug" == 'TRUE' ]; then
199     LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex
200 fi
201
202 source stackrc
203 set -o errexit
204 # Workaround for APEX-207 where sometimes swift proxy is down
205 if ! sudo systemctl status openstack-swift-proxy > /dev/null; then
206   sudo systemctl restart openstack-swift-proxy
207 fi
208 echo "Uploading overcloud glance images"
209 openstack overcloud image upload
210
211 echo "Configuring undercloud and discovering nodes"
212 openstack baremetal import --json instackenv.json
213 openstack baremetal configure boot
214 bash -x set_perf_images.sh ${performance_roles[@]}
215 #if [[ -z "$virtual" ]]; then
216 #  openstack baremetal introspection bulk start
217 #fi
218 echo "Configuring flavors"
219 for flavor in baremetal control compute; do
220   echo -e "${blue}INFO: Updating flavor: \${flavor}${reset}"
221   if openstack flavor list | grep \${flavor}; then
222     openstack flavor delete \${flavor}
223   fi
224   openstack flavor create --id auto --ram 4096 --disk 39 --vcpus 1 \${flavor}
225   if ! openstack flavor list | grep \${flavor}; then
226     echo -e "${red}ERROR: Unable to create flavor \${flavor}${reset}"
227   fi
228 done
229 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" baremetal
230 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="control" control
231 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="compute" compute
232 echo "Configuring nameserver on ctlplane network"
233 dns_server_ext=''
234 for dns_server in ${dns_servers}; do
235   dns_server_ext="\${dns_server_ext} --dns-nameserver \${dns_server}"
236 done
237 neutron subnet-update \$(neutron subnet-list | grep -Ev "id|tenant|external|storage" | grep -v \\\\-\\\\- | awk {'print \$2'}) \${dns_server_ext}
238 sed -i '/CloudDomain:/c\  CloudDomain: '${domain_name} opnfv-environment.yaml
239 echo "Executing overcloud deployment, this should run for an extended period without output."
240 sleep 60 #wait for Hypervisor stats to check-in to nova
241 # save deploy command so it can be used for debugging
242 cat > deploy_command << EOF
243 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
244 EOF
245 EOI
246
247   if [ "$interactive" == "TRUE" ]; then
248     if ! prompt_user "Overcloud Deployment"; then
249       echo -e "${blue}INFO: User requests exit${reset}"
250       exit 0
251     fi
252   fi
253
254   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
255 source stackrc
256 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
257 if ! heat stack-list | grep CREATE_COMPLETE 1>/dev/null; then
258   $(typeset -f debug_stack)
259   debug_stack
260   exit 1
261 fi
262 EOI
263
264   # Configure DPDK
265   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
266     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI || (echo "DPDK config failed, exiting..."; exit 1)
267 source stackrc
268 set -o errexit
269 for node in \$(nova list | grep novacompute | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
270 echo "Running DPDK test app on \$node"
271 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
272 set -o errexit
273 sudo dpdk_helloworld --no-pci
274 sudo dpdk_nic_bind -s
275 EOF
276 done
277 EOI
278   fi
279
280   if [ "$debug" == 'TRUE' ]; then
281       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
282 source overcloudrc
283 echo "Keystone Endpoint List:"
284 openstack endpoint list
285 echo "Keystone Service List"
286 openstack service list
287 cinder quota-show \$(openstack project list | grep admin | awk {'print \$2'})
288 EOI
289   fi
290 }