PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/t0003-wcoll.sh

https://code.google.com/
Shell | 173 lines | 148 code | 13 blank | 12 comment | 0 complexity | ece0d3c972baedf7d0242c0ce2c5e776 MD5 | raw file
  1#!/bin/sh
  2
  3test_description='pdsh wcoll (working collective) argument processing'
  4
  5. ${srcdir:-.}/test-lib.sh
  6
  7#
  8#  Wrapper to check last line of output from pdsh -Qw
  9#   test_pdsh_wcoll <hostlist> <expected output> [<extra args>]
 10#
 11test_pdsh_wcoll() {
 12	OUTPUT=$(pdsh -Qw $1 $3 | tail -1)
 13	test_output_is_expected "$OUTPUT" "$2"
 14}
 15
 16test_expect_success 'hostname range expansion works' '
 17	test_pdsh_wcoll "foo[0-3]" "foo0,foo1,foo2,foo3"
 18'
 19test_expect_success 'host range expansion does not strip leading zeros' '
 20	test_pdsh_wcoll "foo[00-02]" "foo00,foo01,foo02"
 21'
 22test_expect_success 'host range expansion handles mixed size suffixes' '
 23	test_pdsh_wcoll "foo[9-11]" "foo9,foo10,foo11"
 24'
 25test_expect_success 'host range expansion works with "," embedded in range' '
 26	test_pdsh_wcoll "foo[0-2,4]" "foo0,foo1,foo2,foo4"
 27'
 28test_expect_success 'host range expansion works with 2 sets of brackets' '
 29	test_pdsh_wcoll "foo[1-2]-[0-3]" \
 30		"foo1-0,foo1-1,foo1-2,foo1-3,foo2-0,foo2-1,foo2-2,foo2-3"
 31'
 32test_expect_success 'pdsh -x option works' '
 33	test_pdsh_wcoll "foo[9-11]" "foo9,foo11" "-x foo10"
 34'
 35test_expect_success 'pdsh -x option works with ranges' '
 36	test_pdsh_wcoll "foo[0-5]" "foo0,foo4,foo5" "-x foo[1-3]"
 37'
 38test_expect_success 'pdsh -x option works with ranges (gnats:118)' '
 39	test_pdsh_wcoll "foo[0-5]" "foo0,foo4,foo5" "-x foo[1-3]"
 40'
 41test_expect_success 'pdsh -x option works with non-numeric suffix (gnats:120)' '
 42	test_pdsh_wcoll "fooi,fooj,foo[0-5]" \
 43                        "foo0,foo1,foo3,foo4,foo5" \
 44                        "-x fooj,fooi,foo2"
 45'
 46test_expect_success 'pdsh -w- reads from stdin' '
 47	echo "foo1,foo2,foo3" | test_pdsh_wcoll "-" "foo1,foo2,foo3"
 48'
 49test_expect_success 'pdsh -w- can be used with other -w args' '
 50	echo "foo1,foo2,foo3" | test_pdsh_wcoll "-" "foo1,foo2,foo3,foo4" "-wfoo4" 
 51'
 52cat >wcoll <<EOF
 53foo1
 54foo2
 55foo3
 56EOF
 57test_expect_success 'WCOLL environment variable works' '
 58	test_output_is_expected "$(WCOLL=wcoll pdsh -q | tail -1)" "foo[1-3]"
 59'
 60cat >wcoll <<EOF
 61foo[9-11]
 62foo12
 63EOF
 64test_expect_success 'ranges can be embedded in wcoll files' '
 65	test_output_is_expected "$(WCOLL=wcoll pdsh -Q | tail -1)" \
 66                                "foo9,foo10,foo11,foo12"
 67'
 68test_expect_success '^file works' '
 69	test_pdsh_wcoll "^./wcoll" "foo9,foo10,foo11,foo12"
 70'
 71test_expect_success '-x ^file works' '
 72	test_pdsh_wcoll "foo[8-13]" "foo8,foo13" "-x^wcoll"
 73'
 74test_expect_success '^file works with other args' '
 75	test_pdsh_wcoll "foo[1-2],^./wcoll" "foo1,foo2,foo9,foo10,foo11,foo12"
 76'
 77cat >A <<EOF
 78foo1
 79foo2
 80EOF
 81cat >B <<EOF
 82foo7
 83foo8
 84EOF
 85test_expect_success 'Multiple ^file args' '
 86	test_pdsh_wcoll "^A,^B" "foo1,foo2,foo7,foo8"
 87'
 88test_expect_success 'Multiple -w^file' '
 89	test_pdsh_wcoll "^A" "foo1,foo2,foo7,foo8" "-w^B"
 90'
 91test_expect_success '-^file excludes hosts in file' '
 92	test_pdsh_wcoll "foo[8-12],-^./wcoll" "foo8"
 93'
 94test_expect_success '^file errors out if file doesnt exist' '
 95	! pdsh -w "^nosuchfile" -q 2>/dev/null &&
 96	pdsh -w "^nosuchfile" -q 2>&1 | grep -q "nosuchfile: No such file" 
 97'
 98test_expect_success 'host exclusion with "-" works' '
 99	test_pdsh_wcoll "foo[9-11],-foo10"  "foo9,foo11"
100'
101test_expect_success 'regex filtering works' '
102	test_pdsh_wcoll "foo[0-20],/0$/" "foo0,foo10,foo20"
103'
104test_expect_success 'regex exclusion works' '
105	test_pdsh_wcoll "foo[0-20],-/[1-9]$/" "foo0,foo10,foo20"
106'
107test_expect_success 'regex exclusion works from -x' '
108	test_pdsh_wcoll "foo[0-20]" "foo0,foo10,foo20" "-x/[1-9]$/"
109'
110test_expect_success 'multiple -w options' '
111	test_pdsh_wcoll "foo[0-20]" "foo0,foo10,foo20" "-w-/[1-9]$/" &&
112	test_pdsh_wcoll "foo8" "foo8,foo9,foo10,foo11,foo12" "-w^wcoll" &&
113	test_pdsh_wcoll "foo1,bar1" "foo1" "-w/^foo/"
114'
115
116cat >A <<EOF
117foo1
118#include B
119EOF
120cat >B <<EOF
121foo2
122EOF
123
124test_expect_success 'wcoll files support #include syntax' '
125    test_pdsh_wcoll "^A" "foo1,foo2"
126'
127
128mkdir testdir
129cat >testdir/A <<EOF
130foo1
131foo2
132#include B
133EOF
134cat >testdir/B <<EOF
135foo10
136EOF
137
138test_expect_success 'wcoll #include syntax searches dirname of orignal file' '
139    test_pdsh_wcoll "^testdir/A" "foo1,foo2,foo10"
140'
141
142cat >testdir/A <<EOF
143foo1
144foo2
145#include B garbage
146EOF
147
148cat >testdir/B <<EOF
149#
150#included A
151foo10
152EOF
153cat >testdir/C <<EOF
154#
155#include
156foo11
157EOF
158
159test_expect_success 'wcoll #include syntax ignores malformed lines' '
160    test_pdsh_wcoll "^testdir/A" "foo1,foo2" &&
161	pdsh -w^testdir/A -q 2>&1 | grep -q warning
162'
163test_expect_success 'wcoll match #include exactly' '
164    test_pdsh_wcoll "^testdir/B" "foo10" &&
165	pdsh -w^testdir/B -q 2>&1 | grep -q warning
166'
167
168test_expect_success 'wcoll: #include alone fails' '
169    test_pdsh_wcoll "^testdir/C" "foo11" &&
170	pdsh -w^testdir/C -q 2>&1 | grep -q warning
171'
172
173test_done