armband-deploy.sh: Inherit env vars for sudo
[releng.git] / jjb / armband / armband-deploy.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB and others.
5 #           (c) 2017 Enea Software AB
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 ##############################################################################
11 set -o nounset
12 set -o pipefail
13
14 export TERM="vt220"
15
16 if [[ "$BRANCH" != 'master' ]]; then
17     # source the file so we get OPNFV vars
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 fi
23
24 if [[ "$JOB_NAME" =~ "merge" ]]; then
25     # set simplest scenario for virtual deploys to run for merges
26     DEPLOY_SCENARIO="os-nosdn-nofeature-ha"
27 elif [[ "$BRANCH" != 'master' ]]; then
28     # for none-merge deployments
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=${WORKSPACE}/tmpdir
37
38 # arm-pod4 is an aarch64 jenkins slave for the same POD as the
39 # x86 jenkins slave arm-pod3; therefore we use the same pod name
40 # to deploy the pod from both jenkins slaves
41 if [[ "${NODE_NAME}" == "arm-pod4" ]]; then
42     NODE_NAME="arm-pod3"
43 fi
44
45 LAB_NAME=${NODE_NAME/-*}
46 POD_NAME=${NODE_NAME/*-}
47
48 # we currently support enea
49 if [[ ! $LAB_NAME =~ (arm|enea) ]]; then
50     echo "Unsupported/unidentified lab $LAB_NAME. Cannot continue!"
51     exit 1
52 fi
53
54 echo "Using configuration for $LAB_NAME"
55
56 # create TMPDIR if it doesn't exist
57 mkdir -p $TMPDIR
58
59 cd $WORKSPACE
60 if [[ $LAB_CONFIG_URL =~ ^(git|ssh):// ]]; then
61     echo "Cloning securedlab repo $BRANCH"
62     git clone --quiet --branch $BRANCH $LAB_CONFIG_URL lab-config
63     LAB_CONFIG_URL=file://${WORKSPACE}/lab-config
64
65     # Source local_env if present, which contains POD-specific config
66     local_env="${WORKSPACE}/lab-config/labs/$LAB_NAME/$POD_NAME/fuel/config/local_env"
67     if [ -e $local_env ]; then
68         echo "-- Sourcing local environment file"
69         source $local_env
70     fi
71 fi
72
73 if [[ "$NODE_NAME" =~ "virtual" ]]; then
74     POD_NAME="virtual_kvm"
75 fi
76
77 # releng wants us to use nothing else but opnfv.iso for now. We comply.
78 ISO_FILE=$WORKSPACE/opnfv.iso
79
80 # log file name
81 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
82
83 # Deploy Cache (to enable just create the deploy-cache subdir)
84 # NOTE: Only available when ISO files are cached using ISOSTORE mechanism
85 DEPLOY_CACHE=${ISOSTORE:-/iso_mount/opnfv_ci}/${BRANCH##*/}/deploy-cache
86 if [[ -d "${DEPLOY_CACHE}" ]]; then
87     echo "Deploy cache dir present."
88     echo "--------------------------------------------------------"
89     echo "Fuel@OPNFV deploy cache: ${DEPLOY_CACHE}"
90     DEPLOY_CACHE="-C ${DEPLOY_CACHE}"
91 else
92     DEPLOY_CACHE=""
93 fi
94
95 # construct the command
96 DEPLOY_COMMAND="sudo -E $WORKSPACE/ci/deploy.sh -b ${LAB_CONFIG_URL} \
97     -l $LAB_NAME -p $POD_NAME -s $DEPLOY_SCENARIO -i file://${ISO_FILE} \
98     -H -B ${DEFAULT_BRIDGE:-pxebr} -S $TMPDIR -L $WORKSPACE/$FUEL_LOG_FILENAME \
99     ${DEPLOY_CACHE}"
100
101 # log info to console
102 echo "Deployment parameters"
103 echo "--------------------------------------------------------"
104 echo "Scenario: $DEPLOY_SCENARIO"
105 echo "Lab: $LAB_NAME"
106 echo "POD: $POD_NAME"
107 [[ "$BRANCH" != 'master' ]] && echo "ISO: ${OPNFV_ARTIFACT_URL/*\/}"
108 echo
109 echo "Starting the deployment using $INSTALLER_TYPE. This could take some time..."
110 echo "--------------------------------------------------------"
111 echo
112
113 # start the deployment
114 echo "Issuing command"
115 echo "$DEPLOY_COMMAND"
116 echo
117
118 $DEPLOY_COMMAND
119 exit_code=$?
120
121 echo
122 echo "--------------------------------------------------------"
123 echo "Deployment is done!"
124
125 # upload logs for baremetal deployments
126 # work with virtual deployments is still going on so we skip that for the timebeing
127 if [[ "$JOB_NAME" =~ "baremetal-daily" ]]; then
128     echo "Uploading deployment logs"
129     gsutil cp $WORKSPACE/$FUEL_LOG_FILENAME gs://$GS_URL/logs/$FUEL_LOG_FILENAME > /dev/null 2>&1
130     echo "Logs are available as 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 else
137     echo "Deployment is successful!"
138 fi