summaryrefslogtreecommitdiffstats
path: root/fuel/deploy/deploy_fuel.sh
blob: 8cb72b7faa245a982038938de0b8ac09832dd1b5 (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
#!/bin/bash
# Deploy in deployFuel has the "configure host-network,
# install fuel, configure vm and start it" meaning
set -o xtrace
set -o errexit
set -o nounset
set -o pipefail

if [ $# -ne 2 ]; then
    echo "Usage: $0 <iso-file> <interface>"
    exit 1
fi

readonly iso_file=$1
readonly interface=$2
readonly vm_name="fuel_opnfv"
readonly ssh_fuel_vm="sshpass -p r00tme
                          ssh -o UserKnownHostsFile=/dev/null
                              -o StrictHostKeyChecking=no
                              -q
                              root@192.168.0.11"
readonly RUN_INSTALL="${RUN_INSTALL:-false}"
readonly DEV="${DEV:-false}"

# poll is not real timeout, commands can take some undefined time to execute
# it is a count of how many times to try while sleeping shortly
# in between checks
readonly poll_virtinstall=1800
readonly poll_fuel_startup=1200
readonly poll_deployment=2150
readonly fuel_logfile="/var/log/puppet/bootstrap_admin_node.log"

cat >$interface.xml <<EOF
<network>
  <name>$interface</name>
  <forward dev='$interface' mode='bridge'>
    <interface dev='$interface'/>
  </forward>
</network>
EOF

cleanup_previous_run() {
    echo "Cleaning up previous run"
    set +eu
    virsh net-destroy $interface > /dev/null 2>&1
    virsh net-undefine $interface > /dev/null 2>&1
    virsh destroy $vm_name > /dev/null 2>&1
    virsh undefine $vm_name > /dev/null 2>&1
    set -eu
}

create_disk_and_install() {
    rm -rf $vm_name.qcow2
    qemu-img create -f qcow2 -o preallocation=metadata $vm_name.qcow2 60G
    virt-install --connect=qemu:///system \
        --name=$vm_name \
        --network=network:$interface \
        --ram 2048 --vcpus=4,cores=2 --check-cpu --hvm \
        --disk path=$vm_name.qcow2,format=qcow2,device=disk,bus=virtio \
        --noautoconsole --vnc \
        --cdrom $iso_file
}

wait_for_virtinstall() {
    # Workaround for virt-install --wait which restarts vm
    # too fast too attach disk
    echo "Waiting for virt-install to finish..."
    set +eu
    stopped=false
    for i in $(seq 0 $poll_virtinstall); do
        virsh_out=`virsh list | grep "$vm_name"`
        if [ -z "$virsh_out" ]; then
            stopped=true
            break
        fi
        sleep 2
    done
    set -eu
}

wait_for_fuel_startup() {
    echo "Wait for fuel to start up..."
    for i in $(seq 0 $poll_fuel_startup); do
        sleep 2 && echo -n "$i "
        $ssh_fuel_vm grep complete $fuel_logfile &&
            echo "Fuel bootstrap is done, deployment should have started now" &&
            return 0
    done
    return 1
}


cleanup_previous_run
virsh net-define $interface.xml
virsh net-start $interface
create_disk_and_install
wait_for_virtinstall

echo "Starting $vm_name after installation in 6s..." && sleep 6s
set +eu

virsh start $vm_name
if ! wait_for_fuel_startup; then
    echo "Fuel failed to start up"
    exit 1
fi