A simple method to separate configuration for base fuel, plugins, PODs
[fuel.git] / ci / deploy.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # jonas.bjurel@ericsson.com
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 ############################################################################
12 # BEGIN of Exit handlers
13 #
14 do_exit () {
15     clean
16     echo "Exiting ..."
17 }
18 #
19 # End of Exit handlers
20 ############################################################################
21
22 ############################################################################
23 # BEGIN of usage description
24 #
25 usage ()
26 {
27 cat << EOF
28 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
29 `basename $0`: Deploys the Fuel@OPNFV stack
30
31 usage: `basename $0` -b base-uri -l lab-name -p pod-name -i iso
32        -s deployment-scenario [-S optional Deploy-scenario path URI]
33        [-R optional local relen repo (containing deployment Scenarios]
34
35 OPTIONS:
36   -b  Base-uri for the stack-configuration structure
37   -l  Lab-name
38   -p  Pod-name
39   -s  Deploy-scenario short-name/base-file-name
40   -i  iso url
41
42 Description:
43 Deploys the Fuel@OPNFV stack on the indicated lab resource
44
45 This script provides the Fuel@OPNFV deployment abstraction
46 It depends on the OPNFV official configuration directory/file structure
47 and provides a fairly simple mechanism to execute a deployment.
48 Input parameters to the build script is:
49 -b Base URI to the configuration directory (needs to be provided in a URI
50    style, it can be a local resource: file:// or a remote resource http(s)://)
51 -l Lab name as defined in the configuration directory, e.g. lf
52 -p POD name as defined in the configuration directory, e.g. pod-1
53 -s Deployment-scenario, this points to a deployment/test scenario file as
54    defined in the configuration directory:
55    e.g fuel-ocl-heat-ceilometer_scenario_0.0.1.yaml
56    or a deployment short-name as defined by scenario.yaml in the deployment
57    scenario path.
58 -i .iso image to be deployed (needs to be provided in a URI
59    style, it can be a local resource: file:// or a remote resource http(s)://)
60
61 NOTE: Root priviledges are needed for this script to run
62
63 Examples:
64 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
65 EOF
66 }
67
68 #
69 # END of usage description
70 ############################################################################
71
72 ############################################################################
73 # BEGIN of deployment clean-up
74 #
75 clean() {
76     echo "Cleaning up deploy tmp directories"
77     rm -rf ${SCRIPT_PATH}/config
78     rm -rf ${SCRIPT_PATH}/ISO
79     rm -rf ${SCRIPT_PATH}/releng
80 }
81 #
82 # END of deployment clean-up
83 ############################################################################
84
85 ############################################################################
86 # BEGIN of shorthand variables for internal use
87 #
88 SCRIPT_PATH=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
89 DEPLOY_DIR=$(cd ${SCRIPT_PATH}/../deploy; pwd)
90 RELENG_REPO=https://jonasbjurel@gerrit.opnfv.org/gerrit/releng
91 #
92 # END of variables to customize
93 ############################################################################
94
95 ############################################################################
96 # BEGIN of main
97 #
98 while getopts "b:l:p:s:i:h" OPTION
99 do
100     case $OPTION in
101         b)
102             BASE_CONFIG_URI=${OPTARG}
103             ;;
104         l)
105             TARGET_LAB=${OPTARG}
106             ;;
107         p)
108             TARGET_POD=${OPTARG}
109             ;;
110         s)
111             DEPLOY_SCENARIO=${OPTARG}
112             ;;
113         i)
114             ISO=${OPTARG}
115             ;;
116         h)
117             usage
118             exit 0
119             ;;
120         *)
121             echo "${OPTION} is not a valid argument"
122             echo "Arguments not according to new argument style"
123             echo "Trying old-style compatibility mode"
124             pushd ${DEPLOY_DIR} > /dev/null
125             python deploy.py "$@"
126             popd > /dev/null
127             exit 0
128             ;;
129     esac
130 done
131
132 if [[ $EUID -ne 0 ]]; then
133    echo "This script must be run as root" 1>&2
134    exit 1
135 fi
136
137 if [ -z $BASE_CONFIG_URI ] || [ -z $TARGET_LAB ] || \
138    [ -z $TARGET_POD ] || [ -z $DEPLOY_SCENARIO ] || \
139    [ -z $ISO ]; then
140     echo "Arguments not according to new argument style"
141     echo "Trying old-style compatibility mode"
142     pushd ${DEPLOY_DIR} > /dev/null
143     python deploy.py "$@"
144     popd > /dev/null
145     exit 0
146 fi
147
148 # Enable the automatic exit trap
149 set -o errexit
150 trap do_exit SIGINT SIGTERM EXIT
151
152 clean
153
154 pushd ${DEPLOY_DIR} > /dev/null
155 # Prepare the deploy config files based on lab/pod information, deployment
156 # scenario, etc.
157
158 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"
159
160 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
161
162 # Download iso if it doesn't already exists locally
163 if [[ $ISO == file://* ]]; then
164     ISO=${ISO#file://}
165 else
166     mkdir -p ${SCRIPT_PATH}/ISO
167     curl -o ${SCRIPT_PATH}/ISO/image.iso $ISO
168     ISO=${SCRIPT_PATH}/ISO/image.iso
169 fi
170 # Start deployment
171 echo "python deploy.py -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO"
172 python deploy.py -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO
173 popd > /dev/null
174
175 # TBD: Upload the test-section of the scenario yaml file to the fuel master:
176 # var/www/test.yaml
177
178 #
179 # END of main
180 ############################################################################