2 # Ensure that virsh option parsing doesn't regress
4 # Copyright (C) 2011-2012, 2014 Red Hat, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see
18 # <http://www.gnu.org/licenses/>.
20 .
"$(dirname $0)/test-lib.sh"
24 # If $abs_top_builddir/tools is not early in $PATH, put it there,
25 # so that we can safely invoke "virsh" simply with its name.
27 $abs_top_builddir/tools
/src
:$abs_top_builddir/tools
:*) ;;
28 $abs_top_builddir/tools
:*) ;;
29 *) PATH
=$abs_top_builddir/tools
:$PATH; export PATH
;;
32 if test "$VERBOSE" = yes; then
37 cat <<\EOF
> exp-out || framework_failure
39 setvcpus
: <domain
> trying as domain NAME
40 setvcpus
: count
(optdata
): 2
41 setvcpus
: domain
(optdata
): test
42 setvcpus
: found option
<domain
>: test
47 test_url
=test:///default
55 '--domain test --count 2' \
56 '--domain=test --count 2' \
57 '--domain test --count=2' \
58 '--domain=test --count=2' \
59 '--count 2 --domain test' \
60 '--count 2 --domain=test' \
61 '--count=2 --domain test' \
62 '--count=2 --domain=test' \
66 virsh
-k0 -d0 -c $test_url setvcpus
$args >out
2>>err || fail
=1
67 LC_ALL
=C
sort out | compare exp-out
- || fail
=1
70 # Another complex parsing example
71 cat <<\EOF
> exp-out || framework_failure
73 <description
>1<
;2</description
>
76 <disk name
='vda' snapshot
='external'>
77 <source file='a&b,c'/>
84 virsh
-q -c $test_url snapshot-create-as
--print-xml test \
85 --diskspec 'vda,file=a&b,,c,snapshot=external' --description '1<2' \
86 --diskspec vdb
--memspec file=d
,,e
>out
2>>err || fail
=1
87 compare exp-out out || fail
=1
89 cat <<\EOF
> exp-out || framework_failure
92 <description
>vda
</description
>
99 virsh
-q -c $test_url snapshot-create-as
--print-xml test name vda vdb \
100 >out
2>>err || fail
=1
101 compare exp-out out || fail
=1
103 cat <<\EOF
> exp-out || framework_failure
106 <description
>desc
</description
>
115 'test name desc vda vdb' \
116 'test name desc --diskspec vda vdb' \
117 'test name desc --diskspec vda --diskspec vdb' \
118 'test name desc vda vdb' \
119 'test --diskspec vda name --diskspec vdb desc' \
120 '--description desc --name name --domain test vda vdb' \
121 '--description desc --diskspec vda --name name --domain test vdb' \
123 virsh
-q -c $test_url snapshot-create-as
--print-xml $args \
124 >out
2>>err || fail
=1
125 compare exp-out out || fail
=1
128 test -s err
&& fail
=1
130 # Test a required argv
131 cat <<\EOF
> exp-err || framework_failure
132 error
: this
function is not supported by the connection driver
: virDomainQemuMonitorCommand
134 virsh
-q -c $test_url qemu-monitor-command
test a
>out
2>err
&& fail
=1
135 test -s out
&& fail
=1
136 compare exp-err err || fail
=1
138 ### Test a regular numeric option
141 cat <<\EOF
> exp-err || framework_failure
142 error
: Numeric value
'abc' for <start
> option is malformed or out of range
144 virsh
-q -c $test_url cpu-stats
test --start abc
>out
2>err
&& fail
=1
145 test -s out
&& fail
=1
146 compare exp-err err || fail
=1
148 # Numeric value with invalid suffix
149 cat <<\EOF
> exp-err || framework_failure
150 error
: Numeric value
'42WB' for <start
> option is malformed or out of range
152 virsh
-q -c $test_url cpu-stats
test --start 42WB
>out
2>err
&& fail
=1
153 test -s out
&& fail
=1
154 compare exp-err err || fail
=1
156 # Numeric value with valid suffix. Suffixes are not supported for
157 # regular numeric options, so this value is rejected
158 cat <<\EOF
> exp-err || framework_failure
159 error
: Numeric value
'42MB' for <start
> option is malformed or out of range
161 virsh
-q -c $test_url cpu-stats
test --start 42MB
>out
2>err
&& fail
=1
162 test -s out
&& fail
=1
163 compare exp-err err || fail
=1
165 # Numeric value bigger than INT_MAX
166 cat <<\EOF
> exp-err || framework_failure
167 error
: Numeric value
'2147483648' for <start
> option is malformed or out of range
169 virsh
-q -c $test_url cpu-stats
test --start 2147483648 >out
2>err
&& fail
=1
170 test -s out
&& fail
=1
171 compare exp-err err || fail
=1
173 # Negative numeric value. The value is not valid for the command
174 # we're testing, but it has been parsed correctly
175 cat <<\EOF
> exp-err || framework_failure
176 error
: Invalid value
for start CPU
178 virsh
-q -c $test_url cpu-stats
test --start -1 >out
2>err
&& fail
=1
179 test -s out
&& fail
=1
180 compare exp-err err || fail
=1
182 ### Test a scaled numeric option
185 cat <<\EOF
> exp-err || framework_failure
186 error
: Scaled numeric value
'abc' for <size
> option is malformed or out of range
188 virsh
-q -c $test_url setmaxmem
test abc
>out
2>err
&& fail
=1
189 test -s out
&& fail
=1
190 compare exp-err err || fail
=1
192 # Numeric value with invalid suffix
193 cat <<\EOF
> exp-err || framework_failure
194 error
: Scaled numeric value
'42WB' for <size
> option is malformed or out of range
195 error
: invalid argument
: unknown suffix
'WB'
197 virsh
-q -c $test_url setmaxmem
test 42WB
>out
2>err
&& fail
=1
198 test -s out
&& fail
=1
199 compare exp-err err || fail
=1
201 # Numeric value with valid suffix
202 virsh
-q -c $test_url setmaxmem
test 42MB
--config >out
2>err || fail
=1
203 test -s out
&& fail
=1
204 test -s err
&& fail
=1
206 # Numeric value bigger than INT_MAX. No failure here because
207 # scaled numeric values are unsigned long long
208 virsh
-q -c $test_url setmaxmem
test 2147483648 --config >out
2>err || fail
=1
209 test -s out
&& fail
=1
210 test -s err
&& fail
=1
212 # Negative numeric value
213 cat <<\EOF
> exp-err || framework_failure
214 error
: Scaled numeric value
'-1' for <size
> option is malformed or out of range
216 virsh
-q -c $test_url setmaxmem
test -1 >out
2>err
&& fail
=1
217 test -s out
&& fail
=1
218 compare exp-err err || fail
=1
220 # Zero. The value is not valid for the command we're testing, but
221 # it has been parsed correctly
222 cat <<\EOF
> exp-err || framework_failure
223 error
: Unable to change MaxMemorySize
224 error
: memory
in virDomainSetMaxMemory must not be zero
226 virsh
-q -c $test_url setmaxmem
test 0 >out
2>err
&& fail
=1
227 test -s out
&& fail
=1
228 compare exp-err err || fail
=1
231 virsh
-q -c $test_url setmaxmem
test 42 --config >out
2>err || fail
=1
232 test -s out
&& fail
=1
233 test -s err
&& fail
=1
235 ### Test the <timeout> option (numeric option converted to ms)
238 cat <<\EOF
> exp-err || framework_failure
239 error
: Numeric value
'abc' for <timeout
> option is malformed or out of range
241 virsh
-q -c $test_url event
--all --timeout abc
>out
2>err
&& fail
=1
242 test -s out
&& fail
=1
243 compare exp-err err || fail
=1
245 # Numeric value that's too big to be converted to ms and still
247 cat <<\EOF
> exp-err || framework_failure
248 error
: Numeric value
'2147484' for <timeout
> option is malformed or out of range
250 virsh
-q -c $test_url event
--all --timeout 2147484 >out
2>err
&& fail
=1
251 test -s out
&& fail
=1
252 compare exp-err err || fail
=1
254 # Numeric value with invalid suffix
255 cat <<\EOF
> exp-err || framework_failure
256 error
: Numeric value
'42WB' for <timeout
> option is malformed or out of range
258 virsh
-q -c $test_url event
--all --timeout 42WB
>out
2>err
&& fail
=1
259 test -s out
&& fail
=1
260 compare exp-err err || fail
=1
262 # Numeric value with valid suffix. Suffixes are not supported for
263 # the <timeout> option, so this value is rejected
264 cat <<\EOF
> exp-err || framework_failure
265 error
: Numeric value
'42MB' for <timeout
> option is malformed or out of range
267 virsh
-q -c $test_url event
--all --timeout 42MB
>out
2>err
&& fail
=1
268 test -s out
&& fail
=1
269 compare exp-err err || fail
=1
272 cat <<\EOF
> exp-err || framework_failure
273 error
: Numeric value
'-1' for <timeout
> option is malformed or out of range
275 virsh
-q -c $test_url event
--all --timeout -1 >out
2>err
&& fail
=1
276 test -s out
&& fail
=1
277 compare exp-err err || fail
=1
279 # Zero. This is not a valid timeout, but the value is parsed
281 cat <<\EOF
> exp-err || framework_failure
282 error
: Numeric value
'0' for <timeout
> option is malformed or out of range
284 virsh
-q -c $test_url event
--all --timeout 0 >out
2>err
&& fail
=1
285 test -s out
&& fail
=1
286 compare exp-err err || fail
=1
288 # Numeric value. No events will be received and the command will
289 # fail after a second, but the value has been parsed correctly
290 cat <<\EOF
> exp-out || framework_failure
294 virsh
-q -c $test_url event
--all --timeout 1 >out
2>err
&& fail
=1
295 test -s err
&& fail
=1
296 compare exp-out out || fail
=1
298 (exit $fail); exit $fail