8cb72b7faa245a982038938de0b8ac09832dd1b5
[genesis.git] / fuel / deploy / deploy_fuel.sh
1 #!/bin/bash
2 # Deploy in deployFuel has the "configure host-network,
3 # install fuel, configure vm and start it" meaning
4 set -o xtrace
5 set -o errexit
6 set -o nounset
7 set -o pipefail
8
9 if [ $# -ne 2 ]; then
10     echo "Usage: $0 <iso-file> <interface>"
11     exit 1
12 fi
13
14 readonly iso_file=$1
15 readonly interface=$2
16 readonly vm_name="fuel_opnfv"
17 readonly ssh_fuel_vm="sshpass -p r00tme
18                           ssh -o UserKnownHostsFile=/dev/null
19                               -o StrictHostKeyChecking=no
20                               -q
21                               root@192.168.0.11"
22 readonly RUN_INSTALL="${RUN_INSTALL:-false}"
23 readonly DEV="${DEV:-false}"
24
25 # poll is not real timeout, commands can take some undefined time to execute
26 # it is a count of how many times to try while sleeping shortly
27 # in between checks
28 readonly poll_virtinstall=1800
29 readonly poll_fuel_startup=1200
30 readonly poll_deployment=2150
31 readonly fuel_logfile="/var/log/puppet/bootstrap_admin_node.log"
32
33 cat >$interface.xml <<EOF
34 <network>
35   <name>$interface</name>
36   <forward dev='$interface' mode='bridge'>
37     <interface dev='$interface'/>
38   </forward>
39 </network>
40 EOF
41
42 cleanup_previous_run() {
43     echo "Cleaning up previous run"
44     set +eu
45     virsh net-destroy $interface > /dev/null 2>&1
46     virsh net-undefine $interface > /dev/null 2>&1
47     virsh destroy $vm_name > /dev/null 2>&1
48     virsh undefine $vm_name > /dev/null 2>&1
49     set -eu
50 }
51
52 create_disk_and_install() {
53     rm -rf $vm_name.qcow2
54     qemu-img create -f qcow2 -o preallocation=metadata $vm_name.qcow2 60G
55     virt-install --connect=qemu:///system \
56         --name=$vm_name \
57         --network=network:$interface \
58         --ram 2048 --vcpus=4,cores=2 --check-cpu --hvm \
59         --disk path=$vm_name.qcow2,format=qcow2,device=disk,bus=virtio \
60         --noautoconsole --vnc \
61         --cdrom $iso_file
62 }
63
64 wait_for_virtinstall() {
65     # Workaround for virt-install --wait which restarts vm
66     # too fast too attach disk
67     echo "Waiting for virt-install to finish..."
68     set +eu
69     stopped=false
70     for i in $(seq 0 $poll_virtinstall); do
71         virsh_out=`virsh list | grep "$vm_name"`
72         if [ -z "$virsh_out" ]; then
73             stopped=true
74             break
75         fi
76         sleep 2
77     done
78     set -eu
79 }
80
81 wait_for_fuel_startup() {
82     echo "Wait for fuel to start up..."
83     for i in $(seq 0 $poll_fuel_startup); do
84         sleep 2 && echo -n "$i "
85         $ssh_fuel_vm grep complete $fuel_logfile &&
86             echo "Fuel bootstrap is done, deployment should have started now" &&
87             return 0
88     done
89     return 1
90 }
91
92
93 cleanup_previous_run
94 virsh net-define $interface.xml
95 virsh net-start $interface
96 create_disk_and_install
97 wait_for_virtinstall
98
99 echo "Starting $vm_name after installation in 6s..." && sleep 6s
100 set +eu
101
102 virsh start $vm_name
103 if ! wait_for_fuel_startup; then
104     echo "Fuel failed to start up"
105     exit 1
106 fi