Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do users need it? Or it's only for our internal tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spetrosi thank you so much for review.

Based on my understanding, similar to test-moneo.sh.j2 and test-azure-health-checks.sh.j2, this new test script test-aznfs.sh.j2 might be useful for both users and our internal testing processes.

The question is whether to include an option to enable these test installations in future or simply add these test scripts to simplify the process as current method. As we know, other older packages do not have their specific tests integrated as Ansible scripts yet.

For newly added packages, we have two separate testing tasks:

  1. Testing package: defining how to test the package, typically by adding the test within an Ansible script.
  2. Automation: developing the automated test case within the end-to-end (e2e) test repository.

Hi @dgchinner,

Could you please help to check whether I understand the questions about "Do users need it? Or it's only for our internal tests?" correctly? Do we need a overall ansible parameter to control whether need to install test script?

Thank you so much.
Xuemin

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 }}"
Expand Down
187 changes: 187 additions & 0 deletions templates/test-aznfs.sh.j2
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Usage: $(basename "$0") [OPTIONS]

Test Azure NFS Mount Helper (aznfs) installation and functionality

OPTIONS:
-v Verbose mode
-h Show this help message

EXAMPLES:
# Run with default settings
sudo ./test-aznfs.sh

# Run with verbose output
sudo ./test-aznfs.sh -v

EOF
exit 0
}

log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}

verbose_log() {
if [[ $VERBOSE -eq 1 ]]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
fi
}

# ------------------------------------------------------------------------------
# Parse Arguments
# ------------------------------------------------------------------------------

while getopts "vh" opt; do
case $opt in
v)
VERBOSE=1
;;
h)
usage
;;
*)
usage
;;
esac
done

# ------------------------------------------------------------------------------
# Test: Package Installation
# ------------------------------------------------------------------------------

test_aznfs_package() {
log "Test: aznfs package installation..."
echo ""

echo "Checking: aznfs package is installed or not"
if ! rpm -q aznfs >/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 \
# <account-name>.blob.core.windows.net:/<account-name>/<container-name> /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 "$@"
Loading