2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
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 ##############################################################################
13 topdir=$(dirname $(readlink -f $BASH_SOURCE))
14 exampledir=$(cd $topdir/../examples; pwd)
15 functions=${topdir}/functions
17 # Define common functions
18 . ${functions}/common.sh
22 kill -9 `ps -p $killpid -o pid --no-headers` \
23 `ps --ppid $killpid -o pid --no-headers`\
30 Syntax: `basename $0` [-nf] <isofile> <deafile> <dhafile>
32 -nf Do not install Fuel master
37 # maximum allowed deploy time (default three hours)
38 MAXDEPLOYTIME=${MAXDEPLOYTIME-3h}
44 if [ "`whoami`" != "root" ]; then
45 error_exit "You need be root to run this script"
48 # Set initial veriables
53 if [ "$1" == "-nf" ]; then
63 # Setup tmpdir - if TMPDIR env variable is set, use that one
64 # else create in $HOME/fueltmp
65 if [ -n "${TMPDIR}" ]; then
66 if [ -d ${TMPDIR} ]; then
67 tmpdir=${TMPDIR}/fueltmp
68 echo "Using TMPDIR=${TMPDIR}, so tmpdir=${tmpdir}"
70 error_exit "No such directory for TMPDIR: ${TMPDIR}"
73 tmpdir=${HOME}/fueltmp
74 echo "Default: tmpdir=$tmpdir"
77 # Umask must be changed so files created are readable by qemu
80 if [ -d $tmpdir ]; then
81 rm -Rf $tmpdir || error_exit "Could not remove tmpdir $tmpdir"
83 mkdir $tmpdir || error_exit "Could not create tmpdir $tmpdir"
85 isofile=$(cd `dirname $1`; echo `pwd`/`basename $1`)
86 deafile=$(cd `dirname $2`; echo `pwd`/`basename $2`)
87 dhafile=$(cd `dirname $3`; echo `pwd`/`basename $3`)
89 if [ ! -f $isofile ]; then
90 error_exit "Could not find ISO file $isofile"
91 elif [ ! -f $deafile ]; then
92 error_exit "Could not find DEA file $deafile"
93 elif [ ! -f $dhafile ]; then
94 error_exit "Could not find DHA file $dhafile"
98 adapter=`grep "^adapter: " $dhafile | sed 's/.*: //'`
99 if [ -z "$adapter" ]; then
100 error_exit "No adapter in DHA file!"
101 elif [ ! -f $topdir/dha-adapters/${adapter}.sh ]; then
102 error_exit "Could not find adapter for $adapter"
104 . $topdir/dha-adapters/${adapter}.sh $dhafile
108 . ${topdir}/functions/dea-api.sh $deafile
110 # Enable safety catch
111 echo "Enabling auto-kill if deployment exceeds $MAXDEPLOYTIME"
112 (sleep $MAXDEPLOYTIME; echo "Auto-kill of deploy after a timeout of $MAXDEPLOYTIME"; kill $$) &
115 # Enable exit handler
116 trap exit_handler exit
118 # Get Fuel node information
119 fuelIp=`dea getFuelIp` || error_exit "Could not get Fuel IP"
120 fuelNetmask=`dea getFuelNetmask` || error_exit "Could not get Fuel netmask"
121 fuelGateway=`dea getFuelGateway` || error_exit "Could not get Fuel Gateway"
122 fuelHostname=`dea getFuelHostname` || error_exit "Could not get Fuel hostname"
123 fuelDns=`dea getFuelDns` || error_exit "Could not get Fuel DNS"
124 fuelNodeId=`dha getFuelNodeId` || error_exit "Could not get fuel node id"
125 dha useFuelCustomInstall
129 for id in `dha getAllNodeIds`
131 if [ $nofuel -eq 0 -o $fuelCustom -eq 0 ]; then
132 if [ $fuelNodeId -ne $id ]; then
133 echo "Powering off id $id"
137 echo "Powering off id $id"
142 # Install the Fuel master
143 if [ $nofuel -eq 1 ]; then
144 echo "Patching iso file"
146 deployiso="${tmpdir}/deploy-`basename $isofile`"
147 ${functions}/patch-iso.sh $isofile $deployiso $tmpdir \
148 $fuelIp $fuelNetmask $fuelGateway $fuelHostname $fuelDns \
149 || error_exit "Failed to patch ISO"
151 # Swap isofiles from now on
153 if dha useFuelCustomInstall; then
154 echo "Custom Fuel install"
155 dha fuelCustomInstall $isofile || error_exit "Failed to run Fuel custom install"
157 echo "Ordinary Fuel install"
158 . ${functions}/install_iso.sh || error_exit "Failed to install Fuel"
161 echo "Not installing Fuel master"
164 . ${functions}/deploy_env.sh
166 echo "Waiting for one minute for deploy to stabilize"
169 echo "Verifying node status after deployment"
170 # Any node with non-ready status?
171 ssh root@${fuelIp} fuel node 2>/dev/null | tail -n +3 | cut -d "|" -f 2 | \
172 sed 's/ //g' | grep -v ready | wc -l | grep -q "^0$"
173 if [ $? -ne 0 ]; then
174 echo -e "Deploy failed to verify\n"
175 ssh root@${fuelIp} fuel node 2>/dev/null
176 error_exit "Exiting with error status"
178 echo -e "Deployment verified\n"
179 ssh root@${fuelIp} fuel node 2>/dev/null
180 echo -e "\nNow running sanity and smoke health checks"
182 ssh root@${fuelIp} fuel health --env ${envId} --check sanity,smoke \
184 if [ $? -eq 0 ]; then
185 echo "Health checks passed!"
187 error_exit "One or several health checks failed!"
191 echo "Total deployment time: $[(time1-time0)/60] minutes"