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