Use username and password from "os" in nodes.json
[icn.git] / deploy / metal3 / scripts / 03_verify_deprovisioning.sh
1 #!/usr/bin/env bash
2 set -eu -o pipefail
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_deprovisioned {
14     declare -i prev_host_state=0
15     declare -i j=0
16     echo "Baremetal state: 1 means deprovisioned & 0 means not yet deprovisioned"
17     while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; 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 == "ready" ];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_deprovisioned {
53     declare -i k=1
54     while ((timeout > 0)); do
55         echo "Try $k iteration : Wait for $interval seconds to check all bmh state"
56         sleep $interval
57         if ! list_nodes | check_deprovisioned; then
58             echo "All the Baremetal hosts are deprovisioned - success"
59             warm_up_time
60             exit 0
61         fi
62         ((timeout-=1))
63         ((k+=1))
64     done
65     exit 1
66 }
67
68
69 function verify_bm_hosts_cleanup {
70     wait_for_deprovisioned
71 }
72
73 verify_bm_hosts_cleanup