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