/tests/t2001-ssh.sh

https://code.google.com/ · Shell · 201 lines · 179 code · 11 blank · 11 comment · 1 complexity · 6d8b8207e7047a0789d35867367b8d3a MD5 · raw file

  1. #!/bin/sh
  2. test_description='pdsh ssh module tests'
  3. . ${srcdir:-.}/test-lib.sh
  4. if ! test_have_prereq MOD_RCMD_SSH; then
  5. skip_all='skipping ssh tests, ssh module not available'
  6. test_done
  7. fi
  8. #
  9. # Create ssh wrapper script that echoes its own arguments. This allows
  10. # the following tests to run without ssh installed
  11. #
  12. test_expect_success 'create ssh dummy script' '
  13. echo "#!$SHELL_PATH" >ssh &&
  14. echo "echo \"\$@\"" >>ssh &&
  15. chmod 755 ssh
  16. '
  17. export PATH=.:$PATH
  18. unset PDSH_SSH_ARGS PDSH_SSH_ARGS_APPEND
  19. test_expect_success 'ssh module runs' '
  20. OUTPUT=$(pdsh -Rssh -w foo command)
  21. '
  22. test_debug '
  23. echo Output: "$OUTPUT"
  24. '
  25. test_expect_success 'ssh dummy script works' '
  26. echo "$OUTPUT" | grep "foo: .*foo command"
  27. '
  28. test_expect_success 'ssh works with DSHPATH' '
  29. OUTPUT=$(DSHPATH=/test/path pdsh -Rssh -w foo command) &&
  30. echo "$OUTPUT" | grep "foo: .*foo PATH=/test/path; *command"
  31. '
  32. test_debug '
  33. echo Output: "$OUTPUT"
  34. '
  35. test_expect_success 'have ssh connect timeout option' '
  36. SSH_CONNECT_TIMEOUT_OPTION=$(sed -ne "s/#define SSH_CONNECT_TIMEOUT_OPTION \"\(.*\)\"/\1/p" ${PDSH_BUILD_DIR}/config.h) &&
  37. test -n "$SSH_CONNECT_TIMEOUT_OPTION"
  38. '
  39. test_debug '
  40. echo "SSH_CONNECT_TIMEOUT_OPTION=\"$SSH_CONNECT_TIMEOUT_OPTION\""
  41. '
  42. test_expect_success 'ssh works with connect timeout' '
  43. OPT=$(printf -- "$SSH_CONNECT_TIMEOUT_OPTION" 55) &&
  44. OUTPUT=$(pdsh -t55 -Rssh -w foo command) &&
  45. echo "$OUTPUT" | grep -- "$OPT"
  46. '
  47. test_debug '
  48. echo Output: "$OUTPUT"
  49. '
  50. test_expect_success 'ssh and pdcp work together' '
  51. ln -s $PDSH_BUILD_DIR/src/pdsh/pdsh pdcp && touch jnk &&
  52. OUTPUT=$(pdcp -Rssh -w foo jnk /tmp 2>&1 || :) &&
  53. echo "$OUTPUT" | grep "pdcp -z /tmp"
  54. '
  55. test_debug '
  56. echo Output: "$OUTPUT"
  57. '
  58. test_expect_success 'PDSH_SSH_ARGS works' '
  59. OUTPUT=$(PDSH_SSH_ARGS="-p 922 -l%u %h" pdsh -luser -Rssh -wfoo hostname) &&
  60. echo "$OUTPUT" | grep "[-]p 922 -luser foo hostname"
  61. '
  62. test_debug '
  63. echo Output: "$OUTPUT"
  64. '
  65. test_expect_success 'PDSH_SSH_ARGS does not require %h' '
  66. OUTPUT=$(PDSH_SSH_ARGS="-p 888 -l%u" pdsh -luser -Rssh -wfoo hostname)
  67. echo "$OUTPUT" | grep "[-]p 888 -luser foo hostname"
  68. '
  69. test_debug '
  70. echo Output: "$OUTPUT"
  71. '
  72. test_expect_success 'PDSH_SSH_ARGS does not require %u' '
  73. OUTPUT=$(PDSH_SSH_ARGS="-p 888 %h" pdsh -ltestuser -Rssh -wfoo hostname)
  74. echo "$OUTPUT" | grep "[-]ltestuser"
  75. '
  76. test_debug '
  77. echo Output: "$OUTPUT"
  78. '
  79. test_expect_success 'PDSH_SSH_ARGS does not force %u when ruser not set (Issue 39)' '
  80. OUTPUT=$(PDSH_SSH_ARGS="-p 888 %h" pdsh -Rssh -wfoo hostname)
  81. echo "$OUTPUT" | grep "[-]l"
  82. test $? -ne 0
  83. '
  84. test_debug '
  85. echo Output: "$OUTPUT"
  86. '
  87. test_expect_success 'ssh does not set -l%u by default (Issue 40)' '
  88. OUTPUT=$(pdsh -Rssh -wfoo hostname)
  89. echo "$OUTPUT" | grep "[-]l"
  90. test $? -ne 0
  91. '
  92. test_debug '
  93. echo Output: "$OUTPUT"
  94. '
  95. test_expect_success 'ssh sets -l%u when ruser != luser' '
  96. OUTPUT=$(pdsh -Rssh -wfoo,testuser@bar hostname | grep bar) &&
  97. echo "$OUTPUT" | grep "[-]ltestuser"
  98. '
  99. test_debug '
  100. echo Output: "$OUTPUT"
  101. '
  102. test_expect_success 'ssh does not set -l%u when ruser == luser (Issue 40)' '
  103. OUTPUT=$(pdsh -Rssh -wfoo,testuser@bar hostname | grep foo) &&
  104. echo "$OUTPUT" | grep "[-]l"
  105. test $? -ne 0
  106. '
  107. test_debug '
  108. echo Output: "$OUTPUT"
  109. '
  110. test_expect_success 'PDSH_SSH_ARGS without %u inserts %u before %h' '
  111. OUTPUT=$(PDSH_SSH_ARGS="-p 888 %h" pdsh -ltestuser -Rssh -wfoo hostname)
  112. echo "$OUTPUT" | grep "[-]p 888 -ltestuser foo hostname"
  113. '
  114. test_debug '
  115. echo Output: "$OUTPUT"
  116. '
  117. test_expect_success 'PDSH_SSH_ARGS does not require %u or %h' '
  118. OUTPUT=$(PDSH_SSH_ARGS="-p 777" pdsh -ltestuser -Rssh -wfoo hostname)
  119. echo "$OUTPUT" | grep "[-]p 777 -ltestuser foo hostname"
  120. '
  121. test_debug '
  122. echo Output: "$OUTPUT"
  123. '
  124. test_expect_success 'PDSH_SSH_ARGS_APPEND works' '
  125. OUTPUT=$(PDSH_SSH_ARGS_APPEND="-p 922" pdsh -Rssh -wfoo hostname) &&
  126. echo "$OUTPUT" | grep "[-]p 922"
  127. '
  128. test_debug '
  129. echo Output: "$OUTPUT"
  130. '
  131. test_expect_success 'PDSH_SSH_ARGS_APPEND are added to PDSH_SSH_ARGS' '
  132. OUTPUT=$(PDSH_SSH_ARGS_APPEND="-p 922" PDSH_SSH_ARGS="-x -a -l%u %h" \
  133. pdsh -Rssh -lfoouser -wfoo hostname) &&
  134. echo "$OUTPUT" | grep "[-]p 922 -x -a -lfoouser foo hostname"
  135. '
  136. test_debug '
  137. echo Output: "$OUTPUT"
  138. '
  139. test_expect_success 'interactive mode works with ssh (Issue 14)' '
  140. OUTPUT=$(echo test command line | pdsh -Rssh -wfoo)
  141. echo "$OUTPUT" | grep "test command line"
  142. '
  143. test_debug '
  144. echo Output: "$OUTPUT"
  145. '
  146. #
  147. # Exit code tests:
  148. #
  149. # If adding new general tests for ssh module, place above here,
  150. # as the ssh dummy script is rewritten for exit code specific testing.
  151. #
  152. test_expect_success 'create ssh dummy script for exit code testing' '
  153. echo "#!$SHELL_PATH" >ssh
  154. echo "# Usage: $0 -n <this rank> -i <failing rank> -e <exitcode> " >>ssh
  155. echo "while getopts \":n:i:e:l:\" opt; do " >>ssh
  156. echo " case \$opt in" >>ssh
  157. echo " n) RANK=\$OPTARG ;;" >>ssh
  158. echo " i) FAILRANK=\$OPTARG ;;" >>ssh
  159. echo " e) EXITCODE=\$OPTARG ;;" >>ssh
  160. echo " l) ;;" >>ssh
  161. echo " esac" >>ssh
  162. echo "done" >>ssh
  163. echo "" >>ssh
  164. echo "if test \$RANK -eq \$FAILRANK; then exit \$EXITCODE; fi" >>ssh
  165. echo "exit 0" >>ssh
  166. chmod 755 ssh
  167. '
  168. test_expect_success 'ssh dummy script is functional' '
  169. TEST_EXIT_CODE=$(random 254)
  170. echo "$TEST_EXIT_CODE"
  171. ssh -n 1 -i 0 &&
  172. test_expect_code "$TEST_EXIT_CODE" ssh -lfoo -n 1 -i 1 -e $TEST_EXIT_CODE
  173. test_expect_code 0 ssh -lxxx -n0 -i255 -e $TEST_EXIT_CODE
  174. '
  175. test_expect_success 'ssh works with pdsh -S' '
  176. TEST_EXIT_CODE=$(random 254) &&
  177. export PDSH_SSH_ARGS="-n%n -i0 -e$TEST_EXIT_CODE"
  178. test_expect_code "$TEST_EXIT_CODE" pdsh -Rssh -S -w foo0 command
  179. '
  180. unset PDSH_SSH_ARGS
  181. test_expect_success 'ssh works with pdsh -S and multiple targets' '
  182. for n in $(seq 1 24); do
  183. TEST_EXIT_CODE=$(random 254) &&
  184. FAILING_RANK=$(random $n) &&
  185. export PDSH_SSH_ARGS="-n%n -i$FAILING_RANK -e$TEST_EXIT_CODE"
  186. test_expect_code "$TEST_EXIT_CODE" pdsh -Rssh -S -wfoo[0-$n] command
  187. done
  188. '
  189. unset PDSH_SSH_ARGS
  190. test_done