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