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