[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) 2017 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 if [[ "$BRANCH" =~ 'danube' ]]; then
16     # source the file so we get OPNFV vars
17     # shellcheck disable=SC1091
18     source latest.properties
19
20     # echo the info about artifact that is used during the deployment
21     echo "Using ${OPNFV_ARTIFACT_URL/*\/} for deployment"
22
23     # for Danube deployments (no artifact for current master or newer branches)
24     # checkout the commit that was used for building the downloaded artifact
25     # to make sure the ISO and deployment mechanism uses same versions
26     echo "Checking out ${OPNFV_GIT_SHA1}"
27     git checkout "${OPNFV_GIT_SHA1}" --quiet
28
29     # releng wants us to use nothing else but opnfv.iso for now. We comply.
30     ISO_FILE_ARG="-i file://${WORKSPACE}/opnfv.iso"
31 fi
32
33 # shellcheck disable=SC2153
34 if [[ "${JOB_NAME}" =~ 'verify' ]]; then
35     # set simplest scenario for virtual deploys to run for verify
36     DEPLOY_SCENARIO="os-nosdn-nofeature-noha"
37 fi
38
39 # set deployment parameters
40 export TMPDIR=${HOME}/tmpdir
41 # shellcheck disable=SC2153
42 LAB_NAME=${NODE_NAME/-*}
43 # shellcheck disable=SC2153
44 POD_NAME=${NODE_NAME/*-}
45 # Armband might override LAB_CONFIG_URL, all others use the default
46 LAB_CONFIG_URL=${LAB_CONFIG_URL:-'ssh://jenkins-ericsson@gerrit.opnfv.org:29418/securedlab'}
47
48 # Fuel requires deploy script to be ran with sudo, Armband does not
49 SUDO='sudo -E'
50 if [ "${PROJECT}" = 'fuel' ]; then
51     # Fuel currently supports ericsson, intel, lf and zte labs
52     if [[ ! "${LAB_NAME}" =~ (ericsson|intel|lf|zte) ]]; then
53         echo "Unsupported/unidentified lab ${LAB_NAME}. Cannot continue!"
54         exit 1
55     fi
56 else
57     SUDO=
58     # Armband currently supports arm, enea, unh labs
59     if [[ ! "${LAB_NAME}" =~ (arm|enea|unh) ]]; then
60         echo "Unsupported/unidentified lab ${LAB_NAME}. Cannot continue!"
61         exit 1
62     fi
63 fi
64
65 echo "Using configuration for ${LAB_NAME}"
66
67 # create TMPDIR if it doesn't exist, change permissions
68 mkdir -p "${TMPDIR}"
69 chmod a+x "${HOME}" "${TMPDIR}"
70
71 cd "${WORKSPACE}" || exit 1
72 if [[ "$BRANCH" =~ (danube|euphrates) ]]; then
73     if [[ "${LAB_CONFIG_URL}" =~ ^(git|ssh):// ]]; then
74         echo "Cloning securedlab repo ${BRANCH}"
75         LOCAL_CFG="${TMPDIR}/securedlab"
76         rm -rf "${LOCAL_CFG}"
77         git clone --quiet --branch "${BRANCH}" "${LAB_CONFIG_URL}" "${LOCAL_CFG}"
78         LAB_CONFIG_ARG="-b file://${LOCAL_CFG}"
79         BRIDGE_ARG="-B ${BRIDGE:-pxebr}"
80     else
81         LAB_CONFIG_ARG="-b ${LAB_CONFIG_URL}"
82     fi
83 fi
84
85 # log file name
86 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
87
88 # construct the command
89 DEPLOY_COMMAND="${SUDO} ${WORKSPACE}/ci/deploy.sh ${LAB_CONFIG_ARG:-} \
90     -l ${LAB_NAME} -p ${POD_NAME} -s ${DEPLOY_SCENARIO} ${ISO_FILE_ARG:-} \
91     -S ${TMPDIR} ${BRIDGE_ARG:-} \
92     -L ${WORKSPACE}/${FUEL_LOG_FILENAME}"
93
94 # log info to console
95 echo "Deployment parameters"
96 echo "--------------------------------------------------------"
97 echo "Scenario: ${DEPLOY_SCENARIO}"
98 echo "Lab: ${LAB_NAME}"
99 echo "POD: ${POD_NAME}"
100 [[ "${BRANCH}" =~ 'danube' ]] && echo "ISO: ${OPNFV_ARTIFACT_URL/*\/}"
101 echo
102 echo "Starting the deployment using ${INSTALLER_TYPE}. This could take some time..."
103 echo "--------------------------------------------------------"
104 echo
105
106 # start the deployment
107 echo "Issuing command"
108 echo "${DEPLOY_COMMAND}"
109 echo
110
111 ${DEPLOY_COMMAND}
112 exit_code=$?
113
114 echo
115 echo "--------------------------------------------------------"
116 echo "Deployment is done!"
117
118 # upload logs for baremetal deployments
119 # work with virtual deployments is still going on, so skip that for now
120 if [[ "${JOB_NAME}" =~ (baremetal-daily|baremetal-weekly) ]]; then
121     echo "Uploading deployment logs"
122     gsutil cp "${WORKSPACE}/${FUEL_LOG_FILENAME}" \
123         "gs://${GS_URL}/logs/${FUEL_LOG_FILENAME}" > /dev/null 2>&1
124     echo "Logs are available at http://${GS_URL}/logs/${FUEL_LOG_FILENAME}"
125 fi
126
127 if [[ "${exit_code}" -ne 0 ]]; then
128     echo "Deployment failed!"
129     exit "${exit_code}"
130 fi
131
132 echo "Deployment is successful!"
133 exit 0