Add missing libxml2-tools dependency
[archive/platform/upstream/libvirt.git] / tests / virsh-optparse
1 #!/bin/sh
2 # Ensure that virsh option parsing doesn't regress
3
4 # Copyright (C) 2011-2012, 2014 Red Hat, Inc.
5
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.
10
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.
15
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/>.
19
20 : ${srcdir=$(pwd)}
21 : ${abs_top_srcdir=$(pwd)/..}
22 : ${abs_top_builddir=$(pwd)/..}
23
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.
26 case $PATH in
27   $abs_top_builddir/tools/src:$abs_top_builddir/tools:*) ;;
28   $abs_top_builddir/tools:*) ;;
29   *) PATH=$abs_top_builddir/tools:$PATH; export PATH ;;
30 esac
31
32 if test "$VERBOSE" = yes; then
33   set -x
34   virsh --version
35 fi
36
37 . "$srcdir/test-lib.sh"
38
39 cat <<\EOF > exp-out || framework_failure
40
41 setvcpus: <domain> trying as domain NAME
42 setvcpus: count(optdata): 2
43 setvcpus: domain(optdata): test
44 setvcpus: found option <domain>: test
45 EOF
46
47 fail=0
48
49 test_url=test:///default
50
51 for args in \
52     'test 2' \
53     '--domain test 2' \
54     '--domain=test 2' \
55     'test --count 2' \
56     'test --count=2' \
57     '--domain test --count 2' \
58     '--domain=test --count 2' \
59     '--domain test --count=2' \
60     '--domain=test --count=2' \
61     '--count 2 --domain test' \
62     '--count 2 --domain=test' \
63     '--count=2 --domain test' \
64     '--count=2 --domain=test' \
65     '--count 2 test' \
66     '--count=2 test' \
67 ; do
68   virsh -k0 -d0 -c $test_url setvcpus $args >out 2>>err || fail=1
69   LC_ALL=C sort out | compare exp-out - || fail=1
70 done
71
72 # Another complex parsing example
73 cat <<\EOF > exp-out || framework_failure
74 <domainsnapshot>
75   <description>1&lt;2</description>
76   <memory file='d,e'/>
77   <disks>
78     <disk name='vda' snapshot='external'>
79       <source file='a&amp;b,c'/>
80     </disk>
81     <disk name='vdb'/>
82   </disks>
83 </domainsnapshot>
84
85 EOF
86 virsh -q -c $test_url snapshot-create-as --print-xml test \
87   --diskspec 'vda,file=a&b,,c,snapshot=external' --description '1<2' \
88   --diskspec vdb --memspec file=d,,e >out 2>>err || fail=1
89 compare exp-out out || fail=1
90
91 cat <<\EOF > exp-out || framework_failure
92 <domainsnapshot>
93   <name>name</name>
94   <description>vda</description>
95   <disks>
96     <disk name='vdb'/>
97   </disks>
98 </domainsnapshot>
99
100 EOF
101 virsh -q -c $test_url snapshot-create-as  --print-xml test name vda vdb \
102   >out 2>>err || fail=1
103 compare exp-out out || fail=1
104
105 cat <<\EOF > exp-out || framework_failure
106 <domainsnapshot>
107   <name>name</name>
108   <description>desc</description>
109   <disks>
110     <disk name='vda'/>
111     <disk name='vdb'/>
112   </disks>
113 </domainsnapshot>
114
115 EOF
116 for args in \
117     'test name desc vda vdb' \
118     'test name desc --diskspec vda vdb' \
119     'test name desc --diskspec vda --diskspec vdb' \
120     'test name desc vda vdb' \
121     'test --diskspec vda name --diskspec vdb desc' \
122     '--description desc --name name --domain test vda vdb' \
123     '--description desc --diskspec vda --name name --domain test vdb' \
124 ; do
125   virsh -q -c $test_url snapshot-create-as --print-xml $args \
126     >out 2>>err || fail=1
127   compare exp-out out || fail=1
128 done
129
130 test -s err && fail=1
131
132 # Test a required argv
133 cat <<\EOF > exp-err || framework_failure
134 error: this function is not supported by the connection driver: virDomainQemuMonitorCommand
135 EOF
136 virsh -q -c $test_url qemu-monitor-command test a >out 2>err && fail=1
137 test -s out && fail=1
138 compare exp-err err || fail=1
139
140 (exit $fail); exit $fail