Disabling ONOS from Danube
[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     echo -e "${red}ERROR: ONOS is unsupported in Danube...exiting${reset}"
36     exit 1
37     #if [ "${deploy_options_array['sfc']}" == 'True' ]; then
38     #  DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos_sfc.yaml"
39     #else
40     #  DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos.yaml"
41     #fi
42     #SDN_IMAGE=onos
43   elif [ "${deploy_options_array['sdn_controller']}" == 'opencontrail' ]; then
44     echo -e "${red}ERROR: OpenContrail is currently unsupported...exiting${reset}"
45     exit 1
46   elif [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
47     echo -e "${blue}INFO: SDN Controller disabled...will deploy nosdn scenario${reset}"
48     if [ "${deploy_options_array['vpp']}" == 'True' ]; then
49       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-ml2-networking-vpp.yaml"
50     fi
51     SDN_IMAGE=opendaylight
52   else
53     echo "${red}Invalid sdn_controller: ${deploy_options_array['sdn_controller']}${reset}"
54     echo "${red}Valid choices are opendaylight, opendaylight-external, onos, opencontrail, False, or null${reset}"
55     exit 1
56   fi
57
58   # Enable Tacker
59   if [ "${deploy_options_array['tacker']}" == 'True' ]; then
60     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/enable_tacker.yaml"
61   fi
62
63   # Enable Congress
64   if [ "${deploy_options_array['congress']}" == 'True' ]; then
65     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/enable_congress.yaml"
66   fi
67
68   # Make sure the correct overcloud image is available
69   if [ ! -f $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
70       echo "${red} $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute your deployment."
71       echo "Please install the opnfv-apex package to provide this overcloud image for deployment.${reset}"
72       exit 1
73   fi
74
75   echo "Copying overcloud image to Undercloud"
76   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f overcloud-full.qcow2"
77   scp ${SSH_OPTIONS[@]} $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 "stack@$UNDERCLOUD":overcloud-full.qcow2
78
79   if [ "${deploy_options_array['vpn']}" == 'True' ]; then
80       echo -e "${blue}INFO: Enabling ZRPC and Quagga${reset}"
81       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
82       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y install /root/quagga/*.rpm" \
83                                                --run-command "systemctl enable zrpcd" \
84                                                -a overcloud-full.qcow2
85 EOI
86   fi
87
88   # Install ovs-dpdk inside the overcloud image if it is enabled.
89   if [[ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' || "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
90     # install dpdk packages before ovs
91     echo -e "${blue}INFO: Enabling kernel modules for dpdk inside overcloud image${reset}"
92
93     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
94       cat << EOF > vfio_pci.modules
95 #!/bin/bash
96 exec /sbin/modprobe vfio_pci >/dev/null 2>&1
97 EOF
98
99       cat << EOF > uio_pci_generic.modules
100 #!/bin/bash
101 exec /sbin/modprobe uio_pci_generic >/dev/null 2>&1
102 EOF
103
104       LIBGUESTFS_BACKEND=direct virt-customize --upload vfio_pci.modules:/etc/sysconfig/modules/ \
105                                                --upload uio_pci_generic.modules:/etc/sysconfig/modules/ \
106                                                --run-command "chmod 0755 /etc/sysconfig/modules/vfio_pci.modules" \
107                                                --run-command "chmod 0755 /etc/sysconfig/modules/uio_pci_generic.modules" \
108                                                -a overcloud-full.qcow2
109
110       if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
111         LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum install -y /root/dpdk_rpms/*" \
112                                                  --run-command "sed -i '/RuntimeDirectoryMode=.*/d' /usr/lib/systemd/system/openvswitch-nonetwork.service" \
113                                                  --run-command "printf \"%s\\n\" RuntimeDirectoryMode=0775 Group=qemu UMask=0002 >> /usr/lib/systemd/system/openvswitch-nonetwork.service" \
114                                                  --run-command "sed -i 's/\\(^\\s\\+\\)\\(start_daemon "$OVS_VSWITCHD_PRIORITY"\\)/\\1umask 0002 \\&\\& \\2/' /usr/share/openvswitch/scripts/ovs-ctl" \
115                                                  -a overcloud-full.qcow2
116       fi
117
118 EOI
119
120   elif [ "${deploy_options_array['dataplane']}" != 'ovs' ]; then
121     echo "${red}${deploy_options_array['dataplane']} not supported${reset}"
122     exit 1
123   fi
124
125   if [ "$debug" == 'TRUE' ]; then
126     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex"
127   fi
128
129   # upgrade ovs into ovs 2.5.90 with NSH function if SFC is enabled
130   if [[ "${deploy_options_array['sfc']}" == 'True' && "${deploy_options_array['dataplane']}" == 'ovs' ]]; then
131     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
132          LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum install -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_kmod_rpm_name}" \
133                                                   --run-command "yum upgrade -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_rpm_name}" \
134                                                   -a overcloud-full.qcow2
135 EOI
136   fi
137
138   if [ -n "${deploy_options_array['performance']}" ]; then
139     for option in "${performance_options[@]}" ; do
140     arr=($option)
141     # use compute's kernel settings for all nodes for now.
142     if [ "${arr[0]}" == "Compute" ] && [ "${arr[1]}" == "kernel" ]; then
143       kernel_args+=" ${arr[2]}=${arr[3]}"
144     fi
145     done
146
147     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
148        sed -i "/ComputeKernelArgs:/c\  ComputeKernelArgs: '$kernel_args'" ${ENV_FILE}
149        sed -i "$ a\resource_registry:\n  OS::TripleO::NodeUserData: first-boot.yaml" ${ENV_FILE}
150        sed -i "/NovaSchedulerDefaultFilters:/c\  NovaSchedulerDefaultFilters: 'RamFilter,ComputeFilter,AvailabilityZoneFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,NUMATopologyFilter'" ${ENV_FILE}
151 EOI
152   fi
153
154   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
155     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
156       sed -i "/neutron::agents::dhcp::interface_driver:/c\    neutron::agents::dhcp::interface_driver: neutron.agent.linux.interface.NSDriver" ${ENV_FILE}
157       sed -i "/neutron::agents::l3::interface_driver:/c\    neutron::agents::l3::interface_driver: neutron.agent.linux.interface.NSDriver" ${ENV_FILE}
158 EOI
159   fi
160
161   # Set ODL version accordingly
162   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && -n "${deploy_options_array['odl_version']}" ]]; then
163     case "${deploy_options_array['odl_version']}" in
164       beryllium) odl_version=''
165               ;;
166       boron)  odl_version='boron'
167               ;;
168       carbon) odl_version='master'
169               ;;
170       *) echo -e "${red}Invalid ODL version ${deploy_options_array['odl_version']}.  Please use 'carbon' or 'boron' values.${reset}"
171          exit 1
172          ;;
173     esac
174
175     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
176       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
177                                                --run-command "yum -y install /root/${odl_version}/*" \
178                                                -a overcloud-full.qcow2
179 EOI
180   fi
181
182
183   # check if ceph should be enabled
184   if [ "${deploy_options_array['ceph']}" == 'True' ]; then
185     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
186   fi
187
188   #DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.yaml"
189   DEPLOY_OPTIONS+=" -e network-environment.yaml"
190
191
192   # get number of nodes available in inventory
193   num_control_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:control /home/stack/instackenv.json")
194   num_compute_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:compute /home/stack/instackenv.json")
195
196   # check if HA is enabled
197   if [[ "$ha_enabled" == "True" ]]; then
198     if [ "$num_control_nodes" -lt 3 ]; then
199       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}"
200       exit 1
201     else
202      DEPLOY_OPTIONS+=" --control-scale ${num_control_nodes}"
203      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
204      echo -e "${blue}INFO: Number of control nodes set for deployment: ${num_control_nodes}${reset}"
205     fi
206   else
207     if [ "$num_control_nodes" -lt 1 ]; then
208       echo -e "${red}ERROR: Number of control nodes in inventory is less than 1: ${num_control_nodes}. Check your inventory file.${reset}"
209       exit 1
210     fi
211   fi
212
213   if [ "$num_compute_nodes" -le 0 ]; then
214     echo -e "${red}ERROR: Invalid number of compute nodes: ${num_compute_nodes}. Check your inventory file.${reset}"
215     exit 1
216   else
217     echo -e "${blue}INFO: Number of compute nodes set for deployment: ${num_compute_nodes}${reset}"
218     DEPLOY_OPTIONS+=" --compute-scale ${num_compute_nodes}"
219   fi
220
221   DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
222
223   DEPLOY_OPTIONS+=" --control-flavor control --compute-flavor compute"
224   if [[ "$virtual" == "TRUE" ]]; then
225      DEPLOY_OPTIONS+=" -e virtual-environment.yaml"
226   fi
227
228   DEPLOY_OPTIONS+=" -e ${ENV_FILE}"
229
230   echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
231
232   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
233 # Create a key for use by nova for live migration
234 echo "Creating nova SSH key for nova resize support"
235 ssh-keygen -f nova_id_rsa -b 1024 -P ""
236 public_key=\'\$(cat nova_id_rsa.pub | cut -d ' ' -f 2)\'
237 sed -i "s#replace_public_key:#key: \$public_key#g" ${ENV_FILE}
238 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") + "\"")))'
239 mv -f opnfv-environment-new.yaml ${ENV_FILE}
240
241 source stackrc
242 set -o errexit
243 # Workaround for APEX-207 where sometimes swift proxy is down
244 if ! sudo systemctl status openstack-swift-proxy > /dev/null; then
245   sudo systemctl restart openstack-swift-proxy
246 fi
247 echo "Uploading overcloud glance images"
248 openstack overcloud image upload
249
250 echo "Configuring undercloud and discovering nodes"
251 openstack baremetal import --json instackenv.json
252
253 if [[ -z "$virtual" ]]; then
254   openstack baremetal introspection bulk start
255   if [[ -n "$root_disk_list" ]]; then
256     openstack baremetal configure boot --root-device=${root_disk_list}
257   else
258     openstack baremetal configure boot
259   fi
260 else
261   openstack baremetal configure boot
262 fi
263
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} ${ENV_FILE}
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 ! openstack 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 EOI
334   fi
335 }