c30041711d0c60096b8bc6ca8710a206607c9cd2
[releng.git] / jjb / fuel / fuel-deploy.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 # source the file so we get OPNFV vars
14 source latest.properties
15
16 # echo the info about artifact that is used during the deployment
17 echo "Using ${OPNFV_ARTIFACT_URL/*\/} for deployment"
18
19 if [[ "$JOB_NAME" =~ "merge" ]]; then
20     # set simplest scenario for virtual deploys to run for merges
21     DEPLOY_SCENARIO="os-nosdn-nofeature-ha"
22 else
23     # for none-merge deployments
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 fi
29
30 # set deployment parameters
31 export TMPDIR=$HOME/tmpdir
32 BRIDGE=pxebr
33 LAB_NAME=${NODE_NAME/-*}
34 POD_NAME=${NODE_NAME/*-}
35
36 if [[ "$NODE_NAME" =~ "virtual" ]]; then
37     POD_NAME="virtual_kvm"
38 fi
39
40 # we currently support ericsson, intel, lf and zte labs
41 if [[ ! "$LAB_NAME" =~ (ericsson|intel|lf|zte) ]]; then
42     echo "Unsupported/unidentified lab $LAB_NAME. Cannot continue!"
43     exit 1
44 else
45     echo "Using configuration for $LAB_NAME"
46 fi
47
48 # create TMPDIR if it doesn't exist
49 export TMPDIR=$HOME/tmpdir
50 mkdir -p $TMPDIR
51
52 # change permissions down to TMPDIR
53 chmod a+x $HOME
54 chmod a+x $TMPDIR
55
56 # clone the securedlab repo
57 cd $WORKSPACE
58 echo "Cloning securedlab repo ${GIT_BRANCH##origin/}"
59 git clone ssh://jenkins-ericsson@gerrit.opnfv.org:29418/securedlab --quiet \
60     --branch ${GIT_BRANCH##origin/}
61
62 # log file name
63 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
64
65 # construct the command
66 DEPLOY_COMMAND="sudo $WORKSPACE/ci/deploy.sh -b file://$WORKSPACE/securedlab \
67     -l $LAB_NAME -p $POD_NAME -s $DEPLOY_SCENARIO -i file://$WORKSPACE/opnfv.iso \
68     -H -B $BRIDGE -S $TMPDIR -L $WORKSPACE/$FUEL_LOG_FILENAME"
69
70 # log info to console
71 echo "Deployment parameters"
72 echo "--------------------------------------------------------"
73 echo "Scenario: $DEPLOY_SCENARIO"
74 echo "Lab: $LAB_NAME"
75 echo "POD: $POD_NAME"
76 echo "ISO: ${OPNFV_ARTIFACT_URL/*\/}"
77 echo
78 echo "Starting the deployment using $INSTALLER_TYPE. This could take some time..."
79 echo "--------------------------------------------------------"
80 echo
81
82 # start the deployment
83 echo "Issuing command"
84 echo "$DEPLOY_COMMAND"
85 echo
86
87 $DEPLOY_COMMAND
88 exit_code=$?
89
90 echo
91 echo "--------------------------------------------------------"
92 echo "Deployment is done!"
93
94 # upload logs for baremetal deployments
95 # work with virtual deployments is still going on so we skip that for the timebeing
96 if [[ "$JOB_NAME" =~ "baremetal-daily" ]]; then
97     echo "Uploading deployment logs"
98     gsutil cp $WORKSPACE/$FUEL_LOG_FILENAME gs://$GS_URL/logs/$FUEL_LOG_FILENAME > /dev/null 2>&1
99     echo "Logs are available as http://$GS_URL/logs/$FUEL_LOG_FILENAME"
100 fi
101
102 if [[ $exit_code -ne 0 ]]; then
103     echo "Deployment failed!"
104     exit $exit_code
105 else
106     echo "Deployment is successful!"
107 fi
108
109 # Quick and dirty fix for SFC scenatio - will be fixed properly post-release
110 if [[ ! "$DEPLOY_SCENARIO" =~ "os-odl_l2-sfc" ]]; then
111     exit 0
112 fi
113
114 echo
115 echo "SFC Scenario is deployed"
116 echo
117
118 # The stuff below is here temporarily and will be fixed once the release is out
119 # The stuff below is here temporarily and will be fixed once the release is out
120 export FUEL_MASTER_IP=10.20.0.2
121 export TACKER_SCRIPT_URL="https://git.opnfv.org/cgit/fuel/plain/prototypes/sfc_tacker/poc.tacker-up.sh?h=${GIT_BRANCH#*/}"
122 export CONTROLLER_NODE_IP=$(sshpass -pr00tme /usr/bin/ssh -o UserKnownHostsFile=/dev/null \
123     -o StrictHostKeyChecking=no root@$FUEL_MASTER_IP 'fuel node list' | \
124     grep opendaylight | cut -d'|' -f5)
125
126 # we can't do much if we do not have the controller IP
127 if [[ ! "$CONTROLLER_NODE_IP" =~ "10.20.0" ]]; then
128     echo "Unable to retrieve controller IP"
129     exit 1
130 fi
131
132 echo
133 echo "Copying and executing poc.tacker-up.sh script on controller node $CONTROLLER_NODE_IP"
134 echo
135
136 expect << END
137 spawn /usr/bin/ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root $::env(FUEL_MASTER_IP)
138 expect {
139   -re ".*sword.*" {
140     exp_send "r00tme\r"
141   }
142 }
143 expect "# "
144 send "/usr/bin/ssh -l root $::env(CONTROLLER_NODE_IP)\r"
145 expect "# "
146 send "sudo apt-get install -y git\r"
147 expect "# "
148 send "/bin/mkdir -p /root/sfc-poc && cd /root/sfc-poc\r"
149 expect "# "
150 send "git clone https://gerrit.opnfv.org/gerrit/fuel && cd fuel\r"
151 expect "# "
152 send "git fetch https://gerrit.opnfv.org/gerrit/fuel refs/changes/97/10597/2 && git checkout FETCH_HEAD\r"
153 expect "# "
154 send "/bin/bash /root/sfc-poc/fuel/prototypes/sfc_tacker/poc.tacker-up.sh\r"
155 expect "# "
156 send "exit\r"
157 expect "Connection to $::env(CONTROLLER_NODE_IP) closed. "
158 send "exit\r"
159 expect "Connection to $::env(FUEL_MASTER_IP) closed. "
160 END