From 2bac64d8bc11df75d42f6355c337f058f20c5121 Mon Sep 17 00:00:00 2001 From: Xuemin Li Date: Fri, 27 Feb 2026 20:21:47 +0800 Subject: [PATCH] test: add test script for aznfs package Add a test script to validate Azure NFS Mount Helper (aznfs) installation and basic service. This readiness validation is to ensure aznfs is properly installed and ready for use before performing real mount operations, mainly check below items: - aznfs package is installed - aznfswatchdog service is active - mount.aznfs command is available JIRA: RHELHPC-124 Signed-off-by: Xuemin Li --- tasks/main.yml | 10 +- templates/test-aznfs.sh.j2 | 187 +++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 templates/test-aznfs.sh.j2 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 "$@"