PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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