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