ruby-libvirt 0.4.0 → 0.5.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.
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Test the stream methods the bindings support
4
+
5
+ $: << File.dirname(__FILE__)
6
+
7
+ require 'libvirt'
8
+ require 'test_utils.rb'
9
+
10
+ set_test_object("stream")
11
+
12
+ conn = Libvirt::open("qemu:///system")
13
+
14
+ # TESTGROUP: stream.send
15
+ st = conn.stream
16
+
17
+ expect_too_many_args(st, "send", 1, 2)
18
+ expect_too_few_args(st, "send")
19
+ expect_invalid_arg_type(st, "send", 1)
20
+ expect_invalid_arg_type(st, "send", nil)
21
+ expect_invalid_arg_type(st, "send", [])
22
+ expect_invalid_arg_type(st, "send", {})
23
+
24
+ # FIXME: we need to setup a proper stream for this to work
25
+ #expect_success(st, "buffer arg", "send", buffer)
26
+
27
+ st.free
28
+
29
+ # TESTGROUP: stream.recv
30
+ st = conn.stream
31
+
32
+ expect_too_many_args(st, "recv", 1, 2)
33
+ expect_too_few_args(st, "recv")
34
+ expect_invalid_arg_type(st, "recv", nil)
35
+ expect_invalid_arg_type(st, "recv", 'foo')
36
+ expect_invalid_arg_type(st, "recv", [])
37
+ expect_invalid_arg_type(st, "recv", {})
38
+
39
+ # FIXME: we need to setup a proper stream for this to work
40
+ #expect_success(st, "bytes arg", "recv", 12)
41
+
42
+ st.free
43
+
44
+ # TESTGROUP: stream.sendall
45
+ st = conn.stream
46
+
47
+ # equivalent to expect_too_many_args
48
+ begin
49
+ st.sendall(1, 2) {|x,y| x = y}
50
+ rescue NoMethodError
51
+ puts_skipped "#{$test_object}.sendall does not exist"
52
+ rescue ArgumentError => e
53
+ puts_ok "#{$test_object}.sendall too many args threw #{ArgumentError.to_s}"
54
+ rescue => e
55
+ puts_fail "#{$test_object}.sendall too many args expected to throw #{ArgumentError.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}"
56
+ else
57
+ puts_fail "#{$test_object}.sendall too many args expected to throw #{ArgumentError.to_s}, but threw nothing"
58
+ end
59
+
60
+ expect_fail(st, RuntimeError, "no block given", "sendall")
61
+
62
+ # FIXME: we need to setup a proper stream for this to work
63
+ #st.sendall {|opaque,nbytes| return opaque}
64
+
65
+ st.free
66
+
67
+ # TESTGROUP: stream.recvall
68
+ st = conn.stream
69
+
70
+ # equivalent to expect_too_many_args
71
+ begin
72
+ st.recvall(1, 2) {|x,y| x = y}
73
+ rescue NoMethodError
74
+ puts_skipped "#{$test_object}.recvall does not exist"
75
+ rescue ArgumentError => e
76
+ puts_ok "#{$test_object}.recvall too many args threw #{ArgumentError.to_s}"
77
+ rescue => e
78
+ puts_fail "#{$test_object}.recvall too many args expected to throw #{ArgumentError.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}"
79
+ else
80
+ puts_fail "#{$test_object}.recvall too many args expected to throw #{ArgumentError.to_s}, but threw nothing"
81
+ end
82
+
83
+ expect_fail(st, RuntimeError, "no block given", "recvall")
84
+
85
+ # FIXME: we need to setup a proper stream for this to work
86
+ #st.recvall {|data,opaque| return opaque}
87
+
88
+ st.free
89
+
90
+ # TESTGROUP: stream.event_add_callback
91
+ st_event_callback_proc = lambda {|st,events,opaque|
92
+ }
93
+
94
+ st = conn.stream
95
+
96
+ expect_too_many_args(st, "event_add_callback", 1, 2, 3, 4)
97
+ expect_too_few_args(st, "event_add_callback")
98
+ expect_too_few_args(st, "event_add_callback", 1)
99
+ expect_invalid_arg_type(st, "event_add_callback", nil, st_event_callback_proc)
100
+ expect_invalid_arg_type(st, "event_add_callback", 'foo', st_event_callback_proc)
101
+ expect_invalid_arg_type(st, "event_add_callback", [], st_event_callback_proc)
102
+ expect_invalid_arg_type(st, "event_add_callback", {}, st_event_callback_proc)
103
+ expect_invalid_arg_type(st, "event_add_callback", 1, nil)
104
+ expect_invalid_arg_type(st, "event_add_callback", 1, 'foo')
105
+ expect_invalid_arg_type(st, "event_add_callback", 1, 1)
106
+ expect_invalid_arg_type(st, "event_add_callback", 1, [])
107
+ expect_invalid_arg_type(st, "event_add_callback", 1, {})
108
+
109
+ # FIXME: I get "this function is not support by the connection driver"
110
+ #expect_success(st, "events and callback arg", "event_add_callback", Libvirt::Stream::EVENT_READABLE, st_event_callback_proc)
111
+ #st.event_remove_callback
112
+
113
+ st.free
114
+
115
+ # TESTGROUP: stream.event_update_callback
116
+ st = conn.stream
117
+
118
+ expect_too_many_args(st, "event_update_callback", 1, 2)
119
+ expect_too_few_args(st, "event_update_callback")
120
+ expect_invalid_arg_type(st, "event_update_callback", nil)
121
+ expect_invalid_arg_type(st, "event_update_callback", 'foo')
122
+ expect_invalid_arg_type(st, "event_update_callback", [])
123
+ expect_invalid_arg_type(st, "event_update_callback", {})
124
+
125
+ # FIXME: we would need to get st.event_add_callback working to get this working
126
+ #expect_success(st, "events arg", "event_update_callback", Libvirt::Stream::EVENT_WRITABLE)
127
+
128
+ st.free
129
+
130
+ # TESTGROUP: stream.remove_callback
131
+ st = conn.stream
132
+
133
+ expect_too_many_args(st, "event_remove_callback", 1)
134
+
135
+ # FIXME: we would need to get st.event_add_callback working to get this working
136
+ #expect_success(st, "no arg", "event_remove_callback")
137
+
138
+ st.free
139
+
140
+ # TESTGROUP: stream.finish
141
+ st = conn.stream
142
+
143
+ expect_too_many_args(st, "finish", 1)
144
+
145
+ # FIXME: I get "this function is not support by the connection driver"
146
+ #expect_success(st, "no arg", "finish")
147
+
148
+ st.free
149
+
150
+ # TESTGROUP: stream.abort
151
+ st = conn.stream
152
+
153
+ expect_too_many_args(st, "abort", 1)
154
+
155
+ # FIXME: I get "this function is not support by the connection driver"
156
+ #expect_success(st, "no arg", "abort")
157
+
158
+ st.free
159
+
160
+ # TESTGROUP: stream.abort
161
+ st = conn.stream
162
+
163
+ expect_too_many_args(st, "free", 1)
164
+
165
+ expect_success(st, "no arg", "free")
166
+
167
+ # END TESTS
168
+
169
+ conn.close
170
+
171
+ finish_tests
data/tests/test_utils.rb CHANGED
@@ -2,12 +2,15 @@ $FAIL = 0
2
2
  $SUCCESS = 0
3
3
  $SKIPPED = 0
4
4
 
5
- $GUEST_DISK = '/var/lib/libvirt/images/ruby-libvirt-tester.qcow2'
5
+ $GUEST_BASE = '/var/lib/libvirt/images/ruby-libvirt-tester'
6
+ $GUEST_DISK = $GUEST_BASE + '.qcow2'
7
+ $GUEST_SAVE = $GUEST_BASE + '.save'
6
8
  $GUEST_UUID = "93a5c045-6457-2c09-e56f-927cdf34e17a"
7
9
 
8
10
  # XML data for later tests
9
11
  $new_dom_xml = <<EOF
10
12
  <domain type='kvm'>
13
+ <description>Ruby Libvirt Tester</description>
11
14
  <name>ruby-libvirt-tester</name>
12
15
  <uuid>#{$GUEST_UUID}</uuid>
13
16
  <memory>1048576</memory>
@@ -56,11 +59,14 @@ EOF
56
59
  # qemu command-line that roughly corresponds to the above XML
57
60
  $qemu_cmd_line = "/usr/bin/qemu-kvm -S -M pc-0.13 -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -name ruby-libvirt-tester -uuid #{$GUEST_UUID} -nodefconfig -nodefaults -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/ruby-libvirt-tester.monitor,server,nowait -mon chardev=monitor,mode=readline -rtc base=utc -boot c -chardev pty,id=serial0 -device isa-serial,chardev=serial0 -usb -vnc 127.0.0.1:0 -k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5"
58
61
 
62
+ $NEW_INTERFACE_MAC = 'aa:bb:cc:dd:ee:ff'
59
63
  $new_interface_xml = <<EOF
60
- <interface type="bridge" name="ruby-libvirt-tester">
64
+ <interface type="ethernet" name="ruby-libvirt-tester">
61
65
  <start mode="onboot"/>
62
- <bridge delay="0">
63
- </bridge>
66
+ <mac address="#{$NEW_INTERFACE_MAC}"/>
67
+ <protocol family='ipv4'>
68
+ <dhcp peerdns='yes'/>
69
+ </protocol>
64
70
  </interface>
65
71
  EOF
66
72
 
@@ -79,6 +85,10 @@ $new_net_xml = <<EOF
79
85
  </network>
80
86
  EOF
81
87
 
88
+ $new_network_dhcp_ip = <<EOF
89
+ <host mac='00:11:22:33:44:55' ip='192.168.134.5'/>
90
+ EOF
91
+
82
92
  $NWFILTER_UUID = "bd339530-134c-6d07-441a-17fb90dad807"
83
93
  $new_nwfilter_xml = <<EOF
84
94
  <filter name='ruby-libvirt-tester' chain='ipv4'>
@@ -115,36 +125,41 @@ $new_storage_pool_xml = <<EOF
115
125
  </pool>
116
126
  EOF
117
127
 
128
+ $test_object = "unknown"
129
+
130
+ def set_test_object(obj)
131
+ $test_object = obj
132
+ end
133
+
118
134
  def expect_success(object, msg, func, *args)
119
135
  begin
120
- x = object.send(func, *args)
136
+ x = object.__send__(func, *args)
121
137
  if block_given?
122
138
  res = yield x
123
139
  if not res
124
- # FIXME: generate a proper error here
125
- raise "Failed"
140
+ raise "block failed"
126
141
  end
127
142
  end
128
- puts_ok "#{func} #{msg} succeeded"
143
+ puts_ok "#{$test_object}.#{func} #{msg} succeeded"
129
144
  x
130
145
  rescue NoMethodError
131
- puts_skipped "#{func} does not exist"
146
+ puts_skipped "#{$test_object}.#{func} does not exist"
132
147
  rescue => e
133
- puts_fail "#{func} #{msg} expected to succeed, threw #{e.class.to_s}: #{e.to_s}"
148
+ puts_fail "#{$test_object}.#{func} #{msg} expected to succeed, threw #{e.class.to_s}: #{e.to_s}"
134
149
  end
135
150
  end
136
151
 
137
152
  def expect_fail(object, errtype, errmsg, func, *args)
138
153
  begin
139
- object.send(func, *args)
154
+ object.__send__(func, *args)
140
155
  rescue NoMethodError
141
- puts_skipped "#{func} does not exist"
156
+ puts_skipped "#{$test_object}.#{func} does not exist"
142
157
  rescue errtype => e
143
- puts_ok "#{func} #{errmsg} threw #{errtype.to_s}"
158
+ puts_ok "#{$test_object}.#{func} #{errmsg} threw #{errtype.to_s}"
144
159
  rescue => e
145
- puts_fail "#{func} #{errmsg} expected to throw #{errtype.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}"
160
+ puts_fail "#{$test_object}.#{func} #{errmsg} expected to throw #{errtype.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}"
146
161
  else
147
- puts_fail "#{func} #{errmsg} expected to throw #{errtype.to_s}, but threw nothing"
162
+ puts_fail "#{$test_object}.#{func} #{errmsg} expected to throw #{errtype.to_s}, but threw nothing"
148
163
  end
149
164
  end
150
165
 
@@ -178,3 +193,59 @@ end
178
193
  def finish_tests
179
194
  puts "Successfully finished #{$SUCCESS} tests, failed #{$FAIL} tests, skipped #{$SKIPPED} tests"
180
195
  end
196
+
197
+ def find_valid_iface(conn)
198
+ conn.list_interfaces.each do |ifname|
199
+ iface = conn.lookup_interface_by_name(ifname)
200
+ if iface.mac == "00:00:00:00:00:00"
201
+ next
202
+ end
203
+ return iface
204
+ end
205
+ return nil
206
+ end
207
+
208
+ def cleanup_test_domain(conn)
209
+ # cleanup from previous runs
210
+ begin
211
+ olddom = conn.lookup_domain_by_name("ruby-libvirt-tester")
212
+ rescue
213
+ # in case we didn't find it, don't do anything
214
+ end
215
+
216
+ begin
217
+ olddom.destroy
218
+ rescue
219
+ # in case we didn't destroy it, don't do anything
220
+ end
221
+
222
+ begin
223
+ olddom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
224
+ rescue
225
+ # in case we didn't undefine it, don't do anything
226
+ end
227
+
228
+ `rm -f #{$GUEST_DISK}`
229
+ `rm -f #{$GUEST_SAVE}`
230
+ end
231
+
232
+ def cleanup_test_network(conn)
233
+ # initial cleanup for previous run
234
+ begin
235
+ oldnet = conn.lookup_network_by_name("ruby-libvirt-tester")
236
+ rescue
237
+ # in case we didn't find it, don't do anything
238
+ end
239
+
240
+ begin
241
+ oldnet.destroy
242
+ rescue
243
+ # in case we didn't find it, don't do anything
244
+ end
245
+
246
+ begin
247
+ oldnet.undefine
248
+ rescue
249
+ # in case we didn't find it, don't do anything
250
+ end
251
+ end
metadata CHANGED
@@ -1,106 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-libvirt
3
- version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 4
9
- - 0
10
- version: 0.4.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - David Lutterkort, Chris Lalancette
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-07-29 00:00:00 -04:00
19
- default_executable:
11
+ date: 2013-12-10 00:00:00.000000000 Z
20
12
  dependencies: []
21
-
22
13
  description: Ruby bindings for libvirt.
23
14
  email: libvir-list@redhat.com
24
15
  executables: []
25
-
26
- extensions:
16
+ extensions:
27
17
  - ext/libvirt/extconf.rb
28
18
  extra_rdoc_files: []
29
-
30
- files:
19
+ files:
31
20
  - Rakefile
32
21
  - COPYING
33
22
  - README
34
23
  - NEWS
35
24
  - README.rdoc
36
25
  - lib/libvirt.rb
37
- - ext/libvirt/domain.h
38
- - ext/libvirt/domain.c
39
- - ext/libvirt/network.h
40
- - ext/libvirt/secret.c
41
- - ext/libvirt/secret.h
42
- - ext/libvirt/stream.h
43
- - ext/libvirt/storage.h
44
- - ext/libvirt/storage.c
45
26
  - ext/libvirt/_libvirt.c
46
- - ext/libvirt/interface.h
47
- - ext/libvirt/network.c
48
- - ext/libvirt/nwfilter.c
49
- - ext/libvirt/connect.h
27
+ - ext/libvirt/common.c
50
28
  - ext/libvirt/common.h
51
29
  - ext/libvirt/connect.c
52
- - ext/libvirt/common.c
30
+ - ext/libvirt/connect.h
31
+ - ext/libvirt/domain.c
32
+ - ext/libvirt/domain.h
53
33
  - ext/libvirt/interface.c
54
- - ext/libvirt/nodedevice.h
34
+ - ext/libvirt/interface.h
35
+ - ext/libvirt/network.c
36
+ - ext/libvirt/network.h
55
37
  - ext/libvirt/nodedevice.c
56
- - ext/libvirt/stream.c
38
+ - ext/libvirt/nodedevice.h
39
+ - ext/libvirt/nwfilter.c
57
40
  - ext/libvirt/nwfilter.h
41
+ - ext/libvirt/secret.c
42
+ - ext/libvirt/secret.h
43
+ - ext/libvirt/storage.c
44
+ - ext/libvirt/storage.h
45
+ - ext/libvirt/stream.c
46
+ - ext/libvirt/stream.h
58
47
  - ext/libvirt/extconf.rb
48
+ - tests/test_conn.rb
49
+ - tests/test_domain.rb
59
50
  - tests/test_interface.rb
60
51
  - tests/test_network.rb
52
+ - tests/test_nodedevice.rb
61
53
  - tests/test_nwfilter.rb
62
- - tests/test_utils.rb
63
- - tests/test_domain.rb
64
- - tests/test_storage.rb
65
54
  - tests/test_open.rb
66
55
  - tests/test_secret.rb
67
- - tests/test_conn.rb
68
- - tests/test_nodedevice.rb
69
- has_rdoc: true
56
+ - tests/test_storage.rb
57
+ - tests/test_stream.rb
58
+ - tests/test_utils.rb
70
59
  homepage: http://libvirt.org/ruby/
71
- licenses: []
72
-
60
+ licenses:
61
+ - LGPLv2
62
+ metadata: {}
73
63
  post_install_message:
74
64
  rdoc_options: []
75
-
76
- require_paths:
65
+ require_paths:
77
66
  - lib
78
- required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- hash: 53
84
- segments:
85
- - 1
86
- - 8
87
- - 1
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
88
71
  version: 1.8.1
89
- required_rubygems_version: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- hash: 3
95
- segments:
96
- - 0
97
- version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
98
77
  requirements: []
99
-
100
78
  rubyforge_project: None
101
- rubygems_version: 1.3.7
79
+ rubygems_version: 2.0.14
102
80
  signing_key:
103
- specification_version: 3
81
+ specification_version: 4
104
82
  summary: Ruby bindings for LIBVIRT
105
83
  test_files: []
106
-