Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / deploy / functions / deploy_env.sh
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
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
11 # Deploy!
12 scp -q $deafile root@${fuelIp}:. || error_exit "Could not copy DEA file to Fuel"
13 echo "Uploading build tools to Fuel server"
14 ssh root@${fuelIp} rm -rf tools || error_exit "Error cleaning old tools structure"
15 scp -qrp $topdir/tools root@${fuelIp}:. || error_exit "Error copying tools"
16
17 echo "Uploading templating tols to Fuel server"
18 ssh root@${fuelIp} rm -rf create_templates || error_exit "Error cleaning old create_templates structure"
19 scp -qrp $topdir/../create_templates root@${fuelIp}:. || error_exit "Error copying create_templates"
20
21 # Refuse to run if environment already present
22 envcnt=`fuel env | tail -n +3 | grep -v '^$' | wc -l`
23 if [ $envcnt -ne 0 ]; then
24   error_exit "Environment count is $envcnt"
25 fi
26
27 # Refuse to run if any nodes are up
28 nodeCnt=`numberOfNodesUp`
29 if [ $nodeCnt -ne 0 ]; then
30   error_exit "Nodes are up (node count: $nodeCnt)"
31 fi
32
33 # FIXME: Add support for CentOS creation here
34 # Extract release ID for Ubuntu environment
35 ubuntucnt=`fuel release | grep Ubuntu | wc -l`
36 if [ $ubuntucnt -ne 1 ]; then
37   error_exit "Not exacly one Ubuntu release found"
38 fi
39
40 # FIXME: Make release a property in the dea.yaml and use that instead!
41 ubuntuid=`fuel release | grep Ubuntu | awk '{ print $1 }'`
42
43 # Create environment
44 envName=`dea getProperty environment_name` || error_exit "Could not get environment name"
45 envMode=`dea getProperty environment_mode` || error_exit "Could not get environment mode"
46
47 fuel env create --name $envName \
48     --rel $ubuntuid \
49     --mode $envMode \
50     --network-mode neutron \
51     --net-segment-type vlan \
52     || error_exit "Error creating environment"
53
54 envId=`ssh root@${fuelIp} fuel env | tail -n +3 | awk '{ print $1 }'` \
55     || error_exit "Could not get environment id"
56
57 echo "Running transplant #1"
58 ssh root@${fuelIp} "cd tools; ./transplant1.sh ../`basename $deafile`" \
59     || error_exit "Error running transplant sequence #1"
60
61 # Start VMs
62 strategy=`dha getPowerOnStrategy` || error_exit "Could not get power on strategy"
63 if [ $strategy == "all" ]; then
64     echo "Starting all nodes at once"
65     poweredOn=0
66     for id in `dha getAllNodeIds`
67     do
68         if  [ $id -ne $fuelNodeId ]; then
69             echo "Setting boot order pxe disk for node $id"
70             dha nodeSetBootOrder $id "pxe disk" || "Could not set boot order for node"
71             echo "Powering on node $id"
72             dha nodePowerOn $id || error_exit "Could not power on node"
73             poweredOn=$[poweredOn + 1]
74         fi
75     done
76     # Wait for all nodes to be accounted for
77     echo "Waiting for $poweredOn nodes to come up"
78     while true
79     do
80         nodesUp=`numberOfNodesUp`
81         echo -n "[${nodesUp}]"
82         if [ $nodesUp -eq $poweredOn ]; then
83             break
84         fi
85         sleep 10
86     done
87     echo "[${nodesUp}]"
88 else
89     # Refuse to run if any nodes are defined
90     totalNodeCnt=`numberOfNodes`
91     if [ $totalNodeCnt -ne 0 ]; then
92         error_exit "There are already ${totalNodeCnt} defined nodes, can not run power on in sequence!"
93     fi
94     echo "Starting nodes sequentially, waiting for Fuel detection until proceeding"
95     for id in `dha getAllNodeIds`
96     do
97         if  [ $id -ne $fuelNodeId ]; then
98             echo "Setting boot order pxe disk for node $id"
99             dha nodeSetBootOrder $id "pxe disk" || "Could not set boot order for node"
100             echo "Powering on node $id"
101             dha nodePowerOn $id || error_exit "Could not power on node"
102             # Wait for node count to increase
103             waitForNode
104         fi
105     done
106 fi
107
108 # Set roles for detected hosts
109 for id in `dha getAllNodeIds`
110 do
111     # If not a Fuel node
112     if  [ $fuelNodeId -ne $id ]; then
113         longMac=`dha getNodePxeMac $id` || \
114             error_exit "Could not get MAC address for node $id from DHA"
115         shortMac=`dea convertMacToShortMac $longMac`
116         role="`dea getNodeRole $id`"
117         echo "Setting role $role for Fuel node $shortMac (DEA node $id)"
118         fuel node set --node-id $shortMac --role $role --env $envId \
119             || error_exit "Could not set role for $node"
120     fi
121 done
122
123 # Run pre-deploy with default input
124 # Need to set terminal as script does "clear" and needs curses support
125 ssh root@${fuelIp} "TERM=vt100 /opt/opnfv/pre-deploy.sh < /dev/null" \
126     || error_exit "Pre-deploy failed"
127
128 # Inject node network config (will override pre-deploy Astute settings but we
129 # want to catch pre-deploy provisioning changes)
130 # TODO: There needs to be a function to adjust the NTP settings for clients
131 # TODO: to that of the actual set of controllers in this deployment.
132 echo "Running transplant #2"
133 ssh root@${fuelIp} "cd tools; ./transplant2.sh ../`basename $deafile`" \
134     || error_exit "Error running transplant sequence #2"
135
136
137 # Deploy
138 echo "Deploying!"
139 ssh root@${fuelIp} "fuel deploy-changes --env $envId" >/dev/null 2>&1 || error_exit "Deploy failed"
140 echo "Deployment completed"