Merge "Adds Doctor DS driver to Congress"
[apex.git] / ci / deploy.sh
1 #!/bin/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 # Deploy script to install provisioning server for OPNFV Apex
12 # author: Dan Radez (dradez@redhat.com)
13 # author: Tim Rozet (trozet@redhat.com)
14 #
15 # Based on RDO Manager http://www.rdoproject.org
16
17 set -e
18
19 ##VARIABLES
20 reset=$(tput sgr0 || echo "")
21 blue=$(tput setaf 4 || echo "")
22 red=$(tput setaf 1 || echo "")
23 green=$(tput setaf 2 || echo "")
24
25 interactive="FALSE"
26 ping_site="8.8.8.8"
27 dnslookup_site="www.google.com"
28 post_config="TRUE"
29 debug="FALSE"
30
31 ovs_rpm_name=openvswitch-2.6.1-1.el7.centos.x86_64.rpm
32 ovs_kmod_rpm_name=openvswitch-kmod-2.6.1-1.el7.centos.x86_64.rpm
33
34 declare -i CNT
35 declare UNDERCLOUD
36 declare -A deploy_options_array
37 declare -a performance_options
38 declare -A NET_MAP
39
40 APEX_TMP_DIR=$(python3 -c "import tempfile; print(tempfile.mkdtemp())")
41 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
42 DEPLOY_OPTIONS=""
43 BASE=${BASE:-'/var/opt/opnfv'}
44 IMAGES=${IMAGES:-"$BASE/images"}
45 LIB=${LIB:-"$BASE/lib"}
46 OPNFV_NETWORK_TYPES="admin tenant external storage api"
47 ENV_FILE="opnfv-environment.yaml"
48
49 VM_CPUS=4
50 VM_RAM=8
51 VM_COMPUTES=1
52
53 # Netmap used to map networks to OVS bridge names
54 NET_MAP['admin']="br-admin"
55 NET_MAP['tenant']="br-tenant"
56 NET_MAP['external']="br-external"
57 NET_MAP['storage']="br-storage"
58 NET_MAP['api']="br-api"
59 ext_net_type="interface"
60 ip_address_family=4
61
62 # Libraries
63 lib_files=(
64 $LIB/common-functions.sh
65 $LIB/configure-deps-functions.sh
66 $LIB/parse-functions.sh
67 $LIB/virtual-setup-functions.sh
68 $LIB/undercloud-functions.sh
69 $LIB/overcloud-deploy-functions.sh
70 $LIB/post-install-functions.sh
71 $LIB/utility-functions.sh
72 )
73 for lib_file in ${lib_files[@]}; do
74   if ! source $lib_file; then
75     echo -e "${red}ERROR: Failed to source $lib_file${reset}"
76     exit 1
77   fi
78 done
79
80 display_usage() {
81   echo -e "Usage:\n$0 [arguments] \n"
82   echo -e "   --deploy-settings | -d : Full path to deploy settings yaml file. Optional.  Defaults to null"
83   echo -e "   --inventory | -i : Full path to inventory yaml file. Required only for baremetal"
84   echo -e "   --net-settings | -n : Full path to network settings file. Optional."
85   echo -e "   --ping-site | -p : site to use to verify IP connectivity. Optional. Defaults to 8.8.8.8"
86   echo -e "   --dnslookup-site : site to use to verify DNS resolution. Optional. Defaults to www.google.com"
87   echo -e "   --virtual | -v : Virtualize overcloud nodes instead of using baremetal."
88   echo -e "   --no-post-config : disable Post Install configuration."
89   echo -e "   --debug : enable debug output."
90   echo -e "   --interactive : enable interactive deployment mode which requires user to confirm steps of deployment."
91   echo -e "   --virtual-cpus : Number of CPUs to use per Overcloud VM in a virtual deployment (defaults to 4)."
92   echo -e "   --virtual-computes : Number of Virtual Compute nodes to create and use during deployment (defaults to 1 for noha and 2 for ha)."
93   echo -e "   --virtual-default-ram : Amount of default RAM to use per Overcloud VM in GB (defaults to 8)."
94   echo -e "   --virtual-compute-ram : Amount of RAM to use per Overcloud Compute VM in GB (defaults to 8). Overrides --virtual-default-ram arg for computes"
95 }
96
97 ##translates the command line parameters into variables
98 ##params: $@ the entire command line is passed
99 ##usage: parse_cmd_line() "$@"
100 parse_cmdline() {
101   echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
102   echo "Use -h to display help"
103
104   while [ "${1:0:1}" = "-" ]
105   do
106     case "$1" in
107         -h|--help)
108                 display_usage
109                 exit 0
110             ;;
111         -d|--deploy-settings)
112                 DEPLOY_SETTINGS_FILE=$2
113                 echo "Deployment Configuration file: $2"
114                 shift 2
115             ;;
116         -i|--inventory)
117                 INVENTORY_FILE=$2
118                 shift 2
119             ;;
120         -n|--net-settings)
121                 NETSETS=$2
122                 echo "Network Settings Configuration file: $2"
123                 shift 2
124             ;;
125         -e|--environment-file)
126                 ENV_FILE=$2
127                 echo "Base OOO Environment file: $2"
128                 shift 2
129             ;;
130         -p|--ping-site)
131                 ping_site=$2
132                 echo "Using $2 as the ping site"
133                 shift 2
134             ;;
135         --dnslookup-site)
136                 dnslookup_site=$2
137                 echo "Using $2 as the dnslookup site"
138                 shift 2
139             ;;
140         -v|--virtual)
141                 virtual="TRUE"
142                 echo "Executing a Virtual Deployment"
143                 shift 1
144             ;;
145         --no-post-config )
146                 post_config="FALSE"
147                 echo "Post install configuration disabled"
148                 shift 1
149             ;;
150         --debug )
151                 debug="TRUE"
152                 echo "Enable debug output"
153                 shift 1
154             ;;
155         --interactive )
156                 interactive="TRUE"
157                 echo "Interactive mode enabled"
158                 shift 1
159             ;;
160         --virtual-cpus )
161                 VM_CPUS=$2
162                 echo "Number of CPUs per VM set to $VM_CPUS"
163                 shift 2
164             ;;
165         --virtual-default-ram )
166                 VM_RAM=$2
167                 echo "Amount of Default RAM per VM set to $VM_RAM"
168                 shift 2
169             ;;
170         --virtual-computes )
171                 VM_COMPUTES=$2
172                 echo "Virtual Compute nodes set to $VM_COMPUTES"
173                 shift 2
174             ;;
175         --virtual-compute-ram )
176                 VM_COMPUTE_RAM=$2
177                 echo "Virtual Compute RAM set to $VM_COMPUTE_RAM"
178                 shift 2
179             ;;
180         *)
181                 display_usage
182                 exit 1
183             ;;
184     esac
185   done
186   sleep 2
187
188   if [[ -z "$NETSETS" ]]; then
189     echo -e "${red}ERROR: You must provide a network_settings file with -n.${reset}"
190     exit 1
191   fi
192
193   # inventory file usage validation
194   if [[ -n "$virtual" ]]; then
195       if [[ -n "$INVENTORY_FILE" ]]; then
196           echo -e "${red}ERROR: You should not specify an inventory file with virtual deployments${reset}"
197           exit 1
198       else
199           INVENTORY_FILE="$APEX_TMP_DIR/inventory-virt.yaml"
200       fi
201   elif [[ -z "$INVENTORY_FILE" ]]; then
202     echo -e "${red}ERROR: You must specify an inventory file for baremetal deployments! Exiting...${reset}"
203     exit 1
204   elif [[ ! -f "$INVENTORY_FILE" ]]; then
205     echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
206     exit 1
207   fi
208
209   if [[ -z "$DEPLOY_SETTINGS_FILE" || ! -f "$DEPLOY_SETTINGS_FILE" ]]; then
210     echo -e "${red}ERROR: Deploy Settings: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
211     exit 1
212   fi
213
214   if [[ ! -z "$NETSETS" && ! -f "$NETSETS" ]]; then
215     echo -e "${red}ERROR: Network Settings: ${NETSETS} does not exist! Exiting...${reset}"
216     exit 1
217   fi
218
219 }
220
221 main() {
222   parse_cmdline "$@"
223   if [ -n "$DEPLOY_SETTINGS_FILE" ]; then
224     echo -e "${blue}INFO: Parsing deploy settings file...${reset}"
225     parse_deploy_settings
226   fi
227   echo -e "${blue}INFO: Parsing network settings file...${reset}"
228   parse_network_settings
229   if ! configure_deps; then
230     echo -e "${red}Dependency Validation Failed, Exiting.${reset}"
231     exit 1
232   fi
233   #Correct the time on the server prior to launching any VMs
234   if ntpdate $ntp_server; then
235     hwclock --systohc
236   else
237     echo "${blue}WARNING: ntpdate failed to update the time on the server. ${reset}"
238   fi
239   setup_undercloud_vm
240   if [ "$virtual" == "TRUE" ]; then
241     setup_virtual_baremetal $VM_CPUS $VM_RAM
242   fi
243   parse_inventory_file
244   configure_undercloud
245   overcloud_deploy
246   if [ "$post_config" == "TRUE" ]; then
247     if ! configure_post_install; then
248       echo -e "${red}ERROR:Post Install Configuration Failed, Exiting.${reset}"
249       exit 1
250     else
251       echo -e "${blue}INFO: Post Install Configuration Complete${reset}"
252     fi
253   fi
254 }
255
256 main "$@"