adding bm verifier
[icn.git] / deploy / metal3 / scripts / 03_verify_deprovisioning.sh
diff --git a/deploy/metal3/scripts/03_verify_deprovisioning.sh b/deploy/metal3/scripts/03_verify_deprovisioning.sh
new file mode 100755 (executable)
index 0000000..97a8a21
--- /dev/null
@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+#set -x
+
+LIBDIR="$(dirname "$(dirname "$(dirname "$PWD")")")"
+
+eval "$(go env)"
+
+source $LIBDIR/env/lib/common.sh
+
+declare -i timeout=60
+declare -i interval=60
+
+function check_deprovisioned {
+    declare -i prev_host_state=0
+    declare -i j=0
+    echo "Baremetal state: 1 means deprovisioned & 0 means not yet deprovisioned"
+    while read -r name username password address; do
+        declare -i current_host_state=0
+        state=$(kubectl get baremetalhosts $name -n metal3 -o json | jq -r '.status.provisioning.state')
+        echo "Baremetal host metal3 state - "$name" : "$state
+
+        if [ $state == "ready" ];then
+            current_host_state=1
+        fi
+
+        echo "Baremetal $name     current_host_state : "$current_host_state
+        echo "Previous Baremetals prev_host_state    : "$prev_host_state
+
+         if [ $j -eq 0 ]; then
+            prev_host_state=$current_host_state
+            ((j+=1))
+            continue
+        fi
+
+        if [ $current_host_state -eq 1 ] && [ $prev_host_state -eq 1 ]; then
+            prev_host_state=1
+        else
+            prev_host_state=0
+        fi
+
+        echo "All Baremetal hosts aggregated state - prev_host_state:"$prev_host_state
+        ((j+=1))
+    done
+    return $prev_host_state
+}
+
+function warm_up_time {
+    echo "Wait for 240s for all baremetal hosts to reboot and network is up"
+    sleep 4m
+}
+
+function wait_for_deprovisioned {
+    all_bmh_deprovisioned=1
+    declare -i k=1
+    while ((timeout > 0)); do
+        echo "Try $k iteration : Wait for $interval seconds to check all bmh state"
+        sleep $interval
+        list_nodes | check_deprovisioned
+        all_bmh_state=$?
+        if [[ $all_bmh_state -eq $all_bmh_deprovisioned ]]; then
+            echo "All the Baremetal hosts are deprovisioned - success"
+            warm_up_time
+            exit 0
+        fi
+        ((timeout-=1))
+        ((k+=1))
+    done
+    exit 1
+}
+
+
+function verify_bm_hosts_cleanup {
+    wait_for_deprovisioned
+}
+
+verify_bm_hosts_cleanup