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