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
38 requires nbdinfo
--version
40 requires nbdsh
-c 'print(h.set_full_info)'
43 files
="exportname.out exportname.sh"
45 cleanup_fn
rm -f $files
47 query
='[ [.exports[]] | sort_by(."export-name")[] |
48 [."export-name", .description, ."export-size"] ]'
51 cat >exportname.sh
<<\EOF
59 default_export
) echo a
;;
61 export_description | get_size
)
71 chmod +x exportname.sh
73 # Establish a baseline
74 nbdkit
-U - sh exportname.sh \
75 --run 'nbdinfo --json --list "$uri"' > exportname.out
77 test "$(jq -c "$query" exportname.out)" = \
78 '[["a","x",1],["b","y",2],["c","z",3]]'
80 # Set the default export
81 nbdkit
-U - --filter=exportname sh exportname.sh default-export
= \
82 --run 'nbdinfo --no-content --json "$uri"' > exportname.out
84 test "$(jq -c "$query" exportname.out)" = '[["","1",1]]'
86 nbdkit
-U - --filter=exportname sh exportname.sh default-export
=b \
87 --run 'nbdinfo --no-content --json "$uri"' > exportname.out
89 test "$(jq -c "$query" exportname.out)" = '[["b","2",2]]'
91 # Test export list policies
92 nbdkit
-U - --filter=exportname sh exportname.sh exportname-list
=keep \
93 --run 'nbdinfo --json --list "$uri"' > exportname.out
95 test "$(jq -c "$query" exportname.out)" = \
96 '[["a","x",1],["b","y",2],["c","z",3]]'
98 nbdkit
-U - --filter=exportname sh exportname.sh exportname-list
=error \
99 --run 'nbdinfo --json --list "$uri"' > exportname.out
&& fail
=1 ||
:
100 test ! -s exportname.out
102 nbdkit
-U - --filter=exportname sh exportname.sh exportname-list
=empty \
103 --run 'nbdinfo --json --list "$uri"' > exportname.out
105 test "$(jq -c "$query" exportname.out)" = '[]'
107 nbdkit
-U - --filter=exportname sh exportname.sh exportname-list
=defaultonly \
108 --run 'nbdinfo --json --list "$uri"' > exportname.out
110 got
="$(jq -c "$query" exportname.out)"
111 # libnbd 1.4.0 and 1.4.1 differ on whether --list grabs description
112 test "$got" = '[["a",null,1]]' ||
test "$got" = '[["a","1",1]]' || fail
=1
114 nbdkit
-U - --filter=exportname sh exportname.sh default-export
=b \
115 exportname-list
=defaultonly exportname
=a exportname
=b \
116 --run 'nbdinfo --json --list "$uri"' > exportname.out
118 got
="$(jq -c "$query" exportname.out)"
119 test "$got" = '[["b",null,2]]' ||
test "$got" = '[["b","2",2]]' || fail
=1
121 nbdkit
-U - --filter=exportname sh exportname.sh \
122 exportname-list
=explicit exportname
=b exportname
=a \
123 --run 'nbdinfo --json --list "$uri"' > exportname.out
125 got
="$(jq -c "$query" exportname.out)"
126 test "$got" = '[["a",null,1],["b",null,2]]' ||
127 test "$got" = '[["a","1",1],["b","2",2]]' || fail
=1
129 nbdkit
-U - --filter=exportname sh exportname.sh exportname-list
=explicit \
130 --run 'nbdinfo --json --list "$uri"' > exportname.out
132 test "$(jq -c "$query" exportname.out)" = '[]'
134 # Test description modes with lists
135 nbdkit
-U - --filter=exportname sh exportname.sh exportdesc
=keep \
136 --run 'nbdinfo --json --list "$uri"' > exportname.out
138 test "$(jq -c "$query" exportname.out)" = \
139 '[["a","x",1],["b","y",2],["c","z",3]]'
141 nbdkit
-U - --filter=exportname sh exportname.sh exportdesc
=none \
142 --run 'nbdinfo --json --list "$uri"' > exportname.out
144 test "$(jq -c "$query" exportname.out)" = \
145 '[["a",null,1],["b",null,2],["c",null,3]]'
147 nbdkit
-U - --filter=exportname sh exportname.sh exportdesc
=fixed
:hi \
148 --run 'nbdinfo --json --list "$uri"' > exportname.out
150 test "$(jq -c "$query" exportname.out)" = \
151 '[["a","hi",1],["b","hi",2],["c","hi",3]]'
153 nbdkit
-U - --filter=exportname sh exportname.sh \
154 exportdesc
=script:'echo $name$name' \
155 --run 'nbdinfo --json --list "$uri"' > exportname.out
157 test "$(jq -c "$query" exportname.out)" = \
158 '[["a","aa",1],["b","bb",2],["c","cc",3]]'
160 # Test description modes with connections
161 nbdkit
-U - -e c
--filter=exportname sh exportname.sh exportdesc
=fixed
:hi \
162 --run 'nbdinfo --no-content --json "$uri"' > exportname.out
164 test "$(jq -c "$query" exportname.out)" = '[["c","hi",3]]'
166 nbdkit
-U - -e c
--filter=exportname sh exportname.sh \
167 exportdesc
=script:'echo $name$name' \
168 --run 'nbdinfo --no-content --json "$uri"' > exportname.out
170 test "$(jq -c "$query" exportname.out)" = '[["c","cc",3]]'
172 # Test strict mode. Tolerate nbdinfo 1.6.2 which gave invalid JSON but 0 status
174 nbdkit
-U - --filter=exportname sh exportname.sh exportname-strict
=true \
175 --run 'nbdinfo --no-content --json "$uri"' > exportname.out || st
=$?
178 test -s exportname.out
&& jq
-c "$query" exportname.out
&& fail
=1
182 nbdkit
-U - --filter=exportname sh exportname.sh exportname-strict
=true \
183 exportname
=a exportname
=b exportname
=c \
184 --run 'nbdinfo --no-content --json "$uri"' > exportname.out || st
=$?
187 test -s exportname.out
&& jq
-c "$query" exportname.out
&& fail
=1
190 nbdkit
-U - --filter=exportname sh exportname.sh exportname-strict
=true \
191 exportname
=a exportname
=b exportname
= default-export
=a\
192 --run 'nbdinfo --no-content --json "$uri"' > exportname.out
194 test "$(jq -c "$query" exportname.out)" = '[["a","1",1]]'
196 nbdkit
-U - -e a
--filter=exportname sh exportname.sh exportname-strict
=true \
197 exportname
=a exportname
=b exportname
=c \
198 --run 'nbdinfo --no-content --json "$uri"' > exportname.out
200 test "$(jq -c "$query" exportname.out)" = '[["a","1",1]]'