ruby-libvirt-catphish 0.7.1

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(URI)
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 {|stream,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
@@ -0,0 +1,254 @@
1
+ $FAIL = 0
2
+ $SUCCESS = 0
3
+ $SKIPPED = 0
4
+
5
+ URI = ENV['RUBY_LIBVIRT_TEST_URI'] || "qemu:///system"
6
+
7
+ $GUEST_BASE = '/var/lib/libvirt/images/rb-libvirt-test'
8
+ $GUEST_DISK = $GUEST_BASE + '.qcow2'
9
+ $GUEST_SAVE = $GUEST_BASE + '.save'
10
+ $GUEST_UUID = "93a5c045-6457-2c09-e56f-927cdf34e17a"
11
+ $GUEST_RAW_DISK = $GUEST_BASE + '.raw'
12
+
13
+ # XML data for later tests
14
+ $new_dom_xml = <<EOF
15
+ <domain type='kvm'>
16
+ <description>Ruby Libvirt Tester</description>
17
+ <name>rb-libvirt-test</name>
18
+ <uuid>#{$GUEST_UUID}</uuid>
19
+ <memory>1048576</memory>
20
+ <currentMemory>1048576</currentMemory>
21
+ <vcpu>2</vcpu>
22
+ <os>
23
+ <type arch='x86_64'>hvm</type>
24
+ <boot dev='hd'/>
25
+ </os>
26
+ <features>
27
+ <acpi/>
28
+ <apic/>
29
+ <pae/>
30
+ </features>
31
+ <clock offset='utc'/>
32
+ <on_poweroff>destroy</on_poweroff>
33
+ <on_reboot>restart</on_reboot>
34
+ <on_crash>restart</on_crash>
35
+ <devices>
36
+ <disk type='file' device='disk'>
37
+ <driver name='qemu' type='qcow2'/>
38
+ <source file='#{$GUEST_DISK}'/>
39
+ <target dev='vda' bus='virtio'/>
40
+ </disk>
41
+ <interface type='bridge'>
42
+ <mac address='52:54:00:60:3c:95'/>
43
+ <source bridge='virbr0'/>
44
+ <model type='virtio'/>
45
+ <target dev='rl556'/>
46
+ </interface>
47
+ <serial type='pty'>
48
+ <target port='0'/>
49
+ </serial>
50
+ <console type='pty'>
51
+ <target port='0'/>
52
+ </console>
53
+ <input type='mouse' bus='ps2'/>
54
+ <graphics type='vnc' port='-1' autoport='yes' keymap='en-us'/>
55
+ <video>
56
+ <model type='cirrus' vram='9216' heads='1'/>
57
+ </video>
58
+ </devices>
59
+ </domain>
60
+ EOF
61
+
62
+ # qemu command-line that roughly corresponds to the above XML
63
+ $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 rb-libvirt-test -uuid #{$GUEST_UUID} -nodefconfig -nodefaults -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/rb-libvirt-test.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"
64
+
65
+ $NEW_INTERFACE_MAC = 'aa:bb:cc:dd:ee:ff'
66
+ $new_interface_xml = <<EOF
67
+ <interface type="ethernet" name="rb-libvirt-test">
68
+ <start mode="onboot"/>
69
+ <mac address="#{$NEW_INTERFACE_MAC}"/>
70
+ <protocol family='ipv4'>
71
+ <dhcp peerdns='yes'/>
72
+ </protocol>
73
+ </interface>
74
+ EOF
75
+
76
+ $NETWORK_UUID = "04068860-d9a2-47c5-bc9d-9e047ae901da"
77
+ $new_net_xml = <<EOF
78
+ <network>
79
+ <name>rb-libvirt-test</name>
80
+ <uuid>#{$NETWORK_UUID}</uuid>
81
+ <forward mode='nat'/>
82
+ <bridge name='rubybr0' stp='on' delay='0' />
83
+ <ip address='192.168.134.1' netmask='255.255.255.0'>
84
+ <dhcp>
85
+ <range start='192.168.134.2' end='192.168.134.254' />
86
+ </dhcp>
87
+ </ip>
88
+ </network>
89
+ EOF
90
+
91
+ $new_network_dhcp_ip = <<EOF
92
+ <host mac='00:11:22:33:44:55' ip='192.168.134.5'/>
93
+ EOF
94
+
95
+ $NWFILTER_UUID = "bd339530-134c-6d07-441a-17fb90dad807"
96
+ $new_nwfilter_xml = <<EOF
97
+ <filter name='rb-libvirt-test' chain='ipv4'>
98
+ <uuid>#{$NWFILTER_UUID}</uuid>
99
+ <rule action='accept' direction='out' priority='100'>
100
+ <ip srcipaddr='0.0.0.0' dstipaddr='255.255.255.255' protocol='tcp' srcportstart='63000' dstportstart='62000'/>
101
+ </rule>
102
+ <rule action='accept' direction='in' priority='100'>
103
+ <ip protocol='tcp' srcportstart='63000' dstportstart='62000'/>
104
+ </rule>
105
+ </filter>
106
+ EOF
107
+
108
+ $SECRET_UUID = "bd339530-134c-6d07-4410-17fb90dad805"
109
+ $new_secret_xml = <<EOF
110
+ <secret ephemeral='no' private='no'>
111
+ <description>test secret</description>
112
+ <uuid>#{$SECRET_UUID}</uuid>
113
+ <usage type='volume'>
114
+ <volume>/var/lib/libvirt/images/mail.img</volume>
115
+ </usage>
116
+ </secret>
117
+ EOF
118
+
119
+ $POOL_UUID = "33a5c045-645a-2c00-e56b-927cdf34e17a"
120
+ $POOL_PATH = "/var/lib/libvirt/images/rb-libvirt-test"
121
+ $new_storage_pool_xml = <<EOF
122
+ <pool type="dir">
123
+ <name>rb-libvirt-test</name>
124
+ <uuid>#{$POOL_UUID}</uuid>
125
+ <target>
126
+ <path>#{$POOL_PATH}</path>
127
+ </target>
128
+ </pool>
129
+ EOF
130
+
131
+ $test_object = "unknown"
132
+
133
+ def set_test_object(obj)
134
+ $test_object = obj
135
+ end
136
+
137
+ def expect_success(object, msg, func, *args)
138
+ begin
139
+ x = object.__send__(func, *args)
140
+ if block_given?
141
+ res = yield x
142
+ if not res
143
+ raise "block failed"
144
+ end
145
+ end
146
+ puts_ok "#{$test_object}.#{func} #{msg} succeeded"
147
+ x
148
+ rescue NoMethodError
149
+ puts_skipped "#{$test_object}.#{func} does not exist"
150
+ rescue => e
151
+ puts_fail "#{$test_object}.#{func} #{msg} expected to succeed, threw #{e.class.to_s}: #{e.to_s}"
152
+ end
153
+ end
154
+
155
+ def expect_fail(object, errtype, errmsg, func, *args)
156
+ begin
157
+ object.__send__(func, *args)
158
+ rescue NoMethodError
159
+ puts_skipped "#{$test_object}.#{func} does not exist"
160
+ rescue errtype => e
161
+ puts_ok "#{$test_object}.#{func} #{errmsg} threw #{errtype.to_s}"
162
+ rescue => e
163
+ puts_fail "#{$test_object}.#{func} #{errmsg} expected to throw #{errtype.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}"
164
+ else
165
+ puts_fail "#{$test_object}.#{func} #{errmsg} expected to throw #{errtype.to_s}, but threw nothing"
166
+ end
167
+ end
168
+
169
+ def expect_too_many_args(object, func, *args)
170
+ expect_fail(object, ArgumentError, "too many args", func, *args)
171
+ end
172
+
173
+ def expect_too_few_args(object, func, *args)
174
+ expect_fail(object, ArgumentError, "too few args", func, *args)
175
+ end
176
+
177
+ def expect_invalid_arg_type(object, func, *args)
178
+ expect_fail(object, TypeError, "invalid arg type", func, *args)
179
+ end
180
+
181
+ def puts_ok(str)
182
+ puts "OK: " + str
183
+ $SUCCESS = $SUCCESS + 1
184
+ end
185
+
186
+ def puts_fail(str)
187
+ puts "FAIL: " + str
188
+ $FAIL = $FAIL + 1
189
+ end
190
+
191
+ def puts_skipped(str)
192
+ puts "SKIPPED: " + str
193
+ $SKIPPED = $SKIPPED + 1
194
+ end
195
+
196
+ def finish_tests
197
+ puts "Successfully finished #{$SUCCESS} tests, failed #{$FAIL} tests, skipped #{$SKIPPED} tests"
198
+ end
199
+
200
+ def find_valid_iface(conn)
201
+ conn.list_interfaces.each do |ifname|
202
+ iface = conn.lookup_interface_by_name(ifname)
203
+ if iface.mac == "00:00:00:00:00:00"
204
+ next
205
+ end
206
+ return iface
207
+ end
208
+ return nil
209
+ end
210
+
211
+ def cleanup_test_domain(conn)
212
+ # cleanup from previous runs
213
+ begin
214
+ olddom = conn.lookup_domain_by_name("rb-libvirt-test")
215
+ rescue
216
+ # in case we didn't find it, don't do anything
217
+ end
218
+
219
+ begin
220
+ olddom.destroy
221
+ rescue
222
+ # in case we didn't destroy it, don't do anything
223
+ end
224
+
225
+ begin
226
+ olddom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
227
+ rescue
228
+ # in case we didn't undefine it, don't do anything
229
+ end
230
+
231
+ `rm -f #{$GUEST_DISK}`
232
+ `rm -f #{$GUEST_SAVE}`
233
+ end
234
+
235
+ def cleanup_test_network(conn)
236
+ # initial cleanup for previous run
237
+ begin
238
+ oldnet = conn.lookup_network_by_name("rb-libvirt-test")
239
+ rescue
240
+ # in case we didn't find it, don't do anything
241
+ end
242
+
243
+ begin
244
+ oldnet.destroy
245
+ rescue
246
+ # in case we didn't find it, don't do anything
247
+ end
248
+
249
+ begin
250
+ oldnet.undefine
251
+ rescue
252
+ # in case we didn't find it, don't do anything
253
+ end
254
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-libvirt-catphish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.1
5
+ platform: ruby
6
+ authors:
7
+ - David Lutterkort, Chris Lalancette, Charlie Smurthwaite
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby bindings for libvirt.
14
+ email: libvir-list@redhat.com
15
+ executables: []
16
+ extensions:
17
+ - ext/libvirt/extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - COPYING
21
+ - NEWS
22
+ - README
23
+ - README.rdoc
24
+ - Rakefile
25
+ - ext/libvirt/_libvirt.c
26
+ - ext/libvirt/common.c
27
+ - ext/libvirt/common.h
28
+ - ext/libvirt/connect.c
29
+ - ext/libvirt/connect.h
30
+ - ext/libvirt/domain.c
31
+ - ext/libvirt/domain.h
32
+ - ext/libvirt/extconf.h
33
+ - ext/libvirt/extconf.rb
34
+ - ext/libvirt/interface.c
35
+ - ext/libvirt/interface.h
36
+ - ext/libvirt/network.c
37
+ - ext/libvirt/network.h
38
+ - ext/libvirt/nodedevice.c
39
+ - ext/libvirt/nodedevice.h
40
+ - ext/libvirt/nwfilter.c
41
+ - ext/libvirt/nwfilter.h
42
+ - ext/libvirt/secret.c
43
+ - ext/libvirt/secret.h
44
+ - ext/libvirt/storage.c
45
+ - ext/libvirt/storage.h
46
+ - ext/libvirt/stream.c
47
+ - ext/libvirt/stream.h
48
+ - lib/libvirt.rb
49
+ - tests/test_conn.rb
50
+ - tests/test_domain.rb
51
+ - tests/test_interface.rb
52
+ - tests/test_network.rb
53
+ - tests/test_nodedevice.rb
54
+ - tests/test_nwfilter.rb
55
+ - tests/test_open.rb
56
+ - tests/test_secret.rb
57
+ - tests/test_storage.rb
58
+ - tests/test_stream.rb
59
+ - tests/test_utils.rb
60
+ homepage: http://libvirt.org/ruby/
61
+ licenses:
62
+ - LGPLv2
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.8.1
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project: None
80
+ rubygems_version: 2.7.8
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Ruby bindings for LIBVIRT
84
+ test_files: []