Small fixes to the deployment scenario framework:
[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 -l lab-name -p pod-name -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   -d  Dry-run
39
40   -l  Lab-name
41   -p  Pod-name
42   -s  Deploy-scenario short-name/base-file-name
43   -i  iso url
44
45 Description:
46 Deploys the Fuel@OPNFV stack on the indicated lab resource
47
48 This script provides the Fuel@OPNFV deployment abstraction
49 It depends on the OPNFV official configuration directory/file structure
50 and provides a fairly simple mechanism to execute a deployment.
51 Input parameters to the build script is:
52 -b Base URI to the configuration directory (needs to be provided in a URI
53    style, it can be a local resource: file:// or a remote resource http(s)://)
54 -d Dry-run - - Produces deploy config files (config/dea.yaml and
55    config/dha.yaml), but does not execute deploy
56 -l Lab name as defined in the configuration directory, e.g. lf
57 -p POD name as defined in the configuration directory, e.g. pod-1
58 -s Deployment-scenario, this points to a deployment/test scenario file as
59    defined in the configuration directory:
60    e.g fuel-ocl-heat-ceilometer_scenario_0.0.1.yaml
61    or a deployment short-name as defined by scenario.yaml in the deployment
62    scenario path.
63 -i .iso image to be deployed (needs to be provided in a URI
64    style, it can be a local resource: file:// or a remote resource http(s)://)
65
66 NOTE: Root priviledges are needed for this script to run
67
68
69 Examples:
70 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
71 EOF
72 }
73
74 #
75 # END of usage description
76 ############################################################################
77
78 ############################################################################
79 # BEGIN of deployment clean-up
80 #
81 clean() {
82     echo "Cleaning up deploy tmp directories"
83     rm -rf ${SCRIPT_PATH}/ISO
84 }
85 #
86 # END of deployment clean-up
87 ############################################################################
88
89 ############################################################################
90 # BEGIN of shorthand variables for internal use
91 #
92 SCRIPT_PATH=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
93 DEPLOY_DIR=$(cd ${SCRIPT_PATH}/../deploy; pwd)
94 DRY_RUN=0
95 #
96 # END of variables to customize
97 ############################################################################
98
99 ############################################################################
100 # BEGIN of main
101 #
102 while getopts "b:dl:p:s:i:h" OPTION
103 do
104     case $OPTION in
105         b)
106             BASE_CONFIG_URI=${OPTARG}
107             ;;
108         d)
109             DRY_RUN=1
110             ;;
111         l)
112             TARGET_LAB=${OPTARG}
113             ;;
114         p)
115             TARGET_POD=${OPTARG}
116             ;;
117         s)
118             DEPLOY_SCENARIO=${OPTARG}
119             ;;
120         i)
121             ISO=${OPTARG}
122             ;;
123         h)
124             usage
125             exit 0
126             ;;
127         *)
128             echo "${OPTION} is not a valid argument"
129             echo "Arguments not according to new argument style"
130             echo "Trying old-style compatibility mode"
131             pushd ${DEPLOY_DIR} > /dev/null
132             python deploy.py "$@"
133             popd > /dev/null
134             exit 0
135             ;;
136     esac
137 done
138
139 if [[ $EUID -ne 0 ]]; then
140    echo "This script must be run as root" 1>&2
141    exit 1
142 fi
143
144 if [ -z $BASE_CONFIG_URI ] || [ -z $TARGET_LAB ] || \
145    [ -z $TARGET_POD ] || [ -z $DEPLOY_SCENARIO ] || \
146    [ -z $ISO ]; then
147     echo "Arguments not according to new argument style"
148     echo "Trying old-style compatibility mode"
149     pushd ${DEPLOY_DIR} > /dev/null
150     python deploy.py "$@"
151     popd > /dev/null
152     exit 0
153 fi
154
155 # Enable the automatic exit trap
156 trap do_exit SIGINT SIGTERM EXIT
157
158 # Set no restrictive umask so that Jenkins can removeeee any residuals
159 umask 0000
160
161 clean
162
163 pushd ${DEPLOY_DIR} > /dev/null
164 # Prepare the deploy config files based on lab/pod information, deployment
165 # scenario, etc.
166
167 echo "python deploy-config.py -dha ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dha.yaml -deab ${DEPLOY_DIR}/config/dea_base.yaml -deao ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dea-pod-override.yaml -scenario-base-uri ${DEPLOY_DIR}/scenario -scenario ${DEPLOY_SCENARIO} -plugins ${DEPLOY_DIR}/config/plugins -output ${SCRIPT_PATH}/config"
168
169
170 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
171
172 if [ $DRY_RUN -eq 0 ]; then
173     # Download iso if it doesn't already exists locally
174     if [[ $ISO == file://* ]]; then
175         ISO=${ISO#file://}
176     else
177         mkdir -p ${SCRIPT_PATH}/ISO
178         curl -o ${SCRIPT_PATH}/ISO/image.iso $ISO
179         ISO=${SCRIPT_PATH}/ISO/image.iso
180     fi
181     # Start deployment
182     echo "python deploy.py -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO"
183     python deploy.py -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO
184 fi
185 popd > /dev/null
186
187 #
188 # END of main
189 ############################################################################