5d267e6adea396b9ce3d1b8a9b08369c051da269
[genesis.git] / fuel / prototypes / libvirt / deploy / deploy.sh
1 #!/bin/bash
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 ##############################################################################
11
12 # Setup locations
13 topdir=$(cd `dirname $0`; pwd)
14 exampledir=$(cd $topdir/../examples; pwd)
15 functions=${topdir}/functions
16 tmpdir=$HOME/fueltmp
17 deployiso=${tmpdir}/deploy.iso
18
19 # Define common functions
20 . ${functions}/common.sh
21
22 exit_handler() {
23   # Remove safety catch
24   kill $killpid
25 }
26
27 ####### MAIN ########
28
29 if [ "`whoami`" != "root" ]; then
30   error_exit "You need be root to run this script"
31 fi
32
33 if [ $# -eq 0 -o $# -gt 2 ]; then
34   error_exit "Argument error"
35 fi
36
37 # Setup tmpdir
38 if [ -d $tmpdir ]; then
39   rm -Rf $tmpdir || error_exit "Coul not remove tmpdir $tmpdir"
40 fi
41
42 mkdir $tmpdir || error_exit "Could not create tmpdir $tmpdir"  
43
44 if [ ! -f $1 ]; then
45   error_exit "Could not find ISO file $1"
46 else
47   isofile=$(cd `dirname $1`; echo `pwd`/`basename $1`)
48 fi
49
50 # If no DEA specified, use the example one
51 if [ $# -eq 1 ]; then
52   deafile=${exampledir}/libvirt_dea.yaml
53 else
54   deafile=$(cd `dirname $2`; echo `pwd`/`basename $2`)
55 fi
56
57 if [ ! -f $deafile ]; then
58   error-exit "Could not find DEA file $deafile"
59 fi
60
61
62 # Enable safety catch at three hours
63 (sleep 3h; kill $$) &
64 killpid=$!
65
66 # Enable exit handler
67 trap exit_handler exit
68
69
70 # Stop all VMs
71 for node in controller1 controller2 controller3 compute4 compute5 fuel-master
72 do
73   virsh destroy $node >/dev/null 2>&1
74 done
75
76 # Install the Fuel master
77 # (Convert to functions at later stage)
78 echo "Patching iso file"
79 ${functions}/patch-iso.sh $isofile $deployiso $tmpdir || error_exit "Failed to patch ISO"
80 # Swap isofiles from now on
81 isofile=$deployiso
82 . ${functions}/install_iso.sh
83 . ${functions}/deploy_env.sh
84
85 echo "Waiting for five minutes for deploy to stabilize"
86 sleep 5m
87
88 echo "Verifying node status after deployment"
89 # Any node with non-ready status?
90 ssh root@10.20.0.2 fuel node 2>/dev/null | tail -n +3 | cut -d "|" -f 2 | \
91   sed 's/ //g' | grep -v ready | wc -l | grep -q "^0$"
92 if [ $? -ne 0 ]; then
93   echo "Deploy failed to verify"
94   ssh root@10.20.0.2 fuel node 2>/dev/null
95   error_exit "Exiting with error status"
96 else
97   ssh root@10.20.0.2 fuel node 2>/dev/null
98   echo "Deployment verified"
99 fi
100