PageRenderTime 30ms CodeModel.GetById 13ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/tests/t0006-pdcp.sh

https://code.google.com/
Shell | 149 lines | 125 code | 15 blank | 9 comment | 2 complexity | 8599b48acadc121dca46b68732beebfc MD5 | raw file
  1#!/bin/sh
  2
  3test_description='pdcp specific tests'
  4
  5if ! test -x ../src/pdsh/pdsh; then
  6   echo >&2 'Failed to find pdsh binary. Please run make.'
  7   exit 1
  8fi
  9
 10. ${srcdir:-.}/test-lib.sh
 11
 12###########################################################################
 13#
 14#  First set up pdcp link to pdsh
 15#
 16
 17test_expect_success 'Creating pdcp link to pdsh binary' '
 18    ln -s $PDSH_BUILD_DIR/src/pdsh/pdsh pdcp
 19'
 20test_expect_success 'Creating rpdcp link to pdsh binary' '
 21    ln -s $PDSH_BUILD_DIR/src/pdsh/pdsh rpdcp
 22'
 23
 24export PATH=.:$PATH
 25
 26###########################################################################
 27#
 28#  Basic pdcp tests
 29#
 30test_expect_success 'pdcp runs' '
 31	pdcp -w foo -q * /tmp | tail -1 | grep foo
 32'
 33test_expect_success 'rpdcp runs' '
 34	rpdcp -w foo -q * /tmp | tail -1 | grep foo
 35'
 36test_expect_success 'pdcp -V works' '
 37    pdcp -V 2>&1 | grep -q ^pdsh
 38'
 39test_expect_success 'pdcp -q works' '
 40	pdcp -q -w foo * /tmp 2>&1 | grep -q Infile
 41'
 42check_pdcp_option() {
 43	flag=$1; name=$2; value=$3;
 44	flagval=$value
 45	if test "$value" = "Yes" -o "$value" = "No"; then
 46		flagval=""
 47	fi
 48	echo "flag=$flag name='$name' value=$value flagval=$flagval"
 49	pdcp -$flag$flagval -w foo -q * /tmp | grep -q "$name[ 	]*$value$"
 50}
 51
 52test_expect_success '-e sets remote program path' '
 53	check_pdcp_option e "Remote program path" /remote/pdcp
 54'
 55test_expect_success 'PDSH_REMOTE_PDCP_PATH sets remote program path' '
 56    tag="Remote program path"
 57	path="/xxx/pdcp"
 58	PDSH_REMOTE_PDCP_PATH=$path pdcp -w foo -q * /tmp | grep -q "$tag[ 	]*$path$"
 59'
 60test_expect_success '-f sets fanout' '
 61	check_pdcp_option f Fanout 8
 62'
 63test_expect_success '-l sets remote username' '
 64	check_pdcp_option l "Remote username" foouser
 65'
 66test_expect_success '-t sets connect timeout' '
 67	check_pdcp_option t "Connect timeout (secs)" 33
 68'
 69test_expect_success '-u sets command timeout' '
 70	check_pdcp_option u "Command timeout (secs)" 22
 71'
 72test_expect_success 'command timeout 0 by default' '
 73    pdcp -w foo -q * /tmp | grep -q "Command timeout (secs)[ 	]*0$"
 74'
 75
 76export T="$TEST_DIRECTORY/test-modules"
 77
 78test_expect_success DYNAMIC_MODULES,NOTROOT 'Have pcptest rcmd module' '
 79	PDSH_MODULE_DIR=$T pdcp -L | grep -q pcptest
 80'
 81
 82setup_host_dirs() {
 83	pdsh -w "$1" -Rexec mkdir %h
 84}
 85
 86create_random_file() {
 87	name=${1-testfile}
 88	size=${2-1}
 89	dd if=/dev/urandom of=$name bs=1024 count=$size >/dev/null 2>&1
 90}
 91
 92test_expect_success DYNAMIC_MODULES,NOTROOT 'pdcp basic functionality' '
 93    HOSTS="host[0-10]"
 94	setup_host_dirs "$HOSTS" &&
 95	test_when_finished "rm -rf host* testfile" &&
 96	create_random_file testfile 10 &&
 97	PDSH_MODULE_DIR=$T pdcp -Rpcptest -w "$HOSTS" testfile testfile &&
 98	pdsh -SRexec -w "$HOSTS" $GIT_TEST_CMP testfile %h/testfile
 99'
100rm -rf host* testfile
101
102test_expect_success DYNAMIC_MODULES,NOTROOT 'rpdcp basic functionality' '
103	HOSTS="host[0-10]"
104	setup_host_dirs "$HOSTS"
105	test_when_finished "rm -rf host* t output" &&
106	pdsh -Rexec -w "$HOSTS" dd if=/dev/urandom of=%h/t bs=1024 count=10 >/dev/null 2>&1 &&
107	mkdir output &&
108	PDSH_MODULE_DIR=$T rpdcp -Rpcptest -w "$HOSTS" t output/ &&
109	pdsh -SRexec -w "$HOSTS" $GIT_TEST_CMP output/t.%h %h/t
110'
111test_expect_success DYNAMIC_MODULES,NOTROOT 'initialize directory tree' '
112	mkdir tree &&
113	(
114	   cd tree &&
115	   echo foo >foo &&
116	   ln -s foo foo.link &&
117	   mkdir -p dir/a/b/c/d/e &&
118	   create_random_file dir/data 1024 &&
119	   echo "deep dir" > dir/a/b/c/d/e/file &&
120	   mkdir bar &&
121	   echo "zzz" >bar/zzz &&
122	   mkdir baz &&
123	   echo "#!$SHELL_PATH" > baz/exec.sh &&
124	   chmod +x baz/exec.sh &&
125	   echo "write protected file" > dir/a/b/c/xw &&
126	   chmod -w dir/a/b/c/xw
127	)
128'
129test_expect_success DYNAMIC_MODULES,NOTROOT 'pdcp -r works' '
130	HOSTS="host[0-10]"
131	setup_host_dirs "$HOSTS" &&
132	test_when_finished "rm -rf host*" &&
133	PDSH_MODULE_DIR=$T pdcp -Rpcptest -w "$HOSTS" -r tree . &&
134	pdsh -SRexec -w "$HOSTS" diff -r tree %h/tree >/dev/null &&
135	pdsh -SRexec -w "$HOSTS" test -x tree/baz/exec.sh &&
136	pdsh -SRexec -w "$HOSTS" test -h tree/foo.link &&
137	pdsh -SRexec -w "$HOSTS" test ! -w dir/a/b/c/xw
138'
139test_expect_success DYNAMIC_MODULES,NOTROOT 'rpdcp -r works' '
140	HOSTS="host[0-10]"
141	setup_host_dirs "$HOSTS" &&
142	test_when_finished "rm -rf host* output" &&
143	pdsh -SRexec -w "$HOSTS" cp -r tree %h/ &&
144	mkdir output &&
145	PDSH_MODULE_DIR=$T rpdcp -Rpcptest -w "$HOSTS" -r tree output/ &&
146	pdsh -SRexec -w "$HOSTS" diff -r tree output/tree.%h >/dev/null
147'
148
149test_done