2 # shellcheck disable=SC2034,SC2154,SC1090,SC1091
3 ##############################################################################
4 # Copyright (c) 2017 Ericsson AB, Mirantis Inc., Enea 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 ##############################################################################
12 ##############################################################################
13 # BEGIN of Exit handlers
17 cleanup_mounts > /dev/null 2>&1
18 if [ ${RC} -eq 0 ]; then
19 notify "\n[OK] MCP: Openstack installation finished succesfully!\n\n" 2
21 notify "\n[ERROR] MCP: Openstack installation threw a fatal error!\n\n"
25 # End of Exit handlers
26 ##############################################################################
28 ##############################################################################
29 # BEGIN of usage description
34 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
35 $(notify "$(basename "$0"): Deploy the Fuel@OPNFV MCP stack" 3)
38 $(basename "$0") -l lab-name -p pod-name -s deploy-scenario \\
39 [-b Lab Config Base URI] \\
40 [-B PXE Bridge [-B Mgmt Bridge [-B Internal Bridge [-B Public Bridge]]]] \\
41 [-S storage-dir] [-L /path/to/log/file.tar.gz] \\
42 [-f[f]] [-F] [-e | -E[E]] [-d] [-D]
44 $(notify "OPTIONS:" 2)
45 -b Base-uri for the stack-configuration structure
46 -B Bridge(s): 1st usage = PXE, 2nd = Mgmt, 3rd = Internal, 4th = Public
49 -e Do not launch environment deployment
50 -E Remove existing VCP VMs (use twice to redeploy baremetal nodes)
51 -f Deploy on existing Salt master (use twice to also skip config sync)
52 -F Do only create a Salt master
53 -h Print this message and exit
56 -P Skip installation of package dependencies
57 -s Deploy-scenario short-name
58 -S Storage dir for VM images
59 -L Deployment log path and file name
61 $(notify "Description:" 2)
62 Deploys the Fuel@OPNFV stack on the indicated lab resource.
64 This script provides the Fuel@OPNFV deployment abstraction.
65 It depends on the OPNFV official configuration directory/file structure
66 and provides a fairly simple mechanism to execute a deployment.
68 $(notify "Input parameters to the build script are:" 2)
69 -b Base URI to the configuration directory (needs to be provided in URI style,
70 it can be a local resource: file:// or a remote resource http(s)://).
71 A POD Descriptor File (PDF) and its Installer Descriptor File (IDF)
72 companion should be available at:
73 <base-uri>/labs/<lab-name>/<pod-name>.yaml
74 <base-uri>/labs/<lab-name>/idf-<pod-name>.yaml
75 An example config is provided inside current repo in
77 The default is using the git submodule tracking 'OPNFV Pharos' in
78 <./mcp/scripts/pharos>.
79 -B Bridges to be used by deploy script. It can be specified several times,
80 or as a comma separated list of bridges, or both: -B br1 -B br2,br3
81 First occurence sets PXE Brige, next Mgmt, then Internal and Public.
82 For an empty value, the deploy script will use virsh to create the default
83 expected network (e.g. -B pxe,,,public will use existing "pxe" and "public"
84 bridges, respectively create "mgmt" and "internal").
85 Note that a virtual network "mcpcontrol" is always created. For virtual
86 deploys, "mcpcontrol" is also used for PXE, leaving the PXE bridge unused.
87 For baremetal deploys, PXE bridge is used for baremetal node provisioning,
88 while "mcpcontrol" is used to provision the infrastructure VMs only.
89 The default is 'pxebr'.
90 -d Dry-run - Produce deploy config files, but do not execute deploy
91 -D Debug logging - Enable extra logging in sh deploy scripts (set -x)
92 -e Do not launch environment deployment
93 -E Remove existing VCP VMs. It will destroy and undefine all VCP VMs
94 currently defined on cluster KVM nodes. If specified twice (e.g. -E -E),
95 baremetal nodes (VCP too, implicitly) will be removed, then reprovisioned.
96 Only applicable for baremetal deploys.
97 -f Deploy on existing Salt master. It will skip infrastructure VM creation,
98 but it will still sync reclass configuration from current repo to Salt
99 Master node. If specified twice (e.g. -f -f), config sync will also be
101 -F Do only create a Salt master
102 -h Print this message and exit
103 -L Deployment log path and name, eg. -L /home/jenkins/job.log.tar.gz
104 -l Lab name as defined in the configuration directory, e.g. lf
105 -p POD name as defined in the configuration directory, e.g. pod2
106 -P Skip installing dependency distro packages on current host
107 This flag should only be used if you have kept back older packages that
108 would be upgraded and that is undesirable on the current system.
109 Note that without the required packages, deploy will fail.
110 -s Deployment-scenario, this points to a short deployment scenario name, which
111 has to be defined in config directory (e.g. os-odl-nofeature-ha).
112 -S Storage dir for VM images, default is mcp/deploy/images
114 $(notify "[NOTE] sudo & virsh priviledges are needed for this script to run" 3)
118 $(notify "sudo $(basename "$0") \\
119 -b file:///home/jenkins/securedlab \\
121 -s os-odl-nofeature-ha" 2)
126 # END of usage description
127 ##############################################################################
129 ##############################################################################
130 # BEGIN of colored notification wrapper
133 tput setaf "${2:-1}" || true
134 echo -en "${1:-"[WARN] Unsupported opt arg: $3\\n"}"
138 # END of colored notification wrapper
139 ##############################################################################
141 ##############################################################################
142 # BEGIN of variables to customize
144 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
145 REPO_ROOT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")
146 DEPLOY_DIR=$(cd "${REPO_ROOT_PATH}/mcp/scripts"; pwd)
147 STORAGE_DIR=$(cd "${REPO_ROOT_PATH}/mcp/deploy/images"; pwd)
148 RECLASS_CLUSTER_DIR=$(cd "${REPO_ROOT_PATH}/mcp/reclass/classes/cluster"; pwd)
149 DEPLOY_TYPE='baremetal'
150 OPNFV_BRIDGES=('pxebr' 'mgmt' 'internal' 'public')
151 URI_REGEXP='(file|https?|ftp)://.*'
152 BASE_CONFIG_URI="file://${REPO_ROOT_PATH}/mcp/scripts/pharos"
154 # Customize deploy workflow
155 DRY_RUN=${DRY_RUN:-0}
156 USE_EXISTING_PKGS=${USE_EXISTING_PKGS:-0}
157 USE_EXISTING_INFRA=${USE_EXISTING_INFRA:-0}
158 INFRA_CREATION_ONLY=${INFRA_CREATION_ONLY:-0}
159 NO_DEPLOY_ENVIRONMENT=${NO_DEPLOY_ENVIRONMENT:-0}
160 ERASE_ENV=${ERASE_ENV:-0}
162 source "${DEPLOY_DIR}/globals.sh"
163 source "${DEPLOY_DIR}/lib.sh"
166 # END of variables to customize
167 ##############################################################################
169 ##############################################################################
174 while getopts "b:B:dDfEFl:L:p:Ps:S:he" OPTION
178 BASE_CONFIG_URI=${OPTARG}
179 if [[ ! $BASE_CONFIG_URI =~ ${URI_REGEXP} ]]; then
180 notify "[ERROR] -b $BASE_CONFIG_URI - invalid URI\n"
188 OPT_BRIDGES=($OPTARG)
189 for bridge in "${OPT_BRIDGES[@]}"; do
190 if [ -n "${bridge}" ]; then
191 OPNFV_BRIDGES[${OPNFV_BRIDGE_IDX}]="${bridge}"
193 ((OPNFV_BRIDGE_IDX+=1))
204 ((USE_EXISTING_INFRA+=1))
207 INFRA_CREATION_ONLY=1
210 NO_DEPLOY_ENVIRONMENT=1
219 DEPLOY_LOG="${OPTARG}"
223 if [[ "${TARGET_POD}" =~ "virtual" ]]; then
224 DEPLOY_TYPE='virtual'
231 DEPLOY_SCENARIO=${OPTARG}
234 if [[ ${OPTARG} ]]; then
235 STORAGE_DIR="${OPTARG}"
243 notify "[ERROR] Arguments not according to new argument style\n"
249 if [[ "$(sudo whoami)" != 'root' ]]; then
250 notify "[ERROR] This script requires sudo rights\n" 1>&2
254 # Validate mandatory arguments are set
255 if [ -z "${TARGET_LAB}" ] || [ -z "${TARGET_POD}" ] || \
256 [ -z "${DEPLOY_SCENARIO}" ]; then
257 notify "[ERROR] At least one of the mandatory args is missing!\n" 1>&2
262 [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
264 # Enable the automatic exit trap
265 trap do_exit SIGINT SIGTERM EXIT
267 # Set no restrictive umask so that Jenkins can remove any residuals
270 pushd "${DEPLOY_DIR}" > /dev/null
271 # Prepare the deploy config files based on lab/pod information, deployment
274 # Install required packages on jump server
275 if [ ${USE_EXISTING_PKGS} -eq 1 ]; then
276 notify "[NOTE] Skipping distro pkg installation\n" 2 1>&2
278 notify "[NOTE] Installing required distro pkgs\n" 2 1>&2
279 if [ -n "$(command -v apt-get)" ]; then
280 pkg_type='deb'; pkg_cmd='sudo apt-get install -y'
282 pkg_type='rpm'; pkg_cmd='sudo yum install -y --skip-broken'
284 eval "$(parse_yaml "./requirements_${pkg_type}.yaml")"
285 for section in 'common' "${DEPLOY_TYPE}" "$(uname -m)"; do
286 section_var="requirements_pkg_${section}[*]"
287 pkg_list+=" ${!section_var}"
289 # shellcheck disable=SC2086
290 ${pkg_cmd} ${pkg_list}
293 if ! virsh list >/dev/null 2>&1; then
294 notify "[ERROR] This script requires hypervisor access\n" 1>&2
298 # Collect jump server system information for deploy debugging
301 # Clone git submodules and apply our patches
302 make -C "${REPO_ROOT_PATH}/mcp/patches" deepclean patches-import
304 # Convert Pharos-compatible POD Descriptor File (PDF) to reclass model input
305 PHAROS_GEN_CONFIG_SCRIPT="./pharos/config/utils/generate_config.py"
306 PHAROS_INSTALLER_ADAPTER="./pharos/config/installers/fuel/pod_config.yml.j2"
307 BASE_CONFIG_PDF="${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}.yaml"
308 BASE_CONFIG_IDF="${BASE_CONFIG_URI}/labs/${TARGET_LAB}/idf-${TARGET_POD}.yaml"
309 LOCAL_PDF="${STORAGE_DIR}/$(basename "${BASE_CONFIG_PDF}")"
310 LOCAL_IDF="${STORAGE_DIR}/$(basename "${BASE_CONFIG_IDF}")"
311 LOCAL_PDF_RECLASS="${STORAGE_DIR}/pod_config.yml"
312 if ! curl --create-dirs -o "${LOCAL_PDF}" "${BASE_CONFIG_PDF}"; then
313 if [ "${DEPLOY_TYPE}" = 'baremetal' ]; then
314 notify "[ERROR] Could not retrieve PDF (Pod Descriptor File)!\n" 1>&2
317 notify "[WARN] Could not retrieve PDF (Pod Descriptor File)!\n" 3
319 elif ! curl -o "${LOCAL_IDF}" "${BASE_CONFIG_IDF}"; then
320 notify "[WARN] POD has no IDF (Installer Descriptor File)!\n" 3
321 elif ! "${PHAROS_GEN_CONFIG_SCRIPT}" -y "${LOCAL_PDF}" \
322 -j "${PHAROS_INSTALLER_ADAPTER}" > "${LOCAL_PDF_RECLASS}"; then
323 notify "[ERROR] Could not convert PDF to reclass model input!\n" 1>&2
327 # Check scenario file existence
328 SCENARIO_DIR="../config/scenario"
329 if [ ! -f "${SCENARIO_DIR}/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml" ]; then
330 notify "[ERROR] Scenario definition file is missing!\n" 1>&2
334 # Check defaults file existence
335 if [ ! -f "${SCENARIO_DIR}/defaults-$(uname -i).yaml" ]; then
336 notify "[ERROR] Scenario defaults file is missing!\n" 1>&2
340 # Get required infra deployment data
342 eval "$(parse_yaml "${SCENARIO_DIR}/defaults-$(uname -i).yaml")"
343 eval "$(parse_yaml "${SCENARIO_DIR}/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml")"
344 eval "$(parse_yaml "${LOCAL_PDF_RECLASS}")"
345 [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
347 export CLUSTER_DOMAIN=${cluster_domain}
349 # Serialize vnode data as '<name0>,<ram0>,<vcpu0>|<name1>,<ram1>,<vcpu1>[...]'
350 for node in "${virtual_nodes[@]}"; do
351 virtual_custom_ram="virtual_${node}_ram"
352 virtual_custom_vcpus="virtual_${node}_vcpus"
353 virtual_nodes_data+="${node},"
354 virtual_nodes_data+="${!virtual_custom_ram:-$virtual_default_ram},"
355 virtual_nodes_data+="${!virtual_custom_vcpus:-$virtual_default_vcpus}|"
357 virtual_nodes_data=${virtual_nodes_data%|}
359 # Serialize repos, packages to (pre-)install/remove for:
360 # - foundation node VM base image (virtual: all VMs, baremetal: cfg01|mas01)
361 # - virtualized control plane VM base image (only when VCP is used)
362 base_image_flavors=common
363 if [[ "${cluster_states[*]}" =~ virtual_control ]]; then
364 base_image_flavors+=" control"
366 for sc in ${base_image_flavors}; do
367 for va in apt_keys apt_repos pkg_install pkg_remove; do
368 key=virtual_${sc}_${va}
369 eval "${key}=\${${key}[@]// /|}"
370 eval "${key}=\${${key}// /,}"
371 virtual_repos_pkgs+="${!key}^"
374 virtual_repos_pkgs=${virtual_repos_pkgs%^}
376 # Expand reclass and virsh network templates
377 for tp in "${RECLASS_CLUSTER_DIR}/all-mcp-arch-common/opnfv/"*.template \
381 EOF" 2> /dev/null > "${tp%.template}"
384 # Convert Pharos-compatible PDF to reclass network definitions
385 if [ "${DEPLOY_TYPE}" = 'baremetal' ]; then
386 find "${RECLASS_CLUSTER_DIR}" -name '*.j2' | while read -r tp
388 if ! "${PHAROS_GEN_CONFIG_SCRIPT}" -y "${LOCAL_PDF}" \
389 -j "${tp}" > "${tp%.j2}"; then
390 notify "[ERROR] Could not convert PDF to reclass network defs!\n"
396 # Map PDF networks 'admin', 'mgmt', 'private' and 'public' to bridge names
397 BR_NAMES=('admin' 'mgmt' 'private' 'public')
399 "${paramaters__param_opnfv_infra_maas_pxe_address}" \
400 "${parameters__param_opnfv_infra_config_address}" \
401 "${parameters__param_opnfv_openstack_compute_node01_tenant_address}" \
402 "${parameters__param_opnfv_openstack_compute_node01_external_address}" \
404 for ((i = 0; i < ${#BR_NETS[@]}; i++)); do
405 br_jump=$(eval echo "\$parameters__param_opnfv_jump_bridge_${BR_NAMES[i]}")
406 if [ -n "${br_jump}" ] && [ "${br_jump}" != 'None' ] && \
407 [ -d "/sys/class/net/${br_jump}/bridge" ]; then
408 notify "[OK] Bridge found for '${BR_NAMES[i]}': ${br_jump}\n" 2
409 OPNFV_BRIDGES[${i}]="${br_jump}"
410 elif [ -n "${BR_NETS[i]}" ]; then
411 bridge=$(ip addr | awk "/${BR_NETS[i]%.*}./ {print \$NF; exit}")
412 if [ -n "${bridge}" ] && [ -d "/sys/class/net/${bridge}/bridge" ]; then
413 notify "[OK] Bridge found for net ${BR_NETS[i]%.*}.0: ${bridge}\n" 2
414 OPNFV_BRIDGES[${i}]="${bridge}"
418 notify "[NOTE] Using bridges: ${OPNFV_BRIDGES[*]}\n" 2
421 if [ ${DRY_RUN} -eq 1 ]; then
422 notify "[NOTE] Dry run, skipping all deployment tasks\n" 2 1>&2
424 elif [ ${USE_EXISTING_INFRA} -gt 0 ]; then
425 notify "[NOTE] Use existing infra\n" 2 1>&2
429 prepare_vms "${base_image}" "${STORAGE_DIR}" "${virtual_repos_pkgs}" \
430 "${virtual_nodes[@]}"
431 create_networks "${OPNFV_BRIDGES[@]}"
432 create_vms "${STORAGE_DIR}" "${virtual_nodes_data}" "${OPNFV_BRIDGES[@]}"
433 update_mcpcontrol_network
434 start_vms "${virtual_nodes[@]}"
437 if [ ${USE_EXISTING_INFRA} -lt 2 ]; then
438 wait_for 5 "./salt.sh ${LOCAL_PDF_RECLASS}"
441 # Openstack cluster setup
443 if [ ${INFRA_CREATION_ONLY} -eq 1 ] || [ ${NO_DEPLOY_ENVIRONMENT} -eq 1 ]; then
444 notify "[NOTE] Skip openstack cluster setup\n" 2
446 for state in "${cluster_states[@]}"; do
447 notify "[STATE] Applying state: ${state}\n" 2
448 # shellcheck disable=SC2086,2029
449 wait_for 5 "ssh ${SSH_OPTS} ${SSH_SALT} sudo \
450 CI_DEBUG=$CI_DEBUG ERASE_ENV=$ERASE_ENV \
451 /root/fuel/mcp/config/states/${state}"
455 ./log.sh "${DEPLOY_LOG}"
461 ##############################################################################