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