summaryrefslogtreecommitdiffstats
path: root/fuel/deploy/deploy.sh
blob: 916125e6968c2fe85206550d45c50e419219bcda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# stefan.k.berg@ericsson.com
# jonas.bjurel@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

# Setup locations
topdir=$(cd `dirname $0`; pwd)
functions=${topdir}/functions
tmpdir=$HOME/fueltmp
deployiso=${tmpdir}/deploy.iso
cloud_deploy=$(cd ${topdir}/cloud_deploy; pwd)

# Define common functions
. ${functions}/common.sh

exit_handler() {
  # Remove safety catch
  kill -9 `ps -p $killpid -o pid --no-headers` \
        `ps --ppid $killpid -o pid --no-headers`\
  > /dev/null 2>&1
}

# Set maximum allowed deploy time (default three hours)
MAXDEPLOYTIME=${MAXDEPLOYTIME-3h}

####### MAIN ########

if [ "`whoami`" != "root" ]; then
  error_exit "You need be root to run this script"
fi

if [ $# -eq 0 -o $# -gt 2 ]; then
  error_exit "Argument error"
fi

# Setup tmpdir
if [ -d $tmpdir ]; then
  rm -Rf $tmpdir || error_exit "Could not remove tmpdir $tmpdir"
fi

mkdir $tmpdir || error_exit "Could not create tmpdir $tmpdir"  

if [ ! -f $1 ]; then
  error_exit "Could not find ISO file $1"
else
  isofile=$(cd `dirname $1`; echo `pwd`/`basename $1`)
fi

# If no DEA specified, use the example one
if [ $# -eq 1 ]; then
  deafile=${topdir}/dea.yaml
else
  deafile=$(cd `dirname $2`; echo `pwd`/`basename $2`)
fi
cp ${deafile} ${cloud_deploy}/

if [ ! -f $deafile ]; then
  error-exit "Could not find DEA file $deafile"
fi

# Enable safety catch
echo "Enabling auto-kill if deployment exceeds $MAXDEPLOYTIME"
(sleep $MAXDEPLOYTIME; echo "Auto-kill of deploy after a timeout of $MAXDEPLOYTIME"; kill $$) &
killpid=$!

# Enable exit handler
trap exit_handler exit

# Stop all VMs
for node in `ls libvirt/vms`
do
  virsh destroy $node >/dev/null 2>&1
done


# Install the Fuel master
# (Convert to functions at later stage)
echo "Patching iso file"
${functions}/patch-iso.sh $isofile $deployiso $tmpdir || error_exit "Failed to patch ISO"
# Swap isofiles from now on
isofile=$deployiso
. ${functions}/install_iso.sh

python ${cloud_deploy}/cloud_deploy.py

echo "Waiting for five minutes for deploy to stabilize"
sleep 5m

echo "Verifying node status after deployment"
# Any node with non-ready status?
ssh root@10.20.0.2 fuel node 2>/dev/null | tail -n +3 | cut -d "|" -f 2 | \
  sed 's/ //g' | grep -v ready | wc -l | grep -q "^0$"
if [ $? -ne 0 ]; then
  echo "Deploy failed to verify"
  ssh root@10.20.0.2 fuel node 2>/dev/null
  error_exit "Exiting with error status"
else
  ssh root@10.20.0.2 fuel node 2>/dev/null
  echo "Deployment verified"
fi