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]]]] \\
38 $(notify "OPTIONS:" 2)
39 -b Base-uri for the stack-configuration structure
40 -B Bridge(s): 1st usage = PXE, 2nd = Mgmt, 3rd = Internal, 4th = Public
41 -h Print this message and exit
44 -s Deploy-scenario short-name
45 -S Storage dir for VM images
47 $(notify "DISABLED OPTIONS (not yet supported with MCP):" 3)
49 -e (disabled) Do not launch environment deployment
50 -f (disabled) Deploy on existing Salt master
51 -F (disabled) Do only create a Salt master
53 -L (disabled) Deployment log path and file name
54 -T (disabled) Timeout, in minutes, for the deploy.
56 $(notify "Description:" 2)
57 Deploys the Fuel@OPNFV stack on the indicated lab resource.
59 This script provides the Fuel@OPNFV deployment abstraction.
60 It depends on the OPNFV official configuration directory/file structure
61 and provides a fairly simple mechanism to execute a deployment.
63 $(notify "Input parameters to the build script are:" 2)
64 -b Base URI to the configuration directory (needs to be provided in a URI
65 style, it can be a local resource: file:// or a remote resource http(s)://)
66 -B Bridges to be used by deploy script. It can be specified several times,
67 or as a comma separated list of bridges, or both: -B br1 -B br2,br3
68 First occurence sets PXE Brige, next Mgmt, then Internal and Public.
69 For an empty value, the deploy script will use virsh to create the default
70 expected network (e.g. -B pxe,,,public will use existing "pxe" and "public"
71 bridges, respectively create "mgmt" and "internal").
72 Note that a virtual network "mcpcontrol" is always created. For virtual
73 deploys, "mcpcontrol" is also used for PXE, leaving the PXE bridge unused.
74 For baremetal deploys, PXE bridge is used for baremetal node provisioning,
75 while "mcpcontrol" is used to provision the infrastructure VMs only.
76 The default is 'pxebr'.
77 -h Print this message and exit
78 -l Lab name as defined in the configuration directory, e.g. lf
79 -p POD name as defined in the configuration directory, e.g. pod-1
80 -s Deployment-scenario, this points to a short deployment scenario name, which
81 has to be defined in config directory (e.g. os-odl_l2-nofeature-noha).
82 -S Storage dir for VM images, default is mcp/deploy/images
84 $(notify "Disabled input parameters (not yet supported with MCP):" 3)
85 -d (disabled) Dry-run - Produce deploy config files, but do not execute deploy
86 -f (disabled) Deploy on existing Salt master
87 -e (disabled) Do not launch environment deployment
88 -F (disabled) Do only create a Salt master
89 -L (disabled) Deployment log path and name, eg. -L /home/jenkins/job.log.tar.gz
90 -T (disabled) Timeout, in minutes, for the deploy.
91 It defaults to using the DEPLOY_TIMEOUT environment variable when defined.
92 -i (disabled) .iso image to be deployed (needs to be provided in a URI
93 style, it can be a local resource: file:// or a remote resource http(s)://)
95 $(notify "[NOTE] sudo & virsh priviledges are needed for this script to run" 3)
99 $(notify "sudo $(basename "$0") \\
100 -b file:///home/jenkins/lab-config \\
102 -s os-odl_l2-nofeature-noha" 2)
107 # END of usage description
108 ##############################################################################
110 ##############################################################################
111 # BEGIN of colored notification wrapper
114 tput setaf "${2:-1}" || true
115 echo -en "${1:-"[WARN] Unsupported opt arg: $3\\n"}"
119 # END of colored notification wrapper
120 ##############################################################################
122 ##############################################################################
123 # BEGIN of deployment clean-up
126 echo "Cleaning up deploy tmp directories"
129 # END of deployment clean-up
130 ##############################################################################
132 ##############################################################################
133 # BEGIN of variables to customize
135 SCRIPT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
136 DEPLOY_DIR=$(cd "${SCRIPT_PATH}/../mcp/scripts"; pwd)
137 STORAGE_DIR=$(cd "${SCRIPT_PATH}/../mcp/deploy/images"; pwd)
138 DEPLOY_TYPE='baremetal'
139 OPNFV_BRIDGES=('pxebr' 'mgmt' 'internal' 'public')
140 URI_REGEXP='(file|https?|ftp)://.*'
142 # NOTE: When this script runs with sudo, key will land in /root/opnfv/mcp.rsa,
143 # unless SSH_KEY is set to point to non-root user's home (e.g. via env var).
144 export SSH_KEY=${SSH_KEY:-"${HOME}/opnfv/mcp.rsa"}
145 export SALT_MASTER=${SALT_MASTER_IP:-192.168.10.100}
146 export MAAS_IP=${MAAS_IP:-192.168.10.3}
147 export SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${SSH_KEY}"
149 # Variables below are disabled for now, to be re-introduced or removed later
152 FUEL_CREATION_ONLY=''
153 NO_DEPLOY_ENVIRONMENT=''
155 if ! [ -z "${DEPLOY_TIMEOUT}" ]; then
156 DEPLOY_TIMEOUT="-dt ${DEPLOY_TIMEOUT}"
162 # END of variables to customize
163 ##############################################################################
165 ##############################################################################
170 while getopts "b:B:dfFl:L:p:s:S:T:i:he" OPTION
174 BASE_CONFIG_URI=${OPTARG}
175 if [[ ! $BASE_CONFIG_URI =~ ${URI_REGEXP} ]]; then
176 notify "[ERROR] -b $BASE_CONFIG_URI - invalid URI\n"
184 OPT_BRIDGES=($OPTARG)
185 for bridge in "${OPT_BRIDGES[@]}"; do
186 if [ -n "${bridge}" ]; then
187 OPNFV_BRIDGES[${OPNFV_BRIDGE_IDX}]="${bridge}"
189 OPNFV_BRIDGE_IDX=$[OPNFV_BRIDGE_IDX + 1]
194 notify '' 3 "${OPTION}"; continue
198 notify '' 3 "${OPTION}"; continue
199 USE_EXISTING_FUEL='-nf'
202 notify '' 3 "${OPTION}"; continue
203 FUEL_CREATION_ONLY='-fo'
206 notify '' 3 "${OPTION}"; continue
207 NO_DEPLOY_ENVIRONMENT='-nde'
213 notify '' 3 "${OPTION}"; continue
214 DEPLOY_LOG="-log ${OPTARG}"
218 if [[ "${TARGET_POD}" =~ "virtual" ]]; then
219 DEPLOY_TYPE='virtual'
223 DEPLOY_SCENARIO=${OPTARG}
226 if [[ ${OPTARG} ]]; then
227 STORAGE_DIR="-s ${OPTARG}"
231 notify '' 3 "${OPTION}"; continue
232 DEPLOY_TIMEOUT="-dt ${OPTARG}"
235 notify '' 3 "${OPTION}"; continue
237 if [[ ! $ISO =~ ${URI_REGEXP} ]]; then
238 notify "[ERROR] -i $ISO - invalid URI\n"
248 notify "[ERROR] Arguments not according to new argument style\n"
254 if [[ "$(sudo whoami)" != 'root' ]]; then
255 notify "This script requires sudo rights\n" 1>&2
259 if ! virsh list >/dev/null 2>&1; then
260 notify "This script requires hypervisor access\n" 1>&2
264 # Validate mandatory arguments are set
265 # FIXME(armband): Bring back support for BASE_CONFIG_URI
266 if [ -z "${TARGET_LAB}" ] || [ -z "${TARGET_POD}" ] || \
267 [ -z "${DEPLOY_SCENARIO}" ]; then
268 notify "[ERROR] At least one of the mandatory args is missing!\n" 1>&2
275 # Enable the automatic exit trap
276 trap do_exit SIGINT SIGTERM EXIT
278 # Set no restrictive umask so that Jenkins can removeeee any residuals
283 pushd "${DEPLOY_DIR}" > /dev/null
284 # Prepare the deploy config files based on lab/pod information, deployment
287 # Install required packages
288 [ -n "$(command -v apt-get)" ] && sudo apt-get install -y \
289 git make rsync mkisofs curl virtinst cpu-checker qemu-kvm
290 [ -n "$(command -v yum)" ] && sudo yum install -y --skip-broken \
291 git make rsync genisoimage curl virt-install qemu-kvm
293 if [ "$(uname -i)" = "aarch64" ]; then
294 [ -n "$(command -v apt-get)" ] && sudo apt-get install -y vgabios && \
295 sudo ln -sf /usr/share/vgabios/vgabios.bin /usr/share/qemu/vgabios-stdvga.bin
296 [ -n "$(command -v yum)" ] && sudo yum install -y --skip-broken vgabios
299 # Check scenario file existence
300 if [ ! -f "../config/scenario/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml" ]; then
301 notify "[WARN] ${DEPLOY_SCENARIO}.yaml not found! \
302 Setting simplest scenario (os-nosdn-nofeature-noha)\n" 3
303 DEPLOY_SCENARIO='os-nosdn-nofeature-noha'
304 if [ ! -f "../config/scenario/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml" ]; then
305 notify "[ERROR] Scenario definition file is missing!\n" 1>&2
310 # Get required infra deployment data
312 eval "$(parse_yaml "../config/scenario/${DEPLOY_TYPE}/defaults.yaml")"
313 eval "$(parse_yaml "../config/scenario/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml")"
315 export CLUSTER_DOMAIN=${cluster_domain}
317 declare -A virtual_nodes_ram virtual_nodes_vcpus
318 for node in "${virtual_nodes[@]}"; do
319 virtual_custom_ram="virtual_${node}_ram"
320 virtual_custom_vcpus="virtual_${node}_vcpus"
321 virtual_nodes_ram[$node]=${!virtual_custom_ram:-$virtual_default_ram}
322 virtual_nodes_vcpus[$node]=${!virtual_custom_vcpus:-$virtual_default_vcpus}
327 prepare_vms virtual_nodes "${base_image}" "${STORAGE_DIR}"
328 create_networks OPNFV_BRIDGES
329 create_vms virtual_nodes virtual_nodes_ram virtual_nodes_vcpus \
330 OPNFV_BRIDGES "${STORAGE_DIR}"
331 update_mcpcontrol_network
332 start_vms virtual_nodes
337 # Openstack cluster setup
338 for state in "${cluster_states[@]}"; do
339 notify "STATE: ${state}\n" 2
340 # shellcheck disable=SC2086,2029
341 ssh ${SSH_OPTS} "ubuntu@${SALT_MASTER}" \
342 sudo "/root/fuel/mcp/config/states/${state} || true"
349 ##############################################################################