/tests/t0004-module-loading.sh

https://code.google.com/ · Shell · 122 lines · 108 code · 13 blank · 1 comment · 16 complexity · 3cda7df3dad2cf7a46662ae91d620466 MD5 · raw file

  1. #!/bin/sh
  2. test_description='pdsh dynamic module support'
  3. TEST_MODULE_PATH="$(pwd)/test-modules"
  4. . ${srcdir:-.}/test-lib.sh
  5. if ! test_have_prereq DYNAMIC_MODULES; then
  6. skip_all='skipping dynamic module tests, pdsh built with static modules'
  7. test_done
  8. fi
  9. if ! test -f $TEST_MODULE_PATH/a.la -a -f $TEST_MODULE_PATH/b.la; then
  10. echo "$0: Test modules A & B not built, please run \"make check.\"" >&2
  11. exit 1
  12. fi
  13. module_list () {
  14. pdsh -L "$EXTRA_PDSH_ARGS" 2>&1 | \
  15. perl -n -e '\
  16. chomp; ($k,$v) = split(/: */);
  17. $m = $v if ($k eq "Module");
  18. print "$m $v\n" if ($k eq "Active");'
  19. }
  20. loaded_modules() {
  21. module_list | awk '$2 == "yes" {print $1}'
  22. }
  23. conflicting_modules() {
  24. module_list | awk '$2 == "no" {print $1}'
  25. }
  26. module_is_active() {
  27. loaded_modules | while read m; do
  28. if [ "$m" = "$1" ]; then
  29. return 0
  30. fi
  31. done
  32. }
  33. module_is_inactive() {
  34. conflicting_modules | while read m; do
  35. if [ "$m" = "$1" ]; then
  36. return 0
  37. fi
  38. done
  39. }
  40. test_output_matches() {
  41. OUTPUT="$1"
  42. PATTERN="$2"
  43. if ! echo "$OUTPUT" | grep -q "$PATTERN" ; then
  44. say_color error "Error: Didn't find pattern \"$PATTERN\""
  45. say_color info "OUTPUT=$OUTPUT"
  46. false
  47. fi
  48. }
  49. unset EXTRA_PDSH_ARGS
  50. test_expect_success NOTROOT 'PDSH_MODULE_DIR functionality' '
  51. PDSH_MODULE_DIR=$TEST_DIRECTORY/test-modules
  52. module_is_active A && module_is_active B
  53. '
  54. export PDSH_MODULE_DIR="$TEST_DIRECTORY/test-modules"
  55. test_expect_success NOTROOT 'module A takes precedence over B' '
  56. module_is_active misc/A && module_is_inactive misc/B
  57. '
  58. test_expect_success NOTROOT 'pdsh -M B ativates module B' '
  59. EXTRA_PDSH_ARGS="-M B"
  60. module_is_active misc/B && module_is_inactive misc/A
  61. '
  62. test_expect_success NOTROOT 'PDSH_MISC_MODULES option works' '
  63. PDSH_MISC_MODULES=B
  64. module_is_active misc/B && module_is_inactive misc/A
  65. '
  66. test_expect_success NOTROOT '-M option overrides PDSH_MISC_MODULES environment var' '
  67. OUTPUT=$(PDSH_MISC_MODULES=B pdsh -MA -L 2>&1)
  68. say_color error "$OUTPUT"
  69. '
  70. test_expect_success NOTROOT 'pdsh help string correctly displays options of loaded modules' '
  71. OUTPUT=$(pdsh -h 2>&1 | grep ^-a) &&
  72. test_output_matches "$OUTPUT" "Module A" &&
  73. OUTPUT=$(pdsh -M B -h 2>&1 | grep ^-a) &&
  74. test_output_matches "$OUTPUT" "Module B"
  75. '
  76. test_expect_success NOTROOT 'Loading conflicting module with -M causes error' '
  77. OUTPUT=$(pdsh -MA,B 2>&1 | grep Warning)
  78. test_output_matches "$OUTPUT" \
  79. "Failed to initialize requested module \"misc/B\""
  80. '
  81. test_expect_success NOTROOT 'Conflicting modules dont run init()' '
  82. PDSH_MODULE_DIR=$TEST_DIRECTORY/test-modules
  83. if pdsh -q 2>&1 | grep "B: in init"; then
  84. say_color error "Error: init routine for module B run unexpectedly"
  85. false
  86. fi
  87. '
  88. test_expect_success NOTROOT 'Force loaded module runs init()' '
  89. PDSH_MODULE_DIR=$TEST_DIRECTORY/test-modules
  90. if ! pdsh -q -MB 2>&1 | grep "B: in init"; then
  91. say_color error "Error: init routine for module B not run with -M B"
  92. false
  93. fi
  94. '
  95. test_expect_success NOTROOT 'New conflicting module does not run init() with -M' '
  96. PDSH_MODULE_DIR=$TEST_DIRECTORY/test-modules
  97. if pdsh -q -MB 2>&1 | grep "A: in init"; then
  98. say_color error "Error: A init routine run with -M B"
  99. false
  100. fi
  101. '
  102. test_done