ruby-libvirt 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,90 +17,24 @@ def find_valid_iface(conn)
17
17
  end
18
18
  end
19
19
 
20
-
21
20
  conn = Libvirt::open("qemu:///system")
22
21
 
22
+ # test setup
23
23
  begin
24
24
  `rm -f /etc/sysconfig/network-scripts/ifcfg-ruby-libvirt-tester`
25
25
  `brctl delbr ruby-libvirt-tester >& /dev/null`
26
26
  rescue
27
27
  end
28
28
 
29
- new_interface_xml = <<EOF
30
- <interface type="bridge" name="ruby-libvirt-tester">
31
- <start mode="onboot"/>
32
- <bridge delay="0">
33
- </bridge>
34
- </interface>
35
- EOF
36
-
37
- # TESTGROUP: conn.num_of_interfaces
38
- expect_too_many_args(conn, "num_of_interfaces", 1)
39
- expect_success(conn, "no args", "num_of_interfaces")
40
-
41
- # TESTGROUP: conn.list_interfaces
42
- expect_too_many_args(conn, "list_interfaces", 1)
43
- expect_success(conn, "no args", "list_interfaces")
44
-
45
- # TESTGROUP: conn.num_of_defined_interfaces
46
- expect_too_many_args(conn, "num_of_defined_interfaces", 1)
47
- expect_success(conn, "no args", "num_of_defined_interfaces")
48
-
49
- # TESTGROUP: conn.list_defined_interfaces
50
- expect_too_many_args(conn, "list_defined_interfaces", 1)
51
- expect_success(conn, "no args", "list_defined_interfaces")
52
-
53
- # TESTGROUP: conn.lookup_interface_by_name
54
- newiface = conn.define_interface_xml(new_interface_xml)
55
-
56
- expect_too_many_args(conn, "lookup_interface_by_name", 1, 2)
57
- expect_too_few_args(conn, "lookup_interface_by_name")
58
- expect_invalid_arg_type(conn, "lookup_interface_by_name", 1)
59
- expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_interface_by_name", "foobarbazsucker")
60
-
61
- expect_success(conn, "name arg", "lookup_interface_by_name", "ruby-libvirt-tester")
62
-
63
- newiface.destroy
64
-
65
- expect_success(conn, "name arg", "lookup_interface_by_name", "ruby-libvirt-tester")
66
-
67
- newiface.undefine
68
-
69
- # TESTGROUP: conn.lookup_interface_by_mac
70
- newiface = conn.define_interface_xml(new_interface_xml)
71
-
72
- expect_too_many_args(conn, "lookup_interface_by_mac", 1, 2)
73
- expect_too_few_args(conn, "lookup_interface_by_mac")
74
- expect_invalid_arg_type(conn, "lookup_interface_by_mac", 1)
75
- expect_fail(conn, Libvirt::RetrieveError, "non-existent mac arg", "lookup_interface_by_mac", "foobarbazsucker")
76
-
77
- testiface = find_valid_iface(conn)
78
- if not testiface.nil?
79
- expect_success(conn, "name arg", "lookup_interface_by_mac", testiface.mac) {|x| x.mac == testiface.mac}
80
- end
81
-
82
- newiface.undefine
83
-
84
- # TESTGROUP: conn.define_interface_xml
85
- expect_too_many_args(conn, "define_interface_xml", 1, 2, 3)
86
- expect_too_few_args(conn, "define_interface_xml")
87
- expect_invalid_arg_type(conn, "define_interface_xml", 1)
88
- expect_invalid_arg_type(conn, "define_interface_xml", nil)
89
- expect_invalid_arg_type(conn, "define_interface_xml", "hello", 'foo')
90
- expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_interface_xml", "hello")
91
-
92
- expect_success(conn, "interface XML", "define_interface_xml", new_interface_xml)
93
- newiface.undefine
94
-
95
29
  # TESTGROUP: iface.undefine
96
- newiface = conn.define_interface_xml(new_interface_xml)
30
+ newiface = conn.define_interface_xml($new_interface_xml)
97
31
 
98
32
  expect_too_many_args(newiface, "undefine", 1)
99
33
 
100
34
  expect_success(newiface, "no args", "undefine")
101
35
 
102
36
  # TESTGROUP: iface.create
103
- newiface = conn.define_interface_xml(new_interface_xml)
37
+ newiface = conn.define_interface_xml($new_interface_xml)
104
38
 
105
39
  expect_too_many_args(newiface, "create", 1, 2)
106
40
  expect_invalid_arg_type(newiface, "create", 'foo')
@@ -113,7 +47,7 @@ expect_invalid_arg_type(newiface, "create", 'foo')
113
47
  newiface.undefine
114
48
 
115
49
  # TESTGROUP: iface.destroy
116
- newiface = conn.define_interface_xml(new_interface_xml)
50
+ newiface = conn.define_interface_xml($new_interface_xml)
117
51
 
118
52
  expect_too_many_args(newiface, "destroy", 1, 2)
119
53
  expect_invalid_arg_type(newiface, "destroy", 'foo')
@@ -123,7 +57,7 @@ expect_success(newiface, "no args", "destroy")
123
57
  newiface.undefine
124
58
 
125
59
  # TESTGROUP: iface.active?
126
- newiface = conn.define_interface_xml(new_interface_xml)
60
+ newiface = conn.define_interface_xml($new_interface_xml)
127
61
 
128
62
  expect_too_many_args(newiface, "active?", 1)
129
63
 
@@ -136,7 +70,7 @@ expect_success(newiface, "no args", "active?") {|x| x == false}
136
70
  newiface.undefine
137
71
 
138
72
  # TESTGROUP: iface.name
139
- newiface = conn.define_interface_xml(new_interface_xml)
73
+ newiface = conn.define_interface_xml($new_interface_xml)
140
74
 
141
75
  expect_too_many_args(newiface, "name", 1)
142
76
 
@@ -161,7 +95,7 @@ if not testiface.nil?
161
95
  end
162
96
 
163
97
  # TESTGROUP: iface.free
164
- newiface = conn.define_interface_xml(new_interface_xml)
98
+ newiface = conn.define_interface_xml($new_interface_xml)
165
99
  newiface.undefine
166
100
  expect_too_many_args(newiface, "free", 1)
167
101
 
@@ -7,8 +7,6 @@ $: << File.dirname(__FILE__)
7
7
  require 'libvirt'
8
8
  require 'test_utils.rb'
9
9
 
10
- UUID = "04068860-d9a2-47c5-bc9d-9e047ae901da"
11
-
12
10
  conn = Libvirt::open("qemu:///system")
13
11
 
14
12
  # initial cleanup for previous run
@@ -20,98 +18,15 @@ rescue
20
18
  # in case we didn't find it, don't do anything
21
19
  end
22
20
 
23
- new_net_xml = <<EOF
24
- <network>
25
- <name>ruby-libvirt-tester</name>
26
- <uuid>#{UUID}</uuid>
27
- <forward mode='nat'/>
28
- <bridge name='rubybr0' stp='on' delay='0' />
29
- <ip address='192.168.134.1' netmask='255.255.255.0'>
30
- <dhcp>
31
- <range start='192.168.134.2' end='192.168.134.254' />
32
- </dhcp>
33
- </ip>
34
- </network>
35
- EOF
36
-
37
- # TESTGROUP: conn.num_of_networks
38
- expect_too_many_args(conn, "num_of_networks", 1)
39
- expect_success(conn, "no args", "num_of_networks")
40
-
41
- # TESTGROUP: conn.list_networks
42
- expect_too_many_args(conn, "list_networks", 1)
43
- expect_success(conn, "no args", "list_networks")
44
-
45
- # TESTGROUP: conn.num_of_defined_networks
46
- expect_too_many_args(conn, "num_of_defined_networks", 1)
47
- expect_success(conn, "no args", "num_of_defined_networks")
48
-
49
- # TESTGROUP: conn.list_defined_networks
50
- expect_too_many_args(conn, "list_defined_networks", 1)
51
- expect_success(conn, "no args", "list_defined_networks")
52
-
53
- # TESTGROUP: conn.lookup_network_by_name
54
- newnet = conn.create_network_xml(new_net_xml)
55
-
56
- expect_too_many_args(conn, "lookup_network_by_name", 1, 2)
57
- expect_too_few_args(conn, "lookup_network_by_name")
58
- expect_invalid_arg_type(conn, "lookup_network_by_name", 1)
59
- expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_network_by_name", "foobarbazsucker")
60
-
61
- expect_success(conn, "name arg", "lookup_network_by_name", "ruby-libvirt-tester")
62
- newnet.destroy
63
-
64
- newnet = conn.define_network_xml(new_net_xml)
65
- expect_success(conn, "name arg", "lookup_network_by_name", "ruby-libvirt-tester")
66
- newnet.undefine
67
-
68
- # TESTGROUP: conn.lookup_network_by_uuid
69
- newnet = conn.create_network_xml(new_net_xml)
70
-
71
- expect_too_many_args(conn, "lookup_network_by_uuid", 1, 2)
72
- expect_too_few_args(conn, "lookup_network_by_uuid")
73
- expect_invalid_arg_type(conn, "lookup_network_by_uuid", 1)
74
- expect_fail(conn, Libvirt::RetrieveError, "non-existent uuid arg", "lookup_network_by_uuid", "foobarbazsucker")
75
-
76
- expect_success(conn, "uuid arg", "lookup_network_by_uuid", UUID)
77
- newnet.destroy
78
-
79
- newnet = conn.define_network_xml(new_net_xml)
80
- expect_success(conn, "uuid arg", "lookup_network_by_uuid", UUID)
81
- newnet.undefine
82
-
83
- # TESTGROUP: conn.create_network_xml
84
- expect_too_many_args(conn, "create_network_xml", new_net_xml, 0)
85
- expect_too_few_args(conn, "create_network_xml")
86
- expect_invalid_arg_type(conn, "create_network_xml", nil)
87
- expect_invalid_arg_type(conn, "create_network_xml", 1)
88
- expect_fail(conn, Libvirt::Error, "invalid xml", "create_network_xml", "hello")
89
-
90
- newnet = expect_success(conn, "network XML", "create_network_xml", new_net_xml)
91
-
92
- expect_fail(conn, Libvirt::Error, "already existing network", "create_network_xml", new_net_xml)
93
-
94
- newnet.destroy
95
-
96
- # TESTGROUP: conn.define_network_xml
97
- expect_too_many_args(conn, "define_network_xml", 1, 2)
98
- expect_too_few_args(conn, "define_network_xml")
99
- expect_invalid_arg_type(conn, "define_network_xml", 1)
100
- expect_invalid_arg_type(conn, "define_network_xml", nil)
101
- expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_network_xml", "hello")
102
-
103
- newnet = expect_success(conn, "network XML", "define_network_xml", new_net_xml)
104
- newnet.undefine
105
-
106
21
  # TESTGROUP: net.undefine
107
- newnet = conn.define_network_xml(new_net_xml)
22
+ newnet = conn.define_network_xml($new_net_xml)
108
23
 
109
24
  expect_too_many_args(newnet, "undefine", 1)
110
25
 
111
26
  expect_success(newnet, "no args", "undefine")
112
27
 
113
28
  # TESTGROUP: net.create
114
- newnet = conn.define_network_xml(new_net_xml)
29
+ newnet = conn.define_network_xml($new_net_xml)
115
30
 
116
31
  expect_too_many_args(newnet, "create", 1)
117
32
 
@@ -123,14 +38,14 @@ newnet.destroy
123
38
  newnet.undefine
124
39
 
125
40
  # TESTGROUP: net.destroy
126
- newnet = conn.create_network_xml(new_net_xml)
41
+ newnet = conn.create_network_xml($new_net_xml)
127
42
 
128
43
  expect_too_many_args(newnet, "destroy", 1)
129
44
 
130
45
  expect_success(newnet, "no args", "destroy")
131
46
 
132
47
  # TESTGROUP: net.name
133
- newnet = conn.create_network_xml(new_net_xml)
48
+ newnet = conn.create_network_xml($new_net_xml)
134
49
 
135
50
  expect_too_many_args(newnet, "name", 1)
136
51
 
@@ -139,16 +54,16 @@ expect_success(newnet, "no args", "name") {|x| x == "ruby-libvirt-tester"}
139
54
  newnet.destroy
140
55
 
141
56
  # TESTGROUP: net.uuid
142
- newnet = conn.create_network_xml(new_net_xml)
57
+ newnet = conn.create_network_xml($new_net_xml)
143
58
 
144
59
  expect_too_many_args(newnet, "uuid", 1)
145
60
 
146
- expect_success(newnet, "no args", "uuid") {|x| x == UUID}
61
+ expect_success(newnet, "no args", "uuid") {|x| x == $NETWORK_UUID}
147
62
 
148
63
  newnet.destroy
149
64
 
150
65
  # TESTGROUP: net.xml_desc
151
- newnet = conn.create_network_xml(new_net_xml)
66
+ newnet = conn.create_network_xml($new_net_xml)
152
67
 
153
68
  expect_too_many_args(newnet, "xml_desc", 1, 2)
154
69
  expect_invalid_arg_type(newnet, "xml_desc", "foo")
@@ -158,7 +73,7 @@ expect_success(newnet, "no args", "xml_desc")
158
73
  newnet.destroy
159
74
 
160
75
  # TESTGROUP: net.bridge_name
161
- newnet = conn.create_network_xml(new_net_xml)
76
+ newnet = conn.create_network_xml($new_net_xml)
162
77
 
163
78
  expect_too_many_args(newnet, "bridge_name", 1)
164
79
 
@@ -167,7 +82,7 @@ expect_success(newnet, "no args", "bridge_name") {|x| x == "rubybr0"}
167
82
  newnet.destroy
168
83
 
169
84
  # TESTGROUP: net.autostart?
170
- newnet = conn.define_network_xml(new_net_xml)
85
+ newnet = conn.define_network_xml($new_net_xml)
171
86
 
172
87
  expect_too_many_args(newnet, "autostart?", 1)
173
88
 
@@ -180,7 +95,7 @@ expect_success(newnet, "no args", "autostart?") {|x| x == true}
180
95
  newnet.undefine
181
96
 
182
97
  # TESTGROUP: net.autostart=
183
- newnet = conn.define_network_xml(new_net_xml)
98
+ newnet = conn.define_network_xml($new_net_xml)
184
99
 
185
100
  expect_too_many_args(newnet, "autostart=", 1, 2)
186
101
  expect_invalid_arg_type(newnet, "autostart=", 'foo')
@@ -204,14 +119,14 @@ end
204
119
  newnet.undefine
205
120
 
206
121
  # TESTGROUP: net.free
207
- newnet = conn.define_network_xml(new_net_xml)
122
+ newnet = conn.define_network_xml($new_net_xml)
208
123
  newnet.undefine
209
124
  expect_too_many_args(newnet, "free", 1)
210
125
 
211
126
  expect_success(newnet, "no args", "free")
212
127
 
213
128
  # TESTGROUP: net.active?
214
- newnet = conn.create_network_xml(new_net_xml)
129
+ newnet = conn.create_network_xml($new_net_xml)
215
130
 
216
131
  expect_too_many_args(newnet, "active?", 1)
217
132
 
@@ -219,7 +134,7 @@ expect_success(newnet, "no args", "active?") {|x| x == true}
219
134
 
220
135
  newnet.destroy
221
136
 
222
- newnet = conn.define_network_xml(new_net_xml)
137
+ newnet = conn.define_network_xml($new_net_xml)
223
138
 
224
139
  expect_success(newnet, "no args", "active?") {|x| x == false}
225
140
 
@@ -231,7 +146,7 @@ newnet.destroy
231
146
  newnet.undefine
232
147
 
233
148
  # TESTGROUP: net.persistent?
234
- newnet = conn.create_network_xml(new_net_xml)
149
+ newnet = conn.create_network_xml($new_net_xml)
235
150
 
236
151
  expect_too_many_args(newnet, "persistent?", 1)
237
152
 
@@ -239,7 +154,7 @@ expect_success(newnet, "no args", "persistent?") {|x| x == false}
239
154
 
240
155
  newnet.destroy
241
156
 
242
- newnet = conn.define_network_xml(new_net_xml)
157
+ newnet = conn.define_network_xml($new_net_xml)
243
158
 
244
159
  expect_success(newnet, "no args", "persistent?") {|x| x == true}
245
160
 
@@ -9,37 +9,6 @@ require 'test_utils.rb'
9
9
 
10
10
  conn = Libvirt::open("qemu:///system")
11
11
 
12
- # TESTGROUP: conn.num_of_nodedevices
13
- expect_too_many_args(conn, "num_of_nodedevices", 1, 2, 3)
14
- expect_invalid_arg_type(conn, "num_of_nodedevices", 1)
15
- expect_invalid_arg_type(conn, "num_of_nodedevices", 'foo', 'bar')
16
- expect_success(conn, "no args", "num_of_nodedevices")
17
-
18
- # TESTGROUP: conn.list_nodedevices
19
- expect_too_many_args(conn, "list_nodedevices", 1, 2, 3)
20
- expect_invalid_arg_type(conn, "list_nodedevices", 1)
21
- expect_invalid_arg_type(conn, "list_nodedevices", 'foo', 'bar')
22
- expect_success(conn, "no args", "list_nodedevices")
23
-
24
- # TESTGROUP: conn.lookup_nodedevice_by_name
25
- testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
26
-
27
- expect_too_many_args(conn, "lookup_nodedevice_by_name", 1, 2)
28
- expect_too_few_args(conn, "lookup_nodedevice_by_name")
29
- expect_invalid_arg_type(conn, "lookup_nodedevice_by_name", 1)
30
- expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_nodedevice_by_name", "foobarbazsucker")
31
-
32
- expect_success(conn, "name arg", "lookup_nodedevice_by_name", testnode.name)
33
-
34
- # TESTGROUP: conn.create_nodedevice_xml
35
- expect_too_many_args(conn, "create_nodedevice_xml", 1, 2, 3)
36
- expect_too_few_args(conn, "create_nodedevice_xml")
37
- expect_invalid_arg_type(conn, "create_nodedevice_xml", 1)
38
- expect_invalid_arg_type(conn, "create_nodedevice_xml", "foo", 'bar')
39
- expect_fail(conn, Libvirt::Error, "invalid XML", "create_nodedevice_xml", "hello")
40
-
41
- #expect_success(conn, "nodedevice XML", "create_nodedevice_xml", "<nodedevice/>")
42
-
43
12
  # TESTGROUP: nodedevice.name
44
13
  testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0])
45
14
 
@@ -7,72 +7,17 @@ $: << File.dirname(__FILE__)
7
7
  require 'libvirt'
8
8
  require 'test_utils.rb'
9
9
 
10
- UUID = "bd339530-134c-6d07-441a-17fb90dad807"
11
-
12
10
  conn = Libvirt::open("qemu:///system")
13
11
 
14
- new_nwfilter_xml = <<EOF
15
- <filter name='ruby-libvirt-tester' chain='ipv4'>
16
- <uuid>#{UUID}</uuid>
17
- <rule action='accept' direction='out' priority='100'>
18
- <ip srcipaddr='0.0.0.0' dstipaddr='255.255.255.255' protocol='tcp' srcportstart='63000' dstportstart='62000'/>
19
- </rule>
20
- <rule action='accept' direction='in' priority='100'>
21
- <ip protocol='tcp' srcportstart='63000' dstportstart='62000'/>
22
- </rule>
23
- </filter>
24
- EOF
25
-
26
- # TESTGROUP: conn.num_of_nwfilters
27
- expect_too_many_args(conn, "num_of_nwfilters", 1)
28
- expect_success(conn, "no args", "num_of_nwfilters")
29
-
30
- # TESTGROUP: conn.list_nwfilters
31
- expect_too_many_args(conn, "list_nwfilters", 1)
32
- expect_success(conn, "no args", "list_nwfilters")
33
-
34
- # TESTGROUP: conn.lookup_nwfilter_by_name
35
- newnw = conn.define_nwfilter_xml(new_nwfilter_xml)
36
-
37
- expect_too_many_args(conn, "lookup_nwfilter_by_name", 1, 2)
38
- expect_too_few_args(conn, "lookup_nwfilter_by_name")
39
- expect_invalid_arg_type(conn, "lookup_nwfilter_by_name", 1)
40
-
41
- expect_success(conn, "name arg", "lookup_nwfilter_by_name", "ruby-libvirt-tester")
42
-
43
- newnw.undefine
44
-
45
- # TESTGROUP: conn.lookup_nwfilter_by_uuid
46
- newnw = conn.define_nwfilter_xml(new_nwfilter_xml)
47
-
48
- expect_too_many_args(conn, "lookup_nwfilter_by_uuid", 1, 2)
49
- expect_too_few_args(conn, "lookup_nwfilter_by_uuid")
50
- expect_invalid_arg_type(conn, "lookup_nwfilter_by_uuid", 1)
51
-
52
- expect_success(conn, "uuid arg", "lookup_nwfilter_by_uuid", UUID) {|x| x.uuid == UUID}
53
-
54
- newnw.undefine
55
-
56
- # TESTGROUP: conn.define_nwfilter_xml
57
- expect_too_many_args(conn, "define_nwfilter_xml", 1, 2)
58
- expect_too_few_args(conn, "define_nwfilter_xml")
59
- expect_invalid_arg_type(conn, "define_nwfilter_xml", 1)
60
- expect_invalid_arg_type(conn, "define_nwfilter_xml", nil)
61
- expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_nwfilter_xml", "hello")
62
-
63
- newnw = expect_success(conn, "nwfilter XML", "define_nwfilter_xml", new_nwfilter_xml)
64
-
65
- newnw.undefine
66
-
67
12
  # TESTGROUP: nwfilter.undefine
68
- newnw = conn.define_nwfilter_xml(new_nwfilter_xml)
13
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
69
14
 
70
15
  expect_too_many_args(newnw, "undefine", 1)
71
16
 
72
17
  expect_success(newnw, "no args", "undefine")
73
18
 
74
19
  # TESTGROUP: nwfilter.name
75
- newnw = conn.define_nwfilter_xml(new_nwfilter_xml)
20
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
76
21
 
77
22
  expect_too_many_args(newnw, "name", 1)
78
23
 
@@ -81,16 +26,16 @@ expect_success(newnw, "no args", "name") {|x| x == "ruby-libvirt-tester"}
81
26
  newnw.undefine
82
27
 
83
28
  # TESTGROUP: nwfilter.uuid
84
- newnw = conn.define_nwfilter_xml(new_nwfilter_xml)
29
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
85
30
 
86
31
  expect_too_many_args(newnw, "uuid", 1)
87
32
 
88
- expect_success(newnw, "no args", "uuid") {|x| x == UUID}
33
+ expect_success(newnw, "no args", "uuid") {|x| x == $NWFILTER_UUID}
89
34
 
90
35
  newnw.undefine
91
36
 
92
37
  # TESTGROUP: nwfilter.xml_desc
93
- newnw = conn.define_nwfilter_xml(new_nwfilter_xml)
38
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
94
39
 
95
40
  expect_too_many_args(newnw, "xml_desc", 1, 2)
96
41
  expect_invalid_arg_type(newnw, "xml_desc", "foo")
@@ -100,7 +45,7 @@ expect_success(newnw, "no args", "xml_desc")
100
45
  newnw.undefine
101
46
 
102
47
  # TESTGROUP: nwfilter.free
103
- newnw = conn.define_nwfilter_xml(new_nwfilter_xml)
48
+ newnw = conn.define_nwfilter_xml($new_nwfilter_xml)
104
49
  newnw.undefine
105
50
  expect_too_many_args(newnw, "free", 1)
106
51