2 # shellcheck disable=SC2034,SC2154,SC1091
4 ##############################################################################
5 # Copyright (c) 2017 Ericsson AB, Mirantis Inc., Enea AB and others.
6 # jonas.bjurel@ericsson.com
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Apache License, Version 2.0
9 # which accompanies this distribution, and is available at
10 # http://www.apache.org/licenses/LICENSE-2.0
11 ##############################################################################
13 ##############################################################################
14 # BEGIN of Exit handlers
21 # End of Exit handlers
22 ##############################################################################
24 ##############################################################################
25 # BEGIN of usage description
30 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
31 $(notify "$(basename "$0"): Deploy the Fuel@OPNFV MCP stack" 3)
34 $(basename "$0") -b base-uri -l lab-name -p pod-name -s deploy-scenario \\
35 [-B PXE Bridge [-B Mgmt Bridge [-B Internal Bridge [-B Public Bridge]]]]
37 $(notify "OPTIONS:" 2)
38 -b Base-uri for the stack-configuration structure
39 -B Bridge(s): 1st usage = PXE, 2nd = Mgmt, 3rd = Internal, 4th = Public
40 -h Print this message and exit
43 -s Deploy-scenario short-name
45 $(notify "DISABLED OPTIONS (not yet supported with MCP):" 3)
47 -e (disabled) Do not launch environment deployment
48 -f (disabled) Deploy on existing Salt master
49 -F (disabled) Do only create a Salt master
51 -L (disabled) Deployment log path and file name
52 -S (disabled) Storage dir for VM images
53 -T (disabled) Timeout, in minutes, for the deploy.
55 $(notify "Description:" 2)
56 Deploys the Fuel@OPNFV stack on the indicated lab resource.
58 This script provides the Fuel@OPNFV deployment abstraction.
59 It depends on the OPNFV official configuration directory/file structure
60 and provides a fairly simple mechanism to execute a deployment.
62 $(notify "Input parameters to the build script are:" 2)
63 -b Base URI to the configuration directory (needs to be provided in a URI
64 style, it can be a local resource: file:// or a remote resource http(s)://)
65 -B Bridges to be used by deploy script. It can be specified several times,
66 or as a comma separated list of bridges, or both: -B br1 -B br2,br3
67 First occurence sets PXE Brige, next Mgmt, then Internal and Public.
68 For an empty value, the deploy script will use virsh to create the default
69 expected network (e.g. -B pxe,,,public will use existing "pxe" and "public"
70 bridges, respectively create "mgmt" and "internal").
72 -h Print this message and exit
73 -l Lab name as defined in the configuration directory, e.g. lf
74 -p POD name as defined in the configuration directory, e.g. pod-1
75 -s Deployment-scenario, this points to a short deployment scenario name, which
76 has to be defined in config directory (e.g. os-odl_l2-nofeature-noha).
78 $(notify "Disabled input parameters (not yet supported with MCP):" 3)
79 -d (disabled) Dry-run - Produce deploy config files, but do not execute deploy
80 -f (disabled) Deploy on existing Salt master
81 -e (disabled) Do not launch environment deployment
82 -F (disabled) Do only create a Salt master
83 -L (disabled) Deployment log path and name, eg. -L /home/jenkins/job.log.tar.gz
84 -S (disabled) Storage dir for VM images, default is fuel/deploy/images
85 -T (disabled) Timeout, in minutes, for the deploy.
86 It defaults to using the DEPLOY_TIMEOUT environment variable when defined.
87 -i (disabled) .iso image to be deployed (needs to be provided in a URI
88 style, it can be a local resource: file:// or a remote resource http(s)://)
90 $(notify "[NOTE] Root priviledges are needed for this script to run" 3)
94 $(notify "sudo $(basename "$0") \\
95 -b file:///home/jenkins/lab-config \\
97 -s os-odl_l2-nofeature-noha" 2)
102 # END of usage description
103 ##############################################################################
105 ##############################################################################
106 # BEGIN of colored notification wrapper
109 tput setaf "${2:-1}" || true
110 echo -en "${1:-"[WARN] Unsupported opt arg: $3\\n"}"
114 # END of colored notification wrapper
115 ##############################################################################
117 ##############################################################################
118 # BEGIN of deployment clean-up
121 echo "Cleaning up deploy tmp directories"
124 # END of deployment clean-up
125 ##############################################################################
127 ##############################################################################
128 # BEGIN of variables to customize
130 SCRIPT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
131 DEPLOY_DIR=$(cd "${SCRIPT_PATH}/../mcp/scripts"; pwd)
132 OPNFV_BRIDGES=('pxe' 'mgmt' 'internal' 'public')
133 URI_REGEXP='(file|https?|ftp)://.*'
135 export SSH_KEY=${SSH_KEY:-mcp.rsa}
136 export SALT_MASTER=${SALT_MASTER_IP:-192.168.10.100}
137 export SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${SSH_KEY}"
139 # Variables below are disabled for now, to be re-introduced or removed later
142 FUEL_CREATION_ONLY=''
143 NO_DEPLOY_ENVIRONMENT=''
146 if ! [ -z "${DEPLOY_TIMEOUT}" ]; then
147 DEPLOY_TIMEOUT="-dt ${DEPLOY_TIMEOUT}"
153 # END of variables to customize
154 ##############################################################################
156 ##############################################################################
161 while getopts "b:B:dfFl:L:p:s:S:T:i:he" OPTION
165 BASE_CONFIG_URI=${OPTARG}
166 if [[ ! $BASE_CONFIG_URI =~ ${URI_REGEXP} ]]; then
167 notify "[ERROR] -b $BASE_CONFIG_URI - invalid URI\n"
175 OPT_BRIDGES=($OPTARG)
176 for bridge in "${OPT_BRIDGES[@]}"; do
177 if [ -n "${bridge}" ]; then
178 OPNFV_BRIDGES[${OPNFV_BRIDGE_IDX}]="${bridge}"
180 OPNFV_BRIDGE_IDX=$[OPNFV_BRIDGE_IDX + 1]
185 notify '' 3 "${OPTION}"; continue
189 notify '' 3 "${OPTION}"; continue
190 USE_EXISTING_FUEL='-nf'
193 notify '' 3 "${OPTION}"; continue
194 FUEL_CREATION_ONLY='-fo'
197 notify '' 3 "${OPTION}"; continue
198 NO_DEPLOY_ENVIRONMENT='-nde'
204 notify '' 3 "${OPTION}"; continue
205 DEPLOY_LOG="-log ${OPTARG}"
211 DEPLOY_SCENARIO=${OPTARG}
214 notify '' 3 "${OPTION}"; continue
215 if [[ ${OPTARG} ]]; then
216 STORAGE_DIR="-s ${OPTARG}"
220 notify '' 3 "${OPTION}"; continue
221 DEPLOY_TIMEOUT="-dt ${OPTARG}"
224 notify '' 3 "${OPTION}"; continue
226 if [[ ! $ISO =~ ${URI_REGEXP} ]]; then
227 notify "[ERROR] -i $ISO - invalid URI\n"
237 notify "[ERROR] Arguments not according to new argument style\n"
243 if [[ $EUID -ne 0 ]]; then
244 notify "[ERROR] This script must be run as root\n" 1>&2
248 # Validate mandatory arguments are set
249 # FIXME(armband): Bring back support for BASE_CONFIG_URI
250 if [ -z "${TARGET_LAB}" ] || [ -z "${TARGET_POD}" ] || \
251 [ -z "${DEPLOY_SCENARIO}" ]; then
252 notify "[ERROR] At least one of the mandatory args is missing!\n" 1>&2
259 # Enable the automatic exit trap
260 trap do_exit SIGINT SIGTERM EXIT
262 # Set no restrictive umask so that Jenkins can removeeee any residuals
267 pushd "${DEPLOY_DIR}" > /dev/null
268 # Prepare the deploy config files based on lab/pod information, deployment
271 # Install required packages
272 [ -n "$(command -v apt-get)" ] && apt-get install -y \
273 git make rsync mkisofs curl virtinst cpu-checker qemu-kvm
274 [ -n "$(command -v yum)" ] && yum install -y \
275 git make rsync genisoimage curl virt-install qemu-kvm
277 # Check scenario file existence
278 if [[ ! -f ../config/${DEPLOY_SCENARIO}.yaml ]]; then
279 notify "[WARN] ${DEPLOY_SCENARIO}.yaml not found! \
280 Setting simplest scenario (os-nosdn-nofeature-noha)\n" 3
281 DEPLOY_SCENARIO='os-nosdn-nofeature-noha'
284 # Get required infra deployment data
286 eval "$(parse_yaml "../config/defaults.yaml")"
287 eval "$(parse_yaml "../config/${DEPLOY_SCENARIO}.yaml")"
289 export CLUSTER_DOMAIN=${cluster_domain}
291 declare -A virtual_nodes_ram virtual_nodes_vcpus
292 for node in "${virtual_nodes[@]}"; do
293 virtual_custom_ram="virtual_${node}_ram"
294 virtual_custom_vcpus="virtual_${node}_vcpus"
295 virtual_nodes_ram[$node]=${!virtual_custom_ram:-$virtual_default_ram}
296 virtual_nodes_vcpus[$node]=${!virtual_custom_vcpus:-$virtual_default_vcpus}
301 prepare_vms virtual_nodes "${base_image}"
302 create_networks OPNFV_BRIDGES
303 create_vms virtual_nodes virtual_nodes_ram virtual_nodes_vcpus OPNFV_BRIDGES
304 update_pxe_network OPNFV_BRIDGES
305 start_vms virtual_nodes
310 # Openstack cluster setup
311 for state in "${cluster_states[@]}"; do
312 notify "STATE: ${state}\n" 2
313 # shellcheck disable=SC2086,2029
314 ssh ${SSH_OPTS} "ubuntu@${SALT_MASTER}" \
315 sudo "/root/fuel/mcp/config/states/${state}"
322 ##############################################################################