Skip to content

Commit

Permalink
[PLAt-15133][PLAT-15332] Fix the preflight check for disk mount
Browse files Browse the repository at this point in the history
Summary:
This diff fixes -
1. Preflight checks for disk mount.
2. Formatting for preflight checks.

Test Plan: Manually verified the preflight checks

Reviewers: anijhawan, nbhatia, skhilar

Reviewed By: anijhawan, skhilar

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D38117
  • Loading branch information
Vars-07 committed Sep 18, 2024
1 parent 10b5009 commit 3d33b3e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
10 changes: 5 additions & 5 deletions managed/node-agent/resources/ynp/commands/provision_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ def _run_script(self, script_path):
def add_results_helper(self, file):
file.write("""
# Initialize the JSON results array
json_results='{"results":['
json_results='{\n"results":[\n'
add_result() {
local check="$1"
local result="$2"
local message="$3"
if [ "${#json_results}" -gt 12 ]; then
json_results+=','
if [ "${#json_results}" -gt 20 ]; then
json_results+=',\n'
fi
json_results+='{"check":"'$check'","result":"'$result'","message":"'$message'"}'
json_results+=' {\n "check": "'$check'",\n "result": "'$result'",\n "message": "'$message'"\n }'
}
""")

Expand All @@ -96,7 +96,7 @@ def print_results_helper(self, file):
if [[ $json_results == *'"result":"FAIL"'* ]]; then
any_fail=1
fi
json_results+=']}'
json_results+='\n]}'
# Output the JSON
echo "$json_results"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ fi

threshold=49 #Gigabytes
# Convert the space-separated string to an array in bash
IFS=' ' read -r -a mount_points_array <<< {{ mount_points }}
mount_points="{{ mount_points | default('') | trim }}"
IFS=' ' read -ra mount_points_array <<< "$mount_points"
# Verify each mount point
for mount_point in "${mount_point_array[@]}"; do
for mount_point in "${mount_points_array[@]}"; do
if [ -d "$mount_point" ]; then
if [ -w "$mount_point" ] && [ $(( $(stat -c %a "$mount_point") % 10 & 2 )) -ne 0 ]; then
result="PASS"
Expand All @@ -111,19 +112,21 @@ for mount_point in "${mount_point_array[@]}"; do
fi
add_result "$mount_point Check" "$result" "$message"

# Get the available disk space in gigabytes.
free_space_gb=$(df -BG --output=avail "$MOUNT_POINT" | tail -n 1 | tr -d 'G ')
if [ "$free_space_gb" -gt "$threshold" ]; then
result="PASS"
message="Sufficient disk space available: ${AVAILABLE}G"
echo "[PASS] $message"
else
result="FAIL"
message="Insufficient disk space: ${free_space_gb}G available, ${threshold}G required"
echo "[FAIL] $message"
any_fail=1
if [ -d "$mount_point" ]; then
# Get the available disk space in gigabytes.
free_space_gb=$(df -BG --output=avail "$mount_point" | tail -n 1 | tr -d 'G ')
if [ "$free_space_gb" -gt "$threshold" ]; then
result="PASS"
message="Sufficient disk space available: ${free_space_gb}G"
echo "[PASS] $message"
else
result="FAIL"
message="Insufficient disk space: ${free_space_gb}G available, ${threshold}G required"
echo "[FAIL] $message"
any_fail=1
fi
add_result "$mount_point Free space check" "$result" "$message"
fi
add_result "$mount_point Free space check" "$result" "$message"
done

platform_id=$(grep -oP '(?<=^PLATFORM_ID=).+' /etc/os-release | tr -d '"')
Expand Down

0 comments on commit 3d33b3e

Please sign in to comment.