diff --git a/tasks/main.yml b/tasks/main.yml index fc30694..a5003dd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -375,7 +375,15 @@ ternary('ansible.posix.rhel_rpm_ostree', omit) }}" register: __hpc_azure_packages_install until: __hpc_azure_packages_install is success - + + - name: Install package aznfs test script + template: + src: test-aznfs.sh.j2 + dest: "{{ __hpc_azure_tests_dir }}/test-aznfs.sh" + owner: root + group: root + mode: '0755' + - name: Create Azure HPC resource directories file: path: "{{ item }}" diff --git a/templates/test-aznfs.sh.j2 b/templates/test-aznfs.sh.j2 new file mode 100644 index 0000000..51ee9a5 --- /dev/null +++ b/templates/test-aznfs.sh.j2 @@ -0,0 +1,187 @@ +#!/usr/bin/env bash +# These are templates, not actual shell scripts, so tell shellcheck to +# ignore the templated parts +# shellcheck disable=all +{{ ansible_managed | comment }} +{{ "system_role:hpc" | comment(prefix="", postfix="") }} +# shellcheck enable=all +# SPDX-License-Identifier: MIT +# +# Azure NFS Mount Helper Test Script +# Usage: ./test-aznfs.sh [-v] +# + +set -euo pipefail + +# Default configuration +VERBOSE=0 + +# Test counter +PASSED=0 + +# ------------------------------------------------------------------------------ +# Helper Functions +# ------------------------------------------------------------------------------ + +pass() { + echo "[PASS] $1" + PASSED=$((PASSED + 1)) +} + +fail() { + echo "[FAIL] $1" + exit 1 +} + +usage() { + cat </dev/null 2>&1; then + fail "aznfs package is not installed" + fi + pass "aznfs package is installed" + + if [[ $VERBOSE -eq 1 ]]; then + verbose_log "Package: $(rpm -q aznfs)" + fi + + echo "" +} + +# ------------------------------------------------------------------------------ +# Test: Service Status +# ------------------------------------------------------------------------------ + +test_aznfs_service() { + log "Test: aznfswatchdog status..." + echo "" + + echo "Checking: aznfswatchdog service is active or not" + if ! systemctl is-active --quiet aznfswatchdog; then + fail "aznfswatchdog service is not active" + fi + pass "aznfswatchdog service is active" + + # Check if aznfswatchdog service is enabled (verbose mode) + if [[ $VERBOSE -eq 1 ]]; then + if ! systemctl is-enabled --quiet aznfswatchdog 2>/dev/null; then + verbose_log "Warning: aznfswatchdog service is not enabled" + fi + fi + + echo "" +} + +# ------------------------------------------------------------------------------ +# Test: Check "mount.aznfs" command ready or not. +# It does not cover below test for real mount action: +# sudo mount -t aznfs -o vers=3 \ +# .blob.core.windows.net:// /mountpoint +# ------------------------------------------------------------------------------ + +test_aznfs_mount() { + log "Test: aznfs mount readiness validation" + echo "" + + echo "Checking: mount.aznfs command is available or not" + if ! command -v mount.aznfs >/dev/null 2>&1; then + fail "mount.aznfs command not found" + fi + pass "mount.aznfs is available" + + echo "Checking: general NFS mount status" + # Note: "type nfs" but not "type aznfs" in the mount output + if mount | grep -q "type nfs"; then + mount_count=$(mount | grep "type nfs" | wc -l) + pass "Found $mount_count active nfs mount(s)" + if [[ $VERBOSE -eq 1 ]]; then + verbose_log "Active nfs mounts:" + mount | grep "type nfs" + fi + else + pass "No active nfs mounts" + fi + + echo "" +} + +# ------------------------------------------------------------------------------ +# Main +# ------------------------------------------------------------------------------ + +main() { + log "========================================" + log "Azure NFS Mount Helper (aznfs) Test" + log "========================================" + echo "" + + test_aznfs_package + + test_aznfs_service + + test_aznfs_mount + + # If we get here, all tests passed + echo "" + log "========================================" + log "All tests passed ($PASSED)" + log "========================================" + exit 0 +} + +main "$@"