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