2 # shellcheck disable=SC2034,SC2154,SC1090,SC1091,SC2155
3 ##############################################################################
4 # Copyright (c) 2018 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!" 2
21 notify_n "[ERROR] MCP: Openstack installation threw a fatal error!"
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 [-S storage-dir] [-L /path/to/log/file.tar.gz] \\
41 [-f[f]] [-F] [-e | -E[E]] [-d] [-D] [-N]
43 $(notify "OPTIONS:" 2)
44 -b Base-uri for the stack-configuration structure
47 -e Do not launch environment deployment
48 -E Remove existing VCP VMs (use twice to redeploy baremetal nodes)
49 -f Deploy on existing Salt master (use twice to also skip config sync)
50 -F Do only create a Salt master
51 -h Print this message and exit
54 -P Skip installation of package dependencies
55 -s Deploy-scenario short-name
56 -S Storage dir for VM images
57 -L Deployment log path and file name
58 -N Experimental: Do not virtualize control plane (novcp)
60 $(notify_i "Description:" 2)
61 Deploys the Fuel@OPNFV stack on the indicated lab resource.
63 This script provides the Fuel@OPNFV deployment abstraction.
64 It depends on the OPNFV official configuration directory/file structure
65 and provides a fairly simple mechanism to execute a deployment.
67 $(notify_i "Input parameters to the build script are:" 2)
68 -b Base URI to the configuration directory (needs to be provided in URI style,
69 it can be a local resource: file:// or a remote resource http(s)://).
70 A POD Descriptor File (PDF) and its Installer Descriptor File (IDF)
71 companion should be available at:
72 <base-uri>/labs/<lab-name>/<pod-name>.yaml
73 <base-uri>/labs/<lab-name>/idf-<pod-name>.yaml
74 The default is using the git submodule tracking 'OPNFV Pharos' in
75 <./mcp/scripts/pharos>.
76 An example config is provided inside current repo in
77 <./mcp/config>, automatically linked as <./mcp/scripts/pharos/labs/local>.
78 -d Dry-run - Produce deploy config files, but do not execute deploy
79 -D Debug logging - Enable extra logging in sh deploy scripts (set -x)
80 -e Do not launch environment deployment
81 -E Remove existing VCP VMs. It will destroy and undefine all VCP VMs
82 currently defined on cluster KVM nodes. If specified twice (e.g. -E -E),
83 baremetal nodes (VCP too, implicitly) will be removed, then reprovisioned.
84 Only applicable for baremetal deploys.
85 -f Deploy on existing Salt master. It will skip infrastructure VM creation,
86 but it will still sync reclass configuration from current repo to Salt
87 Master node. If specified twice (e.g. -f -f), config sync will also be
89 -F Do only create a Salt master
90 -h Print this message and exit
91 -L Deployment log path and name, eg. -L /home/jenkins/job.log.tar.gz
92 -l Lab name as defined in the configuration directory, e.g. lf
93 For the sample configuration in <./mcp/config>, lab name is 'local'.
94 -p POD name as defined in the configuration directory, e.g. pod2
95 For the sample configuration in <./mcp/config>, POD name is 'virtual1'
96 for virtual deployments or 'pod1' for baremetal (based on lf-pod2).
97 -N Experimental: Instead of virtualizing the control plane (VCP), deploy
98 control plane directly on baremetal nodes
99 -P Skip installing dependency distro packages on current host
100 This flag should only be used if you have kept back older packages that
101 would be upgraded and that is undesirable on the current system.
102 Note that without the required packages, deploy will fail.
103 -s Deployment-scenario, this points to a short deployment scenario name, which
104 has to be defined in config directory (e.g. os-odl-nofeature-ha).
105 -S Storage dir for VM images, default is mcp/deploy/images
107 $(notify_i "[NOTE] sudo & virsh priviledges are needed for this script to run" 3)
111 $(notify_i "sudo $(basename "$0") \\
112 -b file:///home/jenkins/securedlab \\
114 -s os-odl-nofeature-ha" 2)
119 # END of usage description
120 ##############################################################################
122 ##############################################################################
123 # BEGIN of variables to customize
125 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
126 MCP_REPO_ROOT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")
127 DEPLOY_DIR=$(cd "${MCP_REPO_ROOT_PATH}/mcp/scripts"; pwd)
128 MCP_STORAGE_DIR=$(cd "${MCP_REPO_ROOT_PATH}/mcp/deploy/images"; pwd)
129 URI_REGEXP='(file|https?|ftp)://.*'
130 BASE_CONFIG_URI="file://${MCP_REPO_ROOT_PATH}/mcp/scripts/pharos"
132 # Customize deploy workflow
133 DRY_RUN=${DRY_RUN:-0}
134 USE_EXISTING_PKGS=${USE_EXISTING_PKGS:-0}
135 USE_EXISTING_INFRA=${USE_EXISTING_INFRA:-0}
136 INFRA_CREATION_ONLY=${INFRA_CREATION_ONLY:-0}
137 NO_DEPLOY_ENVIRONMENT=${NO_DEPLOY_ENVIRONMENT:-0}
138 ERASE_ENV=${ERASE_ENV:-0}
139 MCP_VCP=${MCP_VCP:-1}
141 source "${DEPLOY_DIR}/globals.sh"
142 source "${DEPLOY_DIR}/lib.sh"
143 source "${DEPLOY_DIR}/lib_template.sh"
146 # END of variables to customize
147 ##############################################################################
149 ##############################################################################
153 while getopts "b:dDfEFl:L:Np:Ps:S:he" OPTION
157 BASE_CONFIG_URI=${OPTARG}
158 if [[ ! $BASE_CONFIG_URI =~ ${URI_REGEXP} ]]; then
159 notify "[ERROR] -b $BASE_CONFIG_URI - invalid URI"
171 ((USE_EXISTING_INFRA+=1))
174 INFRA_CREATION_ONLY=1
177 NO_DEPLOY_ENVIRONMENT=1
186 DEPLOY_LOG="${OPTARG}"
198 DEPLOY_SCENARIO=${OPTARG}
201 if [[ ${OPTARG} ]]; then
202 MCP_STORAGE_DIR="${OPTARG}"
210 notify_e "[ERROR] Unsupported arg, see -h for help"
215 if [[ "$(sudo whoami)" != 'root' ]]; then
216 notify_e "[ERROR] This script requires sudo rights"
219 # Validate mandatory arguments are set
220 if [ -z "${TARGET_LAB}" ] || [ -z "${TARGET_POD}" ] || \
221 [ -z "${DEPLOY_SCENARIO}" ]; then
223 notify_e "[ERROR] At least one of the mandatory args is missing!"
226 [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
228 # Enable the automatic exit trap
229 trap do_exit SIGINT SIGTERM EXIT
231 # Set no restrictive umask so that Jenkins can remove any residuals
234 pushd "${DEPLOY_DIR}" > /dev/null
235 # Prepare the deploy config files based on lab/pod information, deployment
238 # Install required packages on jump server
239 if [ ${USE_EXISTING_PKGS} -eq 1 ]; then
240 notify "[NOTE] Skipping distro pkg installation" 2
242 notify "[NOTE] Installing required distro pkgs" 2
243 jumpserver_pkg_install
246 if ! virsh list >/dev/null 2>&1; then
247 notify_e "[ERROR] This script requires hypervisor access"
250 # Collect jump server system information for deploy debugging
253 # Clone git submodules and apply our patches
254 make -C "${MCP_REPO_ROOT_PATH}/mcp/patches" deepclean patches-import
256 # Check scenario file existence
257 SCENARIO_DIR="$(readlink -f "../config/scenario")"
258 if [ ! -f "${SCENARIO_DIR}/${DEPLOY_SCENARIO}.yaml" ] && \
259 [ ! -f "${SCENARIO_DIR}/${DEPLOY_SCENARIO}.yaml.j2" ]; then
260 notify_e "[ERROR] Scenario definition file is missing!"
263 # key might not exist yet ...
265 export MAAS_SSH_KEY="$(cat "$(basename "${SSH_KEY}").pub")"
267 MCP_DPDK_MODE=$([[ "$DEPLOY_SCENARIO" =~ ovs ]] && echo 1 || echo 0)
268 # Expand jinja2 templates based on PDF data and env vars
269 export MCP_REPO_ROOT_PATH MCP_VCP MCP_DPDK_MODE MCP_STORAGE_DIR \
270 MCP_JUMP_ARCH=$(uname -i)
271 do_templates_scenario "${MCP_STORAGE_DIR}" "${TARGET_LAB}" "${TARGET_POD}" \
272 "${BASE_CONFIG_URI}" "${SCENARIO_DIR}"
273 do_templates_cluster "${MCP_STORAGE_DIR}" "${TARGET_LAB}" "${TARGET_POD}" \
274 "${MCP_REPO_ROOT_PATH}" \
275 "${SCENARIO_DIR}/defaults.yaml" \
276 "${SCENARIO_DIR}/${DEPLOY_SCENARIO}.yaml"
278 # Determine additional data (e.g. jump bridge names) based on XDF
279 source "${DEPLOY_DIR}/xdf_data.sh"
281 # Jumpserver prerequisites check
282 notify "[NOTE] Using bridges: ${OPNFV_BRIDGES[*]}" 2
283 jumpserver_check_requirements "${virtual_nodes[*]}" "${OPNFV_BRIDGES[@]}"
286 if [ ${DRY_RUN} -eq 1 ]; then
287 notify "[NOTE] Dry run, skipping all deployment tasks" 2
289 elif [ ${USE_EXISTING_INFRA} -gt 0 ]; then
290 notify "[NOTE] Use existing infra" 2
293 prepare_vms "${base_image}" "${MCP_STORAGE_DIR}" "${virtual_repos_pkgs}" \
294 "${virtual_nodes[@]}"
295 create_networks "${OPNFV_BRIDGES[@]}"
298 create_vms "${MCP_STORAGE_DIR}" "${virtual_nodes_data}" "${OPNFV_BRIDGES[@]}"
299 update_mcpcontrol_network
300 start_vms "${virtual_nodes[@]}"
303 if [ ${USE_EXISTING_INFRA} -lt 2 ]; then
304 wait_for 5 "./salt.sh ${MCP_STORAGE_DIR}/pod_config.yml ${virtual_nodes[*]}"
307 # Openstack cluster setup
309 if [ ${INFRA_CREATION_ONLY} -eq 1 ] || [ ${NO_DEPLOY_ENVIRONMENT} -eq 1 ]; then
310 notify "[NOTE] Skip openstack cluster setup" 2
312 for state in "${cluster_states[@]}"; do
313 notify "[STATE] Applying state: ${state}" 2
314 # shellcheck disable=SC2086,2029
315 wait_for 5 "ssh ${SSH_OPTS} ${SSH_SALT} sudo \
316 CI_DEBUG=$CI_DEBUG ERASE_ENV=$ERASE_ENV \
317 /root/fuel/mcp/config/states/${state}"
318 if [ "${state}" = 'maas' ]; then
319 # For hybrid PODs (virtual + baremetal nodes), the virtual nodes
320 # should be reset to force a DHCP request from MaaS DHCP
321 reset_vms "${virtual_nodes[@]}"
326 ./log.sh "${DEPLOY_LOG}"
332 ##############################################################################