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
18 # Define common functions
19 . ${functions}/common.sh
23 kill -9 `ps -p $killpid -o pid --no-headers` \
24 `ps --ppid $killpid -o pid --no-headers`\
31 Syntax: `basename $0` [-nf] <isofile> <deafile> <dhafile>
33 -nf Do not install Fuel master
38 # maximum allowed deploy time (default three hours)
39 MAXDEPLOYTIME=${MAXDEPLOYTIME-3h}
45 if [ "`whoami`" != "root" ]; then
46 error_exit "You need be root to run this script"
49 # Set initial veriables
54 if [ "$1" == "-nf" ]; then
65 if [ -d $tmpdir ]; then
66 rm -Rf $tmpdir || error_exit "Could not remove tmpdir $tmpdir"
68 mkdir $tmpdir || error_exit "Could not create tmpdir $tmpdir"
70 isofile=$(cd `dirname $1`; echo `pwd`/`basename $1`)
71 deafile=$(cd `dirname $2`; echo `pwd`/`basename $2`)
72 dhafile=$(cd `dirname $3`; echo `pwd`/`basename $3`)
74 if [ ! -f $isofile ]; then
75 error_exit "Could not find ISO file $isofile"
76 elif [ ! -f $deafile ]; then
77 error-exit "Could not find DEA file $deafile"
78 elif [ ! -f $dhafile ]; then
79 error-exit "Could not find DHA file $dhafile"
83 adapter=`grep "^adapter: " $dhafile | sed 's/.*: //'`
84 if [ -z "$adapter" ]; then
85 error_exit "No adapter in DHA file!"
86 elif [ ! -f $topdir/dha-adapters/${adapter}.sh ]; then
87 error_exit "Could not find adapter for $adapter"
89 . $topdir/dha-adapters/${adapter}.sh $dhafile
93 . ${topdir}/functions/dea-api.sh $deafile
96 echo "Enabling auto-kill if deployment exceeds $MAXDEPLOYTIME"
97 (sleep $MAXDEPLOYTIME; echo "Auto-kill of deploy after a timeout of $MAXDEPLOYTIME"; kill $$) &
100 # Enable exit handler
101 trap exit_handler exit
103 # Get Fuel node information
104 fuelIp=`dea getFuelIp` || error_exit "Could not get Fuel IP"
105 fuelNetmask=`dea getFuelNetmask` || error_exit "Could not get Fuel netmask"
106 fuelGateway=`dea getFuelGateway` || error_exit "Could not get Fuel Gateway"
107 fuelHostname=`dea getFuelHostname` || error_exit "Could not get Fuel hostname"
108 fuelDns=`dea getFuelDns` || error_exit "Could not get Fuel DNS"
109 fuelNodeId=`dha getFuelNodeId` || error_exit "Could not get fuel node id"
110 dha useFuelCustomInstall
114 for id in `dha getAllNodeIds`
116 if [ $nofuel -eq 0 -o $fuelCustom -eq 0 ]; then
117 if [ $fuelNodeId -ne $id ]; then
118 echo "Powering off id $id"
122 echo "Powering off id $id"
127 # Install the Fuel master
128 if [ $nofuel -eq 1 ]; then
129 echo "Patching iso file"
131 deployiso="${tmpdir}/deploy-`basename $isofile`"
132 ${functions}/patch-iso.sh $isofile $deployiso $tmpdir \
133 $fuelIp $fuelNetmask $fuelGateway $fuelHostname $fuelDns \
134 || error_exit "Failed to patch ISO"
136 # Swap isofiles from now on
138 if dha useFuelCustomInstall; then
139 echo "Custom Fuel install"
140 dha fuelCustomInstall $isofile || error_exit "Failed to run Fuel custom install"
142 echo "Ordinary Fuel install"
143 . ${functions}/install_iso.sh || error_exit "Failed to install Fuel"
146 echo "Not installing Fuel master"
149 . ${functions}/deploy_env.sh
151 echo "Waiting for one minute for deploy to stabilize"
154 echo "Verifying node status after deployment"
155 # Any node with non-ready status?
156 ssh root@${fuelIp} fuel node 2>/dev/null | tail -n +3 | cut -d "|" -f 2 | \
157 sed 's/ //g' | grep -v ready | wc -l | grep -q "^0$"
158 if [ $? -ne 0 ]; then
159 echo -e "Deploy failed to verify\n"
160 ssh root@${fuelIp} fuel node 2>/dev/null
161 error_exit "Exiting with error status"
163 echo -e "Deployment verified\n"
164 ssh root@${fuelIp} fuel node 2>/dev/null
165 echo -e "\nNow running sanity and smoke health checks"
167 ssh root@${fuelIp} fuel health --env ${envId} --check sanity,smoke \
169 if [ $? -eq 0 ]; then
170 echo "Health checks passed!"
172 error_exit "One or several health checks failed!"
176 echo "Total deployment time: $[(time1-time0)/60] minutes"