Merge "jjb: infra: bifrost-cleanup-job.yml: Add new bifrost cleanup job"
[releng.git] / jjb / multisite / fuel-deploy-for-multisite.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson 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 # do not continue with the deployment if FRESH_INSTALL is not requested
14 if [[ "$FRESH_INSTALL" == "true" ]]; then
15     echo "Fresh install requested. Proceeding with the installation."
16 else
17     echo "Fresh install is not requested. Skipping the installation."
18     exit 0
19 fi
20
21 export TERM="vt220"
22
23 # get the latest successful job console log and extract the properties filename
24 FUEL_DEPLOY_BUILD_URL="https://build.opnfv.org/ci/job/fuel-deploy-virtual-daily-master/lastSuccessfulBuild/consoleText"
25 FUEL_PROPERTIES_FILE=$(curl -s -L ${FUEL_DEPLOY_BUILD_URL} | grep 'ISO:' | awk '{print $2}' | sed 's/iso/properties/g')
26 if [[ -z "FUEL_PROPERTIES_FILE" ]]; then
27     echo "Unable to extract the url to Fuel ISO properties from ${FUEL_DEPLOY_URL}"
28     exit 1
29 fi
30 curl -L -s -o $WORKSPACE/latest.properties http://artifacts.opnfv.org/fuel/$FUEL_PROPERTIES_FILE
31
32 # source the file so we get OPNFV vars
33 source latest.properties
34
35 # echo the info about artifact that is used during the deployment
36 echo "Using ${OPNFV_ARTIFACT_URL/*\/} for deployment"
37
38 # download the iso
39 echo "Downloading the ISO using the link http://$OPNFV_ARTIFACT_URL"
40 curl -L -s -o $WORKSPACE/opnfv.iso http://$OPNFV_ARTIFACT_URL > gsutil.iso.log 2>&1
41
42
43 # set deployment parameters
44 DEPLOY_SCENARIO="os-nosdn-nofeature-noha"
45 export TMPDIR=$HOME/tmpdir
46 BRIDGE=${BRIDGE:-pxebr}
47 LAB_NAME=${NODE_NAME/-*}
48 POD_NAME=${NODE_NAME/*-}
49
50 if [[ "$NODE_NAME" =~ "virtual" ]]; then
51     POD_NAME="virtual_kvm"
52 fi
53
54 # we currently support ericsson, intel, lf and zte labs
55 if [[ ! "$LAB_NAME" =~ (ericsson|intel|lf|zte) ]]; then
56     echo "Unsupported/unidentified lab $LAB_NAME. Cannot continue!"
57     exit 1
58 else
59     echo "Using configuration for $LAB_NAME"
60 fi
61
62 # create TMPDIR if it doesn't exist
63 export TMPDIR=$HOME/tmpdir
64 mkdir -p $TMPDIR
65
66 # change permissions down to TMPDIR
67 chmod a+x $HOME
68 chmod a+x $TMPDIR
69
70 # clone fuel repo and checkout the sha1 that corresponds to the ISO
71 echo "Cloning fuel repo"
72 git clone https://gerrit.opnfv.org/gerrit/p/fuel.git fuel
73 cd $WORKSPACE/fuel
74 echo "Checking out $OPNFV_GIT_SHA1"
75 git checkout $OPNFV_GIT_SHA1 --quiet
76
77 # clone the securedlab repo
78 cd $WORKSPACE
79 echo "Cloning securedlab repo ${GIT_BRANCH##origin/}"
80 git clone ssh://jenkins-ericsson@gerrit.opnfv.org:29418/securedlab --quiet \
81     --branch ${GIT_BRANCH##origin/}
82
83 # log file name
84 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
85
86 # construct the command
87 DEPLOY_COMMAND="sudo $WORKSPACE/fuel/ci/deploy.sh -b file://$WORKSPACE/securedlab \
88     -l $LAB_NAME -p $POD_NAME -s $DEPLOY_SCENARIO -i file://$WORKSPACE/opnfv.iso \
89     -H -B $BRIDGE -S $TMPDIR -L $WORKSPACE/$FUEL_LOG_FILENAME"
90
91 # log info to console
92 echo "Deployment parameters"
93 echo "--------------------------------------------------------"
94 echo "Scenario: $DEPLOY_SCENARIO"
95 echo "Lab: $LAB_NAME"
96 echo "POD: $POD_NAME"
97 echo "ISO: ${OPNFV_ARTIFACT_URL/*\/}"
98 echo
99 echo "Starting the deployment using $INSTALLER_TYPE. This could take some time..."
100 echo "--------------------------------------------------------"
101 echo
102
103 # start the deployment
104 echo "Issuing command"
105 echo "$DEPLOY_COMMAND"
106 echo
107
108 $DEPLOY_COMMAND
109 exit_code=$?
110
111 echo
112 echo "--------------------------------------------------------"
113 echo "Deployment is done!"
114
115 if [[ $exit_code -ne 0 ]]; then
116     echo "Deployment failed!"
117     exit $exit_code
118 else
119     echo "Deployment is successful!"
120     exit 0
121 fi