ODL build: Allow customizing JAVA URL
[fuel.git] / ci / deploy.sh
1 #!/bin/bash
2 set -e
3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 ############################################################################
13 # BEGIN of Exit handlers
14 #
15 do_exit () {
16     clean
17     echo "Exiting ..."
18 }
19 #
20 # End of Exit handlers
21 ############################################################################
22
23 ############################################################################
24 # BEGIN of usage description
25 #
26 usage ()
27 {
28 cat << EOF
29 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
30 `basename $0`: Deploys the Fuel@OPNFV stack
31
32 usage: `basename $0` -b base-uri [-B PXE Bridge] [-f] [-F] [-H] -l lab-name -p pod-name -s deploy-scenario [-S image-dir] -i iso
33        -s deployment-scenario [-S optional Deploy-scenario path URI]
34        [-R optional local relen repo (containing deployment Scenarios]
35
36 OPTIONS:
37   -b  Base-uri for the stack-configuration structure
38   -B  PXE Bridge for booting of Fuel master
39   -d  Dry-run
40   -f  Deploy on existing Fuel master
41   -e  Do not launch environment deployment
42   -F  Do only create a Fuel master
43   -h  Print this message and exit
44   -H  No health check
45   -l  Lab-name
46   -p  Pod-name
47   -s  Deploy-scenario short-name/base-file-name
48   -S  Storage dir for VM images
49   -i  iso url
50
51 Description:
52 Deploys the Fuel@OPNFV stack on the indicated lab resource
53
54 This script provides the Fuel@OPNFV deployment abstraction
55 It depends on the OPNFV official configuration directory/file structure
56 and provides a fairly simple mechanism to execute a deployment.
57 Input parameters to the build script is:
58 -b Base URI to the configuration directory (needs to be provided in a URI
59    style, it can be a local resource: file:// or a remote resource http(s)://)
60 -B PXE Bridge for booting of Fuel master, default is pxebr
61 -d Dry-run - Produces deploy config files (config/dea.yaml and
62    config/dha.yaml), but does not execute deploy
63 -f Deploy on existing Fuel master
64 -e Do not launch environment deployment
65 -F Do only create a Fuel master
66 -h Print this message and exit
67 -H Do not run fuel built in health-check after successfull deployment
68 -l Lab name as defined in the configuration directory, e.g. lf
69 -p POD name as defined in the configuration directory, e.g. pod-1
70 -s Deployment-scenario, this points to a deployment/test scenario file as
71    defined in the configuration directory:
72    e.g fuel-ocl-heat-ceilometer_scenario_0.0.1.yaml
73    or a deployment short-name as defined by scenario.yaml in the deployment
74    scenario path.
75 -S Storage dir for VM images, default is fuel/deploy/images
76 -i .iso image to be deployed (needs to be provided in a URI
77    style, it can be a local resource: file:// or a remote resource http(s)://)
78
79 NOTE: Root priviledges are needed for this script to run
80
81
82 Examples:
83 sudo `basename $0` -b file:///home/jenkins/lab-config -l lf -p pod1 -s ha_odl-l3_heat_ceilometer -i file:///home/jenkins/myiso.iso
84 EOF
85 }
86
87 #
88 # END of usage description
89 ############################################################################
90
91 ############################################################################
92 # BEGIN of deployment clean-up
93 #
94 clean() {
95     echo "Cleaning up deploy tmp directories"
96     rm -rf ${SCRIPT_PATH}/ISO
97 }
98 #
99 # END of deployment clean-up
100 ############################################################################
101
102 ############################################################################
103 # BEGIN of shorthand variables for internal use
104 #
105 SCRIPT_PATH=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
106 DEPLOY_DIR=$(cd ${SCRIPT_PATH}/../deploy; pwd)
107 PXE_BRIDGE=''
108 NO_HEALTH_CHECK=''
109 USE_EXISTING_FUEL=''
110 FUEL_CREATION_ONLY=''
111 NO_DEPLOY_ENVIRONMENT=''
112 STORAGE_DIR=''
113 DRY_RUN=0
114 #
115 # END of variables to customize
116 ############################################################################
117
118 ############################################################################
119 # BEGIN of main
120 #
121 while getopts "b:B:dfFHl:p:s:S:i:he" OPTION
122 do
123     case $OPTION in
124         b)
125             BASE_CONFIG_URI=${OPTARG}
126             if [[ ! $BASE_CONFIG_URI == file://* ]] && \
127                [[ ! $BASE_CONFIG_URI == http://* ]] && \
128                [[ ! $BASE_CONFIG_URI == https://* ]] && \
129                [[ ! $BASE_CONFIG_URI == ftp://* ]]; then
130                 echo "-b $BASE_CONFIG_URI - Not given in URI style"
131                 usage
132                 exit 1
133             fi
134             ;;
135         B)
136             if [[ ${OPTARG} ]]; then
137                 PXE_BRIDGE="-b ${OPTARG}"
138             fi
139             ;;
140         d)
141             DRY_RUN=1
142             ;;
143         f)
144             USE_EXISTING_FUEL='-nf'
145             ;;
146         F)
147             FUEL_CREATION_ONLY='-fo'
148             ;;
149         e)
150             NO_DEPLOY_ENVIRONMENT='-nde'
151             ;;
152         H)
153             NO_HEALTH_CHECK='-nh'
154             ;;
155         l)
156             TARGET_LAB=${OPTARG}
157             ;;
158         p)
159             TARGET_POD=${OPTARG}
160             ;;
161         s)
162             DEPLOY_SCENARIO=${OPTARG}
163             ;;
164         S)
165             if [[ ${OPTARG} ]]; then
166                 STORAGE_DIR="-s ${OPTARG}"
167             fi
168             ;;
169         i)
170             ISO=${OPTARG}
171             if [[ ! $ISO == file://* ]] && \
172                [[ ! $ISO == http://* ]] && \
173                [[ ! $ISO == https://* ]] && \
174                [[ ! $ISO == ftp://* ]]; then
175                 echo "-i $ISO - Not given in URI style"
176                 usage
177                 exit 1
178             fi
179             ;;
180         h)
181             usage
182             exit 0
183             ;;
184         *)
185             echo "${OPTION} is not a valid argument"
186             echo "Arguments not according to new argument style"
187             echo "Trying old-style compatibility mode"
188             pushd ${DEPLOY_DIR} > /dev/null
189             python deploy.py "$@"
190             popd > /dev/null
191             exit 0
192             ;;
193     esac
194 done
195
196 if [[ $EUID -ne 0 ]]; then
197     echo "This script must be run as root" 1>&2
198     exit 1
199 fi
200
201 if [ -z $BASE_CONFIG_URI ] || [ -z $TARGET_LAB ] || \
202    [ -z $TARGET_POD ] || [ -z $DEPLOY_SCENARIO ] || \
203    [ -z $ISO ]; then
204     echo "Arguments not according to new argument style"
205     echo "Trying old-style compatibility mode"
206     pushd ${DEPLOY_DIR} > /dev/null
207     python deploy.py "$@"
208     popd > /dev/null
209     exit 0
210 fi
211
212 # Enable the automatic exit trap
213 trap do_exit SIGINT SIGTERM EXIT
214
215 # Set no restrictive umask so that Jenkins can removeeee any residuals
216 umask 0000
217
218 clean
219
220 pushd ${DEPLOY_DIR} > /dev/null
221 # Prepare the deploy config files based on lab/pod information, deployment
222 # scenario, etc.
223
224 echo "python deploy-config.py -dha ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dha.yaml -deab file://${DEPLOY_DIR}/config/dea_base.yaml -deao ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dea-pod-override.yaml -scenario-base-uri file://${DEPLOY_DIR}/scenario -scenario ${DEPLOY_SCENARIO} -plugins file://${DEPLOY_DIR}/config/plugins -output ${SCRIPT_PATH}/config"
225
226 python deploy-config.py -dha ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dha.yaml -deab file://${DEPLOY_DIR}/config/dea_base.yaml -deao ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dea-pod-override.yaml -scenario-base-uri file://${DEPLOY_DIR}/scenario -scenario ${DEPLOY_SCENARIO} -plugins file://${DEPLOY_DIR}/config/plugins -output ${SCRIPT_PATH}/config
227
228 if [ $DRY_RUN -eq 0 ]; then
229     # Download iso if it doesn't already exists locally
230     if [[ $ISO == file://* ]]; then
231         ISO=${ISO#file://}
232     else
233         mkdir -p ${SCRIPT_PATH}/ISO
234         curl -o ${SCRIPT_PATH}/ISO/image.iso $ISO
235         ISO=${SCRIPT_PATH}/ISO/image.iso
236     fi
237     # Start deployment
238     echo "python deploy.py $STORAGE_DIR $PXE_BRIDGE $USE_EXISTING_FUEL $FUEL_CREATION_ONLY $NO_HEALTH_CHECK $NO_DEPLOY_ENVIRONMENT -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO"
239     python deploy.py $STORAGE_DIR $PXE_BRIDGE $USE_EXISTING_FUEL $FUEL_CREATION_ONLY $NO_HEALTH_CHECK $NO_DEPLOY_ENVIRONMENT -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO
240 fi
241 popd > /dev/null
242
243 #
244 # END of main
245 ############################################################################