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