generated from linux-system-roles/template
-
Notifications
You must be signed in to change notification settings - Fork 6
test: add test script for aznfs package #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "$@" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
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