Merge "[docs] Limit git submodule recurse to depth 1"
[releng.git] / jjb / fuel / fuel-deploy.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018 Ericsson AB, Mirantis Inc., Enea Software AB and others.
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 set -o nounset
11 set -o pipefail
12
13 export TERM="vt220"
14
15 # set deployment parameters
16 export TMPDIR=${HOME}/tmpdir
17 # shellcheck disable=SC2153
18 LAB_NAME=${NODE_NAME/-*}
19 # shellcheck disable=SC2153
20 POD_NAME=${NODE_NAME/*-}
21
22 # Fuel currently supports arm, enea, ericsson, intel, lf, unh and zte labs
23 if [[ ! "${LAB_NAME}" =~ (arm|enea|ericsson|intel|lf|unh|zte) ]]; then
24     echo "Unsupported/unidentified lab ${LAB_NAME}. Cannot continue!"
25     exit 1
26 fi
27
28 echo "Using configuration for ${LAB_NAME}"
29
30 # Certain labs do not require the deploy script to be ran with sudo
31 SUDO='sudo -E'
32 [[ ! "${LAB_NAME}" =~ (arm|enea|unh) ]] || SUDO=
33
34 # create TMPDIR if it doesn't exist, change permissions
35 mkdir -p "${TMPDIR}"
36 sudo chmod a+x "${HOME}" "${TMPDIR}"
37
38 cd "${WORKSPACE}" || exit 1
39
40 # log file name
41 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
42
43 # Limited scope for vPOD verify jobs running on armband-virtual
44 [[ ! "${JOB_NAME}" =~ verify-deploy-virtual-arm64 ]] || EXTRA_ARGS='-e'
45
46 # construct the command
47 DEPLOY_COMMAND="${SUDO} ${WORKSPACE}/ci/deploy.sh \
48     -l ${LAB_NAME} -p ${POD_NAME} -s ${DEPLOY_SCENARIO} \
49     -S ${TMPDIR} ${EXTRA_ARGS:-} \
50     -L ${WORKSPACE}/${FUEL_LOG_FILENAME}"
51
52 # log info to console
53 echo "Deployment parameters"
54 echo "--------------------------------------------------------"
55 echo "Scenario: ${DEPLOY_SCENARIO}"
56 echo "Lab: ${LAB_NAME}"
57 echo "POD: ${POD_NAME}"
58 echo
59 echo "Starting the deployment using ${INSTALLER_TYPE}. This could take some time..."
60 echo "--------------------------------------------------------"
61 echo
62
63 # start the deployment
64 echo "Issuing command"
65 echo "${DEPLOY_COMMAND}"
66 echo
67
68 ${DEPLOY_COMMAND}
69 exit_code=$?
70
71 echo
72 echo "--------------------------------------------------------"
73 echo "Deployment is done!"
74
75 # upload logs for baremetal deployments
76 # work with virtual deployments is still going on, so skip that for now
77 if [[ "${JOB_NAME}" =~ baremetal-daily ]]; then
78     echo "Uploading deployment logs"
79     gsutil cp "${WORKSPACE}/${FUEL_LOG_FILENAME}" \
80         "gs://${GS_URL}/logs/${FUEL_LOG_FILENAME}" > /dev/null 2>&1
81     echo "Logs are available at http://${GS_URL}/logs/${FUEL_LOG_FILENAME}"
82 fi
83
84 if [[ "${exit_code}" -ne 0 ]]; then
85     echo "Deployment failed!"
86     exit "${exit_code}"
87 fi
88
89 echo "Deployment is successful!"
90 exit 0