ruby-libvirt 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +43 -0
- data/README +40 -2
- data/README.rdoc +3 -1
- data/Rakefile +3 -25
- data/ext/libvirt/_libvirt.c +636 -35
- data/ext/libvirt/common.c +142 -16
- data/ext/libvirt/common.h +78 -22
- data/ext/libvirt/connect.c +1811 -95
- data/ext/libvirt/connect.h +0 -1
- data/ext/libvirt/domain.c +880 -424
- data/ext/libvirt/domain.h +4 -0
- data/ext/libvirt/extconf.rb +90 -0
- data/ext/libvirt/interface.c +40 -118
- data/ext/libvirt/network.c +22 -125
- data/ext/libvirt/network.h +1 -0
- data/ext/libvirt/nodedevice.c +27 -142
- data/ext/libvirt/nwfilter.c +10 -83
- data/ext/libvirt/secret.c +35 -113
- data/ext/libvirt/storage.c +125 -223
- data/tests/test_conn.rb +193 -43
- data/tests/test_domain.rb +1067 -102
- data/tests/test_interface.rb +156 -19
- data/tests/test_network.rb +237 -26
- data/tests/test_nodedevice.rb +103 -15
- data/tests/test_nwfilter.rb +97 -14
- data/tests/test_open.rb +186 -6
- data/tests/test_secret.rb +126 -14
- data/tests/test_storage.rb +513 -40
- data/tests/test_utils.rb +73 -0
- metadata +5 -6
- data/tests/node.xml +0 -110
- data/tests/tc_connect.rb +0 -178
data/tests/test_secret.rb
CHANGED
@@ -2,32 +2,144 @@
|
|
2
2
|
|
3
3
|
# Test the secret methods the bindings support
|
4
4
|
|
5
|
+
$: << File.dirname(__FILE__)
|
6
|
+
|
5
7
|
require 'libvirt'
|
8
|
+
require 'test_utils.rb'
|
9
|
+
|
10
|
+
UUID = "bd339530-134c-6d07-4410-17fb90dad805"
|
6
11
|
|
7
|
-
conn = Libvirt::open
|
8
|
-
puts "Number of Secrets: #{conn.num_of_secrets}"
|
12
|
+
conn = Libvirt::open("qemu:///system")
|
9
13
|
|
10
14
|
new_secret_xml = <<EOF
|
11
15
|
<secret ephemeral='no' private='no'>
|
12
16
|
<description>test secret</description>
|
17
|
+
<uuid>#{UUID}</uuid>
|
18
|
+
<usage type='volume'>
|
19
|
+
<volume>/var/lib/libvirt/images/mail.img</volume>
|
20
|
+
</usage>
|
13
21
|
</secret>
|
14
22
|
EOF
|
15
23
|
|
24
|
+
# TESTGROUP: conn.num_of_secrets
|
25
|
+
expect_too_many_args(conn, "num_of_secrets", 1)
|
26
|
+
expect_success(conn, "no args", "num_of_secrets")
|
27
|
+
|
28
|
+
# TESTGROUP: conn.list_secrets
|
29
|
+
expect_too_many_args(conn, "list_secrets", 1)
|
30
|
+
expect_success(conn, "no args", "list_secrets")
|
31
|
+
|
32
|
+
# TESTGROUP: conn.lookup_secret_by_uuid
|
33
|
+
newsecret = conn.define_secret_xml(new_secret_xml)
|
34
|
+
|
35
|
+
expect_too_many_args(conn, "lookup_secret_by_uuid", 1, 2)
|
36
|
+
expect_too_few_args(conn, "lookup_secret_by_uuid")
|
37
|
+
expect_invalid_arg_type(conn, "lookup_secret_by_uuid", 1)
|
38
|
+
|
39
|
+
expect_success(conn, "uuid arg", "lookup_secret_by_uuid", UUID) {|x| x.uuid == UUID}
|
40
|
+
|
41
|
+
newsecret.undefine
|
42
|
+
|
43
|
+
# TESTGROUP: conn.lookup_secret_by_usage
|
16
44
|
newsecret = conn.define_secret_xml(new_secret_xml)
|
17
|
-
newsecret.set_value("hello")
|
18
|
-
puts newsecret.get_value
|
19
|
-
newsecret.set_value("bob", 0)
|
20
|
-
puts newsecret.get_value
|
21
45
|
|
22
|
-
conn
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
46
|
+
expect_too_many_args(conn, "lookup_secret_by_usage", 1, 2, 3)
|
47
|
+
expect_too_few_args(conn, "lookup_secret_by_usage")
|
48
|
+
expect_invalid_arg_type(conn, "lookup_secret_by_usage", 'foo', 1)
|
49
|
+
expect_invalid_arg_type(conn, "lookup_secret_by_usage", 1, 2)
|
50
|
+
expect_fail(conn, Libvirt::RetrieveError, "invalid secret", "lookup_secret_by_usage", Libvirt::Secret::USAGE_TYPE_VOLUME, "foo")
|
51
|
+
|
52
|
+
expect_success(conn, "usage type and key", "lookup_secret_by_usage", Libvirt::Secret::USAGE_TYPE_VOLUME, "/var/lib/libvirt/images/mail.img")
|
53
|
+
|
54
|
+
newsecret.undefine
|
55
|
+
|
56
|
+
# TESTGROUP: conn.define_secret_xml
|
57
|
+
expect_too_many_args(conn, "define_secret_xml", 1, 2, 3)
|
58
|
+
expect_too_few_args(conn, "define_secret_xml")
|
59
|
+
expect_invalid_arg_type(conn, "define_secret_xml", 1)
|
60
|
+
expect_invalid_arg_type(conn, "define_secret_xml", nil)
|
61
|
+
expect_invalid_arg_type(conn, "define_secret_xml", "hello", 'foo')
|
62
|
+
expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_secret_xml", "hello")
|
63
|
+
|
64
|
+
expect_success(conn, "secret XML", "define_secret_xml", new_secret_xml)
|
30
65
|
|
31
66
|
newsecret.undefine
|
32
67
|
|
68
|
+
# TESTGROUP: secret.uuid
|
69
|
+
newsecret = conn.define_secret_xml(new_secret_xml)
|
70
|
+
|
71
|
+
expect_too_many_args(newsecret, "uuid", 1)
|
72
|
+
|
73
|
+
expect_success(newsecret, "no args", "uuid") {|x| x == UUID}
|
74
|
+
|
75
|
+
newsecret.undefine
|
76
|
+
|
77
|
+
# TESTGROUP: secret.usagetype
|
78
|
+
newsecret = conn.define_secret_xml(new_secret_xml)
|
79
|
+
|
80
|
+
expect_too_many_args(newsecret, "usagetype", 1)
|
81
|
+
|
82
|
+
expect_success(newsecret, "no args", "usagetype") {|x| x == Libvirt::Secret::USAGE_TYPE_VOLUME}
|
83
|
+
|
84
|
+
newsecret.undefine
|
85
|
+
|
86
|
+
# TESTGROUP: secret.usageid
|
87
|
+
newsecret = conn.define_secret_xml(new_secret_xml)
|
88
|
+
|
89
|
+
expect_too_many_args(newsecret, "usageid", 1)
|
90
|
+
|
91
|
+
expect_success(newsecret, "no args", "usageid")
|
92
|
+
|
93
|
+
newsecret.undefine
|
94
|
+
|
95
|
+
# TESTGROUP: secret.xml_desc
|
96
|
+
newsecret = conn.define_secret_xml(new_secret_xml)
|
97
|
+
|
98
|
+
expect_too_many_args(newsecret, "xml_desc", 1, 2)
|
99
|
+
expect_invalid_arg_type(newsecret, "xml_desc", "foo")
|
100
|
+
|
101
|
+
expect_success(newsecret, "no args", "xml_desc")
|
102
|
+
|
103
|
+
newsecret.undefine
|
104
|
+
|
105
|
+
# TESTGROUP: secret.set_value
|
106
|
+
newsecret = conn.define_secret_xml(new_secret_xml)
|
107
|
+
|
108
|
+
expect_too_many_args(newsecret, "set_value", 1, 2, 3)
|
109
|
+
expect_too_few_args(newsecret, "set_value")
|
110
|
+
expect_invalid_arg_type(newsecret, "set_value", 1)
|
111
|
+
expect_invalid_arg_type(newsecret, "set_value", "foo", "bar")
|
112
|
+
|
113
|
+
expect_success(newsecret, "value arg", "set_value", "foo")
|
114
|
+
|
115
|
+
newsecret.undefine
|
116
|
+
|
117
|
+
# TESTGROUP: secret.get_value
|
118
|
+
newsecret = conn.define_secret_xml(new_secret_xml)
|
119
|
+
newsecret.set_value("foo")
|
120
|
+
|
121
|
+
expect_too_many_args(newsecret, "get_value", 1, 2)
|
122
|
+
expect_invalid_arg_type(newsecret, "get_value", 'foo')
|
123
|
+
|
124
|
+
expect_success(newsecret, "no args", "get_value") {|x| x == 'foo'}
|
125
|
+
|
126
|
+
newsecret.undefine
|
127
|
+
|
128
|
+
# TESTGROUP: secret.undefine
|
129
|
+
newsecret = conn.define_secret_xml(new_secret_xml)
|
130
|
+
|
131
|
+
expect_too_many_args(newsecret, "undefine", 1)
|
132
|
+
|
133
|
+
expect_success(newsecret, "no args", "undefine")
|
134
|
+
|
135
|
+
# TESTGROUP: secret.free
|
136
|
+
newsecret = conn.define_secret_xml(new_secret_xml)
|
137
|
+
newsecret.undefine
|
138
|
+
|
139
|
+
expect_too_many_args(newsecret, "free", 1)
|
140
|
+
|
141
|
+
expect_success(newsecret, "no args", "free")
|
142
|
+
|
33
143
|
conn.close
|
144
|
+
|
145
|
+
finish_tests
|
data/tests/test_storage.rb
CHANGED
@@ -2,48 +2,521 @@
|
|
2
2
|
|
3
3
|
# Test the storage methods the bindings support
|
4
4
|
|
5
|
+
$: << File.dirname(__FILE__)
|
6
|
+
|
5
7
|
require 'libvirt'
|
8
|
+
require 'test_utils.rb'
|
9
|
+
|
10
|
+
UUID = "33a5c045-645a-2c00-e56b-927cdf34e17a"
|
11
|
+
|
12
|
+
conn = Libvirt::open("qemu:///system")
|
13
|
+
|
14
|
+
begin
|
15
|
+
oldpool = conn.lookup_storage_pool_by_name("ruby-libvirt-tester")
|
16
|
+
oldpool.destroy
|
17
|
+
oldpool.undefine
|
18
|
+
rescue
|
19
|
+
# in case we didn't find it, don't do anything
|
20
|
+
end
|
21
|
+
|
22
|
+
# test setup
|
23
|
+
`rm -rf /tmp/ruby-libvirt-tester; mkdir /tmp/ruby-libvirt-tester`
|
24
|
+
|
25
|
+
new_storage_pool_xml = <<EOF
|
26
|
+
<pool type="dir">
|
27
|
+
<name>ruby-libvirt-tester</name>
|
28
|
+
<uuid>#{UUID}</uuid>
|
29
|
+
<target>
|
30
|
+
<path>/tmp/ruby-libvirt-tester</path>
|
31
|
+
</target>
|
32
|
+
</pool>
|
33
|
+
EOF
|
34
|
+
|
35
|
+
new_storage_vol_xml = <<EOF
|
36
|
+
<volume>
|
37
|
+
<name>test.img</name>
|
38
|
+
<allocation>0</allocation>
|
39
|
+
<capacity unit="G">1</capacity>
|
40
|
+
<target>
|
41
|
+
<path>/tmp/ruby-libvirt-tester/test.img</path>
|
42
|
+
</target>
|
43
|
+
</volume>
|
44
|
+
EOF
|
45
|
+
|
46
|
+
new_storage_vol_xml_2 = <<EOF
|
47
|
+
<volume>
|
48
|
+
<name>test2.img</name>
|
49
|
+
<allocation>0</allocation>
|
50
|
+
<capacity unit="G">5</capacity>
|
51
|
+
<target>
|
52
|
+
<path>/tmp/ruby-libvirt-tester/test2.img</path>
|
53
|
+
</target>
|
54
|
+
</volume>
|
55
|
+
EOF
|
56
|
+
|
57
|
+
# TESTGROUP: conn.list_storage_pools
|
58
|
+
expect_too_many_args(conn, "list_storage_pools", 1)
|
59
|
+
expect_success(conn, "no args", "list_storage_pools")
|
60
|
+
|
61
|
+
# TESTGROUP: conn.num_of_storage_pools
|
62
|
+
expect_too_many_args(conn, "num_of_storage_pools", 1)
|
63
|
+
expect_success(conn, "no args", "num_of_storage_pools")
|
64
|
+
|
65
|
+
# TESTGROUP: conn.list_defined_storage_pools
|
66
|
+
expect_too_many_args(conn, "list_defined_storage_pools", 1)
|
67
|
+
expect_success(conn, "no args", "list_defined_storage_pools")
|
68
|
+
|
69
|
+
# TESTGROUP: conn.num_of_defined_storage_pools
|
70
|
+
expect_too_many_args(conn, "num_of_defined_storage_pools", 1)
|
71
|
+
expect_success(conn, "no args", "num_of_defined_storage_pools")
|
72
|
+
|
73
|
+
# TESTGROUP: conn.lookup_storage_pool_by_name
|
74
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
75
|
+
|
76
|
+
expect_too_many_args(conn, "lookup_storage_pool_by_name", 1, 2)
|
77
|
+
expect_too_few_args(conn, "lookup_storage_pool_by_name")
|
78
|
+
expect_invalid_arg_type(conn, "lookup_storage_pool_by_name", 1)
|
79
|
+
expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_storage_pool_by_name", "foobarbazsucker")
|
80
|
+
|
81
|
+
expect_success(conn, "name arg", "lookup_storage_pool_by_name", "ruby-libvirt-tester")
|
82
|
+
|
83
|
+
newpool.destroy
|
84
|
+
|
85
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
86
|
+
expect_success(conn, "name arg", "lookup_storage_pool_by_name", "ruby-libvirt-tester")
|
87
|
+
newpool.undefine
|
88
|
+
|
89
|
+
# TESTGROUP: conn.lookup_storage_pool_by_uuid
|
90
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
91
|
+
|
92
|
+
expect_too_many_args(conn, "lookup_storage_pool_by_uuid", 1, 2)
|
93
|
+
expect_too_few_args(conn, "lookup_storage_pool_by_uuid")
|
94
|
+
expect_invalid_arg_type(conn, "lookup_storage_pool_by_uuid", 1)
|
95
|
+
expect_fail(conn, Libvirt::RetrieveError, "non-existent uuid arg", "lookup_storage_pool_by_uuid", "foobarbazsucker")
|
96
|
+
|
97
|
+
expect_success(conn, "uuid arg", "lookup_storage_pool_by_uuid", UUID)
|
98
|
+
|
99
|
+
newpool.destroy
|
100
|
+
|
101
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
102
|
+
|
103
|
+
expect_success(conn, "uuid arg", "lookup_storage_pool_by_uuid", UUID)
|
104
|
+
|
105
|
+
newpool.undefine
|
106
|
+
|
107
|
+
# TESTGROUP: vol.pool
|
108
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
109
|
+
|
110
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
111
|
+
|
112
|
+
expect_too_many_args(newvol, "pool", 1)
|
113
|
+
|
114
|
+
expect_success(newvol, "no args", "pool")
|
115
|
+
|
116
|
+
newvol.delete
|
117
|
+
|
118
|
+
newpool.destroy
|
119
|
+
|
120
|
+
# TESTGROUP: conn.create_storage_pool_xml
|
121
|
+
expect_too_many_args(conn, "create_storage_pool_xml", new_storage_pool_xml, 0, 1)
|
122
|
+
expect_too_few_args(conn, "create_storage_pool_xml")
|
123
|
+
expect_invalid_arg_type(conn, "create_storage_pool_xml", nil)
|
124
|
+
expect_invalid_arg_type(conn, "create_storage_pool_xml", 1)
|
125
|
+
expect_invalid_arg_type(conn, "create_storage_pool_xml", new_storage_pool_xml, "foo")
|
126
|
+
expect_fail(conn, Libvirt::Error, "invalid xml", "create_storage_pool_xml", "hello")
|
127
|
+
|
128
|
+
expect_success(conn, "storage pool XML", "create_storage_pool_xml", new_storage_pool_xml)
|
129
|
+
|
130
|
+
expect_fail(conn, Libvirt::Error, "already existing domain", "create_storage_pool_xml", new_storage_pool_xml)
|
131
|
+
|
132
|
+
newpool.destroy
|
133
|
+
|
134
|
+
# TESTGROUP: conn.define_storage_pool_xml
|
135
|
+
expect_too_many_args(conn, "define_storage_pool_xml", new_storage_pool_xml, 0, 1)
|
136
|
+
expect_too_few_args(conn, "define_storage_pool_xml")
|
137
|
+
expect_invalid_arg_type(conn, "define_storage_pool_xml", nil)
|
138
|
+
expect_invalid_arg_type(conn, "define_storage_pool_xml", 1)
|
139
|
+
expect_invalid_arg_type(conn, "define_storage_pool_xml", new_storage_pool_xml, "foo")
|
140
|
+
expect_fail(conn, Libvirt::Error, "invalid xml", "define_storage_pool_xml", "hello")
|
141
|
+
|
142
|
+
expect_success(conn, "storage pool XML", "define_storage_pool_xml", new_storage_pool_xml)
|
143
|
+
|
144
|
+
newpool.undefine
|
145
|
+
|
146
|
+
# TESTGROUP: conn.discover_storage_pool_sources
|
147
|
+
expect_too_many_args(conn, "discover_storage_pool_sources", 1, 2, 3, 4)
|
148
|
+
expect_too_few_args(conn, "discover_storage_pool_sources")
|
149
|
+
expect_invalid_arg_type(conn, "discover_storage_pool_sources", 1)
|
150
|
+
expect_invalid_arg_type(conn, "discover_storage_pool_sources", "foo", 1)
|
151
|
+
expect_invalid_arg_type(conn, "discover_storage_pool_sources", "foo", "bar", "baz")
|
152
|
+
|
153
|
+
expect_fail(conn, Libvirt::Error, "invalid pool type", "discover_storage_pool_sources", "foo")
|
154
|
+
|
155
|
+
expect_success(conn, "pool type", "discover_storage_pool_sources", "logical")
|
156
|
+
|
157
|
+
# TESTGROUP: pool.build
|
158
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
159
|
+
|
160
|
+
expect_too_many_args(newpool, "build", 1, 2)
|
161
|
+
expect_invalid_arg_type(newpool, "build", 'foo')
|
162
|
+
|
163
|
+
expect_success(newpool, "no args", "build")
|
164
|
+
|
165
|
+
newpool.undefine
|
166
|
+
|
167
|
+
# TESTGROUP: pool.undefine
|
168
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
169
|
+
|
170
|
+
expect_too_many_args(newpool, "undefine", 1)
|
171
|
+
|
172
|
+
expect_success(newpool, "no args", "undefine")
|
173
|
+
|
174
|
+
# TESTGROUP: pool.create
|
175
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
176
|
+
|
177
|
+
expect_too_many_args(newpool, "create", 1, 2)
|
178
|
+
expect_invalid_arg_type(newpool, "create", 'foo')
|
179
|
+
|
180
|
+
expect_success(newpool, "no args", "create")
|
181
|
+
|
182
|
+
newpool.destroy
|
183
|
+
newpool.undefine
|
184
|
+
|
185
|
+
# TESTGROUP: pool.destroy
|
186
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
187
|
+
|
188
|
+
expect_too_many_args(newpool, "destroy", 1)
|
189
|
+
|
190
|
+
expect_success(newpool, "no args", "destroy")
|
191
|
+
|
192
|
+
# TESTGROUP: pool.delete
|
193
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
194
|
+
|
195
|
+
expect_too_many_args(newpool, "delete", 1, 2)
|
196
|
+
expect_invalid_arg_type(newpool, "delete", 'foo')
|
197
|
+
|
198
|
+
expect_success(newpool, "no args", "delete")
|
199
|
+
|
200
|
+
`mkdir /tmp/ruby-libvirt-tester`
|
201
|
+
|
202
|
+
newpool.undefine
|
203
|
+
|
204
|
+
# TESTGROUP: pool.refresh
|
205
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
206
|
+
|
207
|
+
expect_too_many_args(newpool, "refresh", 1, 2)
|
208
|
+
expect_invalid_arg_type(newpool, "refresh", 'foo')
|
209
|
+
|
210
|
+
expect_success(newpool, "no args", "refresh")
|
211
|
+
|
212
|
+
newpool.destroy
|
213
|
+
|
214
|
+
# TESTGROUP: pool.name
|
215
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
216
|
+
|
217
|
+
expect_too_many_args(newpool, "name", 1)
|
218
|
+
|
219
|
+
expect_success(newpool, "no args", "name") {|x| x == "ruby-libvirt-tester"}
|
220
|
+
|
221
|
+
newpool.destroy
|
222
|
+
|
223
|
+
# TESTGROUP: pool.uuid
|
224
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
225
|
+
|
226
|
+
expect_too_many_args(newpool, "uuid", 1)
|
227
|
+
|
228
|
+
expect_success(newpool, "no args", "uuid") {|x| x == UUID}
|
229
|
+
|
230
|
+
newpool.destroy
|
231
|
+
|
232
|
+
# TESTGROUP: pool.info
|
233
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
234
|
+
|
235
|
+
expect_too_many_args(newpool, "info", 1)
|
236
|
+
|
237
|
+
expect_success(newpool, "no args", "info")
|
238
|
+
|
239
|
+
newpool.destroy
|
240
|
+
|
241
|
+
# TESTGROUP: pool.xml_desc
|
242
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
243
|
+
|
244
|
+
expect_too_many_args(newpool, "xml_desc", 1, 2)
|
245
|
+
expect_invalid_arg_type(newpool, "xml_desc", "foo")
|
246
|
+
|
247
|
+
expect_success(newpool, "no args", "xml_desc")
|
248
|
+
|
249
|
+
newpool.destroy
|
250
|
+
|
251
|
+
# TESTGROUP: pool.autostart?
|
252
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
253
|
+
|
254
|
+
expect_too_many_args(newpool, "autostart?", 1)
|
255
|
+
|
256
|
+
expect_success(newpool, "no args", "autostart?") {|x| x == false}
|
257
|
+
|
258
|
+
newpool.autostart = true
|
259
|
+
|
260
|
+
expect_success(newpool, "no args", "autostart?") {|x| x == true}
|
261
|
+
|
262
|
+
newpool.undefine
|
6
263
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
puts " Allocation: #{info.allocation}"
|
28
|
-
puts " Available: #{info.available}"
|
29
|
-
puts " XML:"
|
30
|
-
puts storagepool.xml_desc
|
31
|
-
puts " Number of Volumes: #{storagepool.num_of_volumes}"
|
32
|
-
puts " Volumes:"
|
33
|
-
storagepool.list_volumes.each do |volname|
|
34
|
-
storagevolume = storagepool.lookup_volume_by_name(volname)
|
35
|
-
vol2 = storagepool.lookup_volume_by_key(storagevolume.key)
|
36
|
-
vol3 = storagepool.lookup_volume_by_path(storagevolume.path)
|
37
|
-
puts " Volume #{storagevolume.name}:"
|
38
|
-
puts " Pool: #{storagevolume.pool.name}"
|
39
|
-
puts " Key: #{storagevolume.key}"
|
40
|
-
puts " Path: #{storagevolume.path}"
|
41
|
-
info = storagevolume.info
|
42
|
-
puts " Info:"
|
43
|
-
puts " Type: #{info.type}"
|
44
|
-
puts " Capacity: #{info.capacity}"
|
45
|
-
puts " Allocation: #{info.allocation}"
|
46
|
-
end
|
264
|
+
# TESTGROUP: pool.autostart=
|
265
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
266
|
+
|
267
|
+
expect_too_many_args(newpool, "autostart=", 1, 2)
|
268
|
+
expect_invalid_arg_type(newpool, "autostart=", 'foo')
|
269
|
+
expect_invalid_arg_type(newpool, "autostart=", nil)
|
270
|
+
expect_invalid_arg_type(newpool, "autostart=", 1234)
|
271
|
+
|
272
|
+
expect_success(newpool, "no args", "autostart=", true)
|
273
|
+
if not newpool.autostart?
|
274
|
+
puts_fail "pool.autostart= did not set autostart to true"
|
275
|
+
else
|
276
|
+
puts_ok "pool.autostart= set autostart to true"
|
277
|
+
end
|
278
|
+
|
279
|
+
expect_success(newpool, "no args", "autostart=", false)
|
280
|
+
if newpool.autostart?
|
281
|
+
puts_fail "pool.autostart= did not set autostart to false"
|
282
|
+
else
|
283
|
+
puts_ok "pool.autostart= set autostart to false"
|
47
284
|
end
|
48
285
|
|
286
|
+
newpool.undefine
|
287
|
+
|
288
|
+
# TESTGROUP: pool.num_of_volumes
|
289
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
290
|
+
|
291
|
+
expect_too_many_args(newpool, "num_of_volumes", 1)
|
292
|
+
|
293
|
+
expect_success(newpool, "no args", "num_of_volumes") {|x| x == 0}
|
294
|
+
|
295
|
+
newpool.destroy
|
296
|
+
|
297
|
+
# TESTGROUP: pool.list_volumes
|
298
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
299
|
+
|
300
|
+
expect_too_many_args(newpool, "list_volumes", 1)
|
301
|
+
|
302
|
+
expect_success(newpool, "no args", "list_volumes")
|
303
|
+
|
304
|
+
newpool.destroy
|
305
|
+
|
306
|
+
# TESTGROUP: pool.free
|
307
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
308
|
+
newpool.undefine
|
309
|
+
expect_too_many_args(newpool, "free", 1)
|
310
|
+
|
311
|
+
expect_success(newpool, "no args", "free")
|
312
|
+
|
313
|
+
# TESTGROUP: pool.lookup_volume_by_name
|
314
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
315
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
316
|
+
|
317
|
+
expect_too_many_args(newpool, "lookup_volume_by_name", 1, 2)
|
318
|
+
expect_too_few_args(newpool, "lookup_volume_by_name")
|
319
|
+
expect_invalid_arg_type(newpool, "lookup_volume_by_name", 1);
|
320
|
+
expect_invalid_arg_type(newpool, "lookup_volume_by_name", nil);
|
321
|
+
expect_fail(newpool, Libvirt::RetrieveError, "non-existent name arg", "lookup_volume_by_name", "foobarbazsucker")
|
322
|
+
|
323
|
+
expect_success(newpool, "name arg", "lookup_volume_by_name", "test.img")
|
324
|
+
|
325
|
+
newvol.delete
|
326
|
+
newpool.destroy
|
327
|
+
|
328
|
+
# TESTGROUP: pool.lookup_volume_by_key
|
329
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
330
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
331
|
+
|
332
|
+
expect_too_many_args(newpool, "lookup_volume_by_key", 1, 2)
|
333
|
+
expect_too_few_args(newpool, "lookup_volume_by_key")
|
334
|
+
expect_invalid_arg_type(newpool, "lookup_volume_by_key", 1);
|
335
|
+
expect_invalid_arg_type(newpool, "lookup_volume_by_key", nil);
|
336
|
+
expect_fail(newpool, Libvirt::RetrieveError, "non-existent key arg", "lookup_volume_by_key", "foobarbazsucker")
|
337
|
+
|
338
|
+
expect_success(newpool, "name arg", "lookup_volume_by_key", newvol.key)
|
339
|
+
|
340
|
+
newvol.delete
|
341
|
+
newpool.destroy
|
342
|
+
|
343
|
+
# TESTGROUP: pool.lookup_volume_by_path
|
344
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
345
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
346
|
+
|
347
|
+
expect_too_many_args(newpool, "lookup_volume_by_path", 1, 2)
|
348
|
+
expect_too_few_args(newpool, "lookup_volume_by_path")
|
349
|
+
expect_invalid_arg_type(newpool, "lookup_volume_by_path", 1);
|
350
|
+
expect_invalid_arg_type(newpool, "lookup_volume_by_path", nil);
|
351
|
+
expect_fail(newpool, Libvirt::RetrieveError, "non-existent path arg", "lookup_volume_by_path", "foobarbazsucker")
|
352
|
+
|
353
|
+
expect_success(newpool, "name arg", "lookup_volume_by_path", newvol.path)
|
354
|
+
|
355
|
+
newvol.delete
|
356
|
+
newpool.destroy
|
357
|
+
|
358
|
+
# TESTGROUP: vol.name
|
359
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
360
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
361
|
+
|
362
|
+
expect_too_many_args(newvol, "name", 1)
|
363
|
+
|
364
|
+
expect_success(newvol, "no args", "name")
|
365
|
+
|
366
|
+
newvol.delete
|
367
|
+
newpool.destroy
|
368
|
+
|
369
|
+
# TESTGROUP: vol.key
|
370
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
371
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
372
|
+
|
373
|
+
expect_too_many_args(newvol, "key", 1)
|
374
|
+
|
375
|
+
expect_success(newvol, "no args", "key")
|
376
|
+
|
377
|
+
newvol.delete
|
378
|
+
newpool.destroy
|
379
|
+
|
380
|
+
# TESTGROUP: pool.create_volume_xml
|
381
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
382
|
+
|
383
|
+
expect_too_many_args(newpool, "create_volume_xml", new_storage_vol_xml, 0, 1)
|
384
|
+
expect_too_few_args(newpool, "create_volume_xml")
|
385
|
+
expect_invalid_arg_type(newpool, "create_volume_xml", nil)
|
386
|
+
expect_invalid_arg_type(newpool, "create_volume_xml", 1)
|
387
|
+
expect_invalid_arg_type(newpool, "create_volume_xml", new_storage_vol_xml, "foo")
|
388
|
+
expect_fail(newpool, Libvirt::Error, "invalid xml", "create_volume_xml", "hello")
|
389
|
+
|
390
|
+
expect_success(newpool, "storage volume XML", "create_volume_xml", new_storage_vol_xml)
|
391
|
+
|
392
|
+
expect_fail(newpool, Libvirt::Error, "already existing domain", "create_volume_xml", new_storage_vol_xml)
|
393
|
+
|
394
|
+
newvol.delete
|
395
|
+
newpool.destroy
|
396
|
+
|
397
|
+
# TESTGROUP: pool.create_volume_xml_from
|
398
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
399
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
400
|
+
|
401
|
+
expect_too_many_args(newpool, "create_volume_xml_from", new_storage_vol_xml_2, 0, 1, 2)
|
402
|
+
expect_too_few_args(newpool, "create_volume_xml_from")
|
403
|
+
expect_invalid_arg_type(newpool, "create_volume_xml_from", 1, 2)
|
404
|
+
expect_invalid_arg_type(newpool, "create_volume_xml_from", "foo", 2)
|
405
|
+
expect_invalid_arg_type(newpool, "create_volume_xml_from", "foo", newvol, "bar")
|
406
|
+
expect_fail(newpool, Libvirt::Error, "invalid xml", "create_volume_xml_from", "hello", newvol)
|
407
|
+
|
408
|
+
newvol2 = expect_success(newpool, "storage volume XML", "create_volume_xml_from", new_storage_vol_xml_2, newvol)
|
409
|
+
|
410
|
+
expect_fail(newpool, Libvirt::Error, "already existing domain", "create_volume_xml_from", new_storage_vol_xml_2, newvol)
|
411
|
+
|
412
|
+
newvol2.delete
|
413
|
+
newvol.delete
|
414
|
+
newpool.destroy
|
415
|
+
|
416
|
+
# TESTGROUP: pool.active?
|
417
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
418
|
+
|
419
|
+
expect_too_many_args(newpool, "active?", 1)
|
420
|
+
|
421
|
+
expect_success(newpool, "no args", "active?") {|x| x == true}
|
422
|
+
|
423
|
+
newpool.destroy
|
424
|
+
|
425
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
426
|
+
|
427
|
+
expect_success(newpool, "no args", "active?") {|x| x == false}
|
428
|
+
|
429
|
+
newpool.create
|
430
|
+
|
431
|
+
expect_success(newpool, "no args", "active?") {|x| x == true}
|
432
|
+
|
433
|
+
newpool.destroy
|
434
|
+
newpool.undefine
|
435
|
+
|
436
|
+
# TESTGROUP: pool.persistent?
|
437
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
438
|
+
sleep 1
|
439
|
+
|
440
|
+
expect_too_many_args(newpool, "persistent?", 1)
|
441
|
+
|
442
|
+
expect_success(newpool, "no args", "persistent?") {|x| x == false}
|
443
|
+
|
444
|
+
newpool.destroy
|
445
|
+
|
446
|
+
newpool = conn.define_storage_pool_xml(new_storage_pool_xml)
|
447
|
+
|
448
|
+
expect_success(newpool, "no args", "persistent?") {|x| x == true}
|
449
|
+
|
450
|
+
newpool.undefine
|
451
|
+
|
452
|
+
# TESTGROUP: vol.delete
|
453
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
454
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
455
|
+
|
456
|
+
expect_too_many_args(newvol, "delete", 1, 2)
|
457
|
+
expect_invalid_arg_type(newvol, "delete", 'foo')
|
458
|
+
|
459
|
+
expect_success(newvol, "no args", "delete")
|
460
|
+
|
461
|
+
newpool.destroy
|
462
|
+
|
463
|
+
# TESTGROUP: vol.wipe
|
464
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
465
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
466
|
+
|
467
|
+
expect_too_many_args(newvol, "wipe", 1, 2)
|
468
|
+
expect_invalid_arg_type(newvol, "wipe", 'foo')
|
469
|
+
|
470
|
+
expect_success(newvol, "no args", "wipe")
|
471
|
+
|
472
|
+
newvol.delete
|
473
|
+
newpool.destroy
|
474
|
+
|
475
|
+
# TESTGROUP: vol.info
|
476
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
477
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
478
|
+
|
479
|
+
expect_too_many_args(newvol, "info", 1)
|
480
|
+
|
481
|
+
expect_success(newvol, "no args", "info")
|
482
|
+
|
483
|
+
newvol.delete
|
484
|
+
newpool.destroy
|
485
|
+
|
486
|
+
# TESTGROUP: vol.xml_desc
|
487
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
488
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
489
|
+
|
490
|
+
expect_too_many_args(newvol, "xml_desc", 1, 2)
|
491
|
+
expect_invalid_arg_type(newvol, "xml_desc", "foo")
|
492
|
+
|
493
|
+
expect_success(newvol, "no args", "xml_desc")
|
494
|
+
|
495
|
+
newvol.delete
|
496
|
+
newpool.destroy
|
497
|
+
|
498
|
+
# TESTGROUP: vol.path
|
499
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
500
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
501
|
+
|
502
|
+
expect_too_many_args(newvol, "path", 1)
|
503
|
+
|
504
|
+
expect_success(newvol, "no args", "path")
|
505
|
+
|
506
|
+
newvol.delete
|
507
|
+
newpool.destroy
|
508
|
+
|
509
|
+
# TESTGROUP: vol.free
|
510
|
+
newpool = conn.create_storage_pool_xml(new_storage_pool_xml)
|
511
|
+
newvol = newpool.create_volume_xml(new_storage_vol_xml)
|
512
|
+
newvol.delete
|
513
|
+
|
514
|
+
expect_too_many_args(newvol, "free", 1)
|
515
|
+
|
516
|
+
expect_success(newvol, "no args", "free")
|
517
|
+
|
518
|
+
newpool.destroy
|
519
|
+
|
49
520
|
conn.close
|
521
|
+
|
522
|
+
finish_tests
|