ce42ebac6aacd6afb60c436e059d019d12f36909
[icn.git] / deploy / metal3-vm / 04_verify.sh
1 #!/usr/bin/env bash
2 set -eu -o pipefail
3
4 # shellcheck disable=SC1091
5 source lib/common.sh
6
7 declare -i timeout=30
8 declare -i interval=60
9
10 function check_provisioned {
11     declare -i prev_host_state=0
12     declare -i j=0
13     echo "VM state: 1 means provisioned & 0 means not yet provisioned"
14     while read -r name address user password mac; do
15         declare -i current_host_state=0
16         state=$(kubectl get baremetalhosts $name -n metal3 -o json | jq -r '.status.provisioning.state')
17         echo "VM host metal3 state - "$name" : "$state
18
19         if [ $state == "provisioned" ];then
20             current_host_state=1
21         fi
22
23         echo "VM $name current_host_state : "$current_host_state
24         echo "VMs      prev_host_state    : "$prev_host_state
25
26          if [ $j -eq 0 ]; then
27             prev_host_state=$current_host_state
28             ((j+=1))
29             continue
30         fi
31
32         if [ $current_host_state -eq 1 ] && [ $prev_host_state -eq 1 ]; then
33             prev_host_state=1
34         else
35             prev_host_state=0
36         fi
37
38         echo "All VM hosts aggregated state - prev_host_state:"$prev_host_state
39         ((j+=1))
40     done
41     return $prev_host_state
42 }
43
44 function warm_up_time {
45     echo "Wait for 75s for all VM to reboot and network is up"
46     sleep 75
47 }
48
49 function wait_for_provisioned {
50     declare -i k=1
51     declare -i t=$timeout
52     while ((t > 0)); do
53         echo "Try $k/$timeout iteration : Wait for $interval seconds to check all bmh state"
54         sleep $interval
55         if ! list_nodes | check_provisioned; then
56             echo "All the VMs are provisioned - success"
57             warm_up_time
58             exit 0
59         fi
60         ((t-=1))
61         ((k+=1))
62     done
63     exit 1
64 }
65
66 function verify_bm_hosts {
67     wait_for_provisioned
68 }
69
70 verify_bm_hosts