3 # Copyright (C) 2019-2020 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 # This test works with newer libnbd, showing that dynamic mode affects
41 requires nbdinfo
--version
43 # Does the nbd plugin support dynamic lists?
44 if ! nbdkit
--dump-plugin nbd |
grep -sq libnbd_dynamic_list
=1; then
45 echo "$0: nbd plugin built without dynamic export list support"
49 base
=test-nbd-dynamic-list
50 sock1
=$
(mktemp
-u /tmp
/nbdkit-test-sock.XXXXXX
)
51 sock2
=$
(mktemp
-u /tmp
/nbdkit-test-sock.XXXXXX
)
54 files
="$sock1 $sock2 $pid1 $pid2 $base.list $base.out1 $base.out2 $base.err"
56 cleanup_fn
rm -f $files
60 # Start a long-running server with .list_exports and .default_export
61 # set to varying contents
62 start_nbdkit
-P $pid1 -U $sock1 eval get_size
='echo "$2"|wc -c' \
63 open
='echo "$3"' list_exports
="cat '$PWD/$base.list'" \
64 default_export
="cat '$PWD/$base.list'"
66 # Long-running nbd bridge, which should pass export list through
67 start_nbdkit
-P $pid2 -U $sock2 nbd socket
=$sock1 dynamic-export
=true
69 # check_success_one EXPORT
70 # - nbdinfo of EXPORT on both servers should succeed, with matching output
73 nbdinfo
--no-content "nbd+unix:///$1?socket=$sock1" |
74 grep -v uri
: > $base.out1
75 nbdinfo
--no-content "nbd+unix:///$1?socket=$sock2" |
76 grep -v uri
: > $base.out2
78 diff -u $base.out1
$base.out2
82 # - nbdinfo --list on both servers should succeed, with matching output
85 nbdinfo
--list --json nbd
+unix
://\?socket
=$sock1 |
86 grep -v '"uri"' > $base.out1
87 nbdinfo
--list --json nbd
+unix
://\?socket
=$sock2 |
88 grep -v '"uri"' > $base.out2
90 diff -u $base.out1
$base.out2
93 # check_success EXPORT... - both sub-tests, on all EXPORTs
97 check_success_one
"$exp"
102 # check_fail_one EXPORT
103 # - nbdinfo of EXPORT on both servers should fail
106 # Work around nbdinfo 1.6.2 bug that had error message but 0 status
107 if nbdinfo
--no-content "nbd+unix:///$1?socket=$sock1" > $base.out1 \
108 2> $base.err
&& ! grep "server replied with error" $base.err
; then
111 if nbdinfo
--no-content "nbd+unix:///$1?socket=$sock2" > $base.out2 \
112 2> $base.err
&& ! grep "server replied with error" $base.err
; then
118 # - nbdinfo --list on both servers should fail
121 if nbdinfo
--list --json nbd
+unix
://\?socket
=$sock1 > $base.out1
; then
124 if nbdinfo
--list --json nbd
+unix
://\?socket
=$sock2 > $base.out2
; then
129 # With no file, list_exports and the default export fail,
130 # but other exports work
132 check_success_one name
135 # With an empty list, there are 0 exports, and any export works
137 check_success
"" name
139 # An explicit advertisement of the default export, any export works
141 check_success
"" name
143 # A non-empty default name
144 echo name
> $base.list
145 check_success
"" name
147 # Multiple exports, with descriptions
148 cat > $base.list
<<EOF
155 echo name
> $base.list
156 check_success
"" name1
158 # Longest possible name and description
159 long
=$
(printf %04096d
1)
160 echo NAMES
+DESCRIPTIONS
> $base.list
161 echo $long >> $base.list
162 echo $long >> $base.list
163 check_success
"" $long
165 # An invalid name prevents list, but we can still connect
166 echo 2$long >> $base.list