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.
@@ -0,0 +1,73 @@
1
+ $FAIL = 0
2
+ $SUCCESS = 0
3
+ $SKIPPED = 0
4
+
5
+ def expect_success(object, msg, func, *args)
6
+ begin
7
+ x = object.send(func, *args)
8
+ if block_given?
9
+ res = yield x
10
+ if not res
11
+ # FIXME: generate a proper error here
12
+ raise "Failed"
13
+ end
14
+ end
15
+ puts "OK: #{func} #{msg} succeeded"
16
+ $SUCCESS = $SUCCESS + 1
17
+ x
18
+ rescue NoMethodError
19
+ puts "SKIPPED: #{func} does not exist"
20
+ $SKIPPED = $SKIPPED + 1
21
+ rescue => e
22
+ puts "FAIL: #{func} #{msg} expected to succeed, threw #{e.class.to_s}: #{e.to_s}"
23
+ $FAIL = $FAIL + 1
24
+ end
25
+ end
26
+
27
+ def expect_fail(object, errtype, errmsg, func, *args)
28
+ begin
29
+ object.send(func, *args)
30
+ rescue NoMethodError
31
+ puts "SKIPPED: #{func} does not exist"
32
+ rescue errtype => e
33
+ puts "OK: #{func} #{errmsg} threw #{errtype.to_s}"
34
+ $SUCCESS = $SUCCESS + 1
35
+ rescue => e
36
+ puts "FAIL: #{func} #{errmsg} expected to throw #{errtype.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}"
37
+ $FAIL = $FAIL + 1
38
+ else
39
+ puts "FAIL: #{func} #{errmsg} expected to throw #{errtype.to_s}, but threw nothing"
40
+ $FAIL = $FAIL + 1
41
+ end
42
+ end
43
+
44
+ def expect_too_many_args(object, func, *args)
45
+ expect_fail(object, ArgumentError, "too many args", func, *args)
46
+ end
47
+
48
+ def expect_too_few_args(object, func, *args)
49
+ expect_fail(object, ArgumentError, "too few args", func, *args)
50
+ end
51
+
52
+ def expect_invalid_arg_type(object, func, *args)
53
+ expect_fail(object, TypeError, "invalid arg type", func, *args)
54
+ end
55
+
56
+ def puts_ok(str)
57
+ puts "OK: " + str
58
+ $SUCCESS = $SUCCESS + 1
59
+ end
60
+
61
+ def puts_fail(str)
62
+ puts "FAIL: " + str
63
+ $FAIL = $FAIL + 1
64
+ end
65
+
66
+ def puts_skipped(str)
67
+ puts "SKIPPED: " + str
68
+ $SKIPPED = $SKIPPED + 1
69
+ end
70
+
71
+ def finish_tests
72
+ puts "Successfully finished #{$SUCCESS} tests, failed #{$FAIL} tests, skipped #{$SKIPPED} tests"
73
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-libvirt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Lutterkort, Chris Lalancette
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-05 00:00:00 -04:00
18
+ date: 2010-12-12 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -57,9 +57,8 @@ files:
57
57
  - ext/libvirt/interface.h
58
58
  - ext/libvirt/extconf.rb
59
59
  - tests/test_interface.rb
60
- - tests/tc_connect.rb
60
+ - tests/test_utils.rb
61
61
  - tests/test_network.rb
62
- - tests/node.xml
63
62
  - tests/test_domain.rb
64
63
  - tests/test_open.rb
65
64
  - tests/test_secret.rb
@@ -1,110 +0,0 @@
1
- <?xml version="1.0"?>
2
- <node>
3
- <!-- This file gives an example config for the mock 'test' backend
4
- driver to libvirt. This is intended to allow relible unit testing
5
- of applications using libvirt. To use this with virsh, run something
6
- like:
7
-
8
- virsh -connect test:////path/to/this/dir/testnode.xml nodeinfo
9
-
10
- -->
11
- <domain type="test">
12
- <name>fv0</name>
13
- <uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>
14
- <os>
15
- <type>hvm</type>
16
- <loader>/usr/lib/xen/boot/hvmloader</loader>
17
- <boot dev="hd"/>
18
- </os>
19
- <currentMemory>2097152</currentMemory>
20
- <memory>8388608</memory>
21
- <vcpu>2</vcpu>
22
- <on_poweroff>destroy</on_poweroff>
23
- <on_reboot>restart</on_reboot>
24
- <on_crash>restart</on_crash>
25
- <features>
26
- <pae/>
27
- <acpi/>
28
- <apic/>
29
- </features>
30
- <devices>
31
- <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
32
- <interface type="bridge">
33
- <source bridge="xenbr0"/>
34
- <mac address="00:16:3e:5d:c7:9e"/>
35
- <script path="vif-bridge"/>
36
- </interface>
37
- <disk type="file">
38
- <source file="/root/fv0"/>
39
- <target dev="hda"/>
40
- </disk>
41
- <disk type="file" device="cdrom">
42
- <source file="/root/fc5-x86_64-boot.iso"/>
43
- <target dev="hdc"/>
44
- <readonly/>
45
- </disk>
46
- <disk type="file" device="floppy">
47
- <source file="/root/fd.img"/>
48
- <target dev="fda"/>
49
- </disk>
50
- <graphics type="vnc" port="5904"/>
51
- </devices>
52
- </domain>
53
- <domain type="test">
54
- <name>fc4</name>
55
- <uuid>EF86180145B911CB88E3AFBFE5370493</uuid>
56
- <os>
57
- <type>xen</type>
58
- <kernel>/boot/vmlinuz-2.6.15-1.43_FC5guest</kernel>
59
- <initrd>/boot/initrd-2.6.15-1.43_FC5guest.img</initrd>
60
- <root>/dev/sda1</root>
61
- <cmdline> ro selinux=0 3</cmdline>
62
- </os>
63
- <memory>261072</memory>
64
- <currentMemory>131072</currentMemory>
65
- <vcpu>1</vcpu>
66
- <devices>
67
- <disk type="file">
68
- <source file="/u/fc4.img"/>
69
- <target dev="sda1"/>
70
- </disk>
71
- <interface type="bridge">
72
- <source bridge="xenbr0"/>
73
- <mac address="aa:00:00:00:00:11"/>
74
- <script path="/etc/xen/scripts/vif-bridge"/>
75
- </interface>
76
- <console tty="/dev/pts/5"/>
77
- </devices>
78
- </domain>
79
- <network>
80
- <name>private</name>
81
- <uuid>004b22212d78c30f5aa5f03c87d21e69</uuid>
82
- <bridge name="brpriv"/>
83
- <ip address="192.168.124.1" netmask="255.255.255.0">
84
- <dhcp>
85
- <range start="192.168.124.128" end="192.168.124.253"/>
86
- </dhcp>
87
- </ip>
88
- </network>
89
- <network>
90
- <name>default</name>
91
- <uuid>004b96e12d78c30f5aa5f03c87d21e69</uuid>
92
- <bridge name="brdefault"/>
93
- <forward dev="eth0"/>
94
- <ip address="192.168.122.1" netmask="255.255.255.0">
95
- <dhcp>
96
- <range start="192.168.122.128" end="192.168.122.253"/>
97
- </dhcp>
98
- </ip>
99
- </network>
100
- <cpu>
101
- <mhz>6000</mhz>
102
- <model>i986</model>
103
- <active>50</active>
104
- <nodes>4</nodes>
105
- <sockets>4</sockets>
106
- <cores>4</cores>
107
- <threads>2</threads>
108
- </cpu>
109
- <memory>8192000</memory>
110
- </node>
@@ -1,178 +0,0 @@
1
- require 'test/unit'
2
-
3
- $:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
4
- $:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "libvirt"))
5
- require 'libvirt'
6
-
7
- class TestConnect < Test::Unit::TestCase
8
-
9
- LIBVIRT_VERSION = Libvirt::version("Test")[0]
10
-
11
- TEST_CAPS_OLD = "<capabilities>\n <host>\n <cpu>\n <arch>i686</arch>\n <features>\n <pae/>\n <nonpae/>\n </features>\n </cpu>\n </host>\n\n <guest>\n <os_type>linux</os_type>\n <arch name=\"i686\">\n <wordsize>32</wordsize>\n <domain type=\"test\"/>\n </arch>\n <features>\n <pae/>\n <nonpae/>\n </features>\n </guest>\n</capabilities>\n"
12
-
13
- TEST_CAPS_0_40_1 = "<capabilities>\n\n <host>\n <cpu>\n <arch>i686</arch>\n <features>\n <pae/>\n <nonpae/>\n </features>\n </cpu>\n <topology>\n <cells num='2'>\n <cell id='0'>\n <cpus num='8'>\n <cpu id='0'>\n <cpu id='2'>\n <cpu id='4'>\n <cpu id='6'>\n <cpu id='8'>\n <cpu id='10'>\n <cpu id='12'>\n <cpu id='14'>\n </cpus>\n </cell>\n <cell id='1'>\n <cpus num='8'>\n <cpu id='1'>\n <cpu id='3'>\n <cpu id='5'>\n <cpu id='7'>\n <cpu id='9'>\n <cpu id='11'>\n <cpu id='13'>\n <cpu id='15'>\n </cpus>\n </cell>\n </cells>\n </topology>\n </host>\n\n <guest>\n <os_type>linux</os_type>\n <arch name='i686'>\n <wordsize>32</wordsize>\n <domain type='test'>\n </domain>\n </arch>\n <features>\n <pae/>\n <nonpae/>\n </features>\n </guest>\n\n</capabilities>\n"
14
-
15
- if LIBVIRT_VERSION.major >= 0 &&
16
- LIBVIRT_VERSION.minor >= 4 &&
17
- LIBVIRT_VERSION.release >= 1
18
- TEST_CAPS = TEST_CAPS_0_40_1
19
- else
20
- TEST_CAPS = TEST_CAPS_OLD
21
- end
22
-
23
- UUID = "4dea22b3-1d52-d8f3-2516-782e98ab3fa0"
24
-
25
- NETWORK_UUID = "004b96e1-2d78-c30f-5aa5-f03c87d21e69"
26
-
27
- NETWORK_XML = "<network>
28
- <name>local</name>
29
- <uuid>9b562b27-0969-4b39-8c96-ef7858152ccc</uuid>
30
- <bridge name='virbr0'/>
31
- <forward/>
32
- <ip address='172.31.122.1' netmask='255.255.255.0'>
33
- <dhcp>
34
- <range start='172.31.122.2' end='172.31.122.254'/>
35
- </dhcp>
36
- </ip>
37
- </network>
38
- "
39
-
40
- def test_url
41
- "test://" + File::join(File::expand_path(File::dirname(__FILE__)),
42
- "node.xml")
43
- end
44
-
45
- def connect
46
- c = Libvirt::open(test_url)
47
- assert_not_nil(c)
48
- assert(! c.closed?)
49
- return c
50
- end
51
-
52
- def test_open
53
- c = connect
54
- assert_nothing_raised {
55
- c.close
56
- }
57
- assert(c.closed?)
58
- assert_nothing_raised {
59
- c.close
60
- }
61
- assert(c.closed?)
62
- end
63
-
64
- def test_node_info
65
- ni = connect.node_get_info
66
- assert_equal(4, ni.nodes)
67
- assert_equal(50, ni.cpus)
68
- assert_equal(2, ni.threads)
69
- assert_equal(4, ni.sockets)
70
- assert_equal(6000, ni.mhz)
71
- assert_equal(4, ni.cores)
72
- assert_equal("i986", ni.model)
73
- end
74
-
75
- def test_misc
76
- c = connect
77
- assert_equal("Test", c.type)
78
- assert_equal(2, c.version)
79
- hostname=`hostname`.chomp
80
-
81
- assert_nothing_raised {
82
- c.lookup_network_by_name("default").create
83
- }
84
-
85
- assert_equal(hostname, c.hostname)
86
- assert_equal(test_url, c.uri)
87
- assert_equal(32, c.max_vcpus("bogus"))
88
- assert(c.capabilities.size > 0)
89
- assert_equal(2, c.num_of_domains)
90
- assert_equal([1, 2], c.list_domains.sort)
91
- assert_equal(0, c.num_of_defined_domains)
92
- assert_equal([], c.list_defined_domains)
93
- assert_equal(1, c.num_of_networks)
94
- assert_equal(["default"], c.list_networks)
95
- assert_equal(1, c.num_of_defined_networks)
96
- assert_equal(["private"], c.list_defined_networks)
97
-
98
- v = Libvirt::version("Test")
99
- assert_equal("libvirt", v[0].type)
100
- assert_equal("Test", v[1].type)
101
- end
102
-
103
- def test_domain
104
- c = connect
105
-
106
- dom = c.lookup_domain_by_id(1)
107
- assert_equal("fv0", dom.name)
108
- assert_equal("linux", dom.os_type)
109
- assert_equal(UUID, dom.uuid)
110
- assert_equal(UUID, c.lookup_domain_by_uuid(UUID).uuid)
111
- assert_equal(UUID, c.lookup_domain_by_name("fv0").uuid)
112
-
113
- info = dom.info
114
- assert_equal(8388608, info.max_mem)
115
- assert_equal(2097152, info.memory)
116
- assert_equal(2, info.nr_virt_cpu)
117
- assert_equal(Libvirt::Domain::RUNNING, info.state)
118
-
119
- dom.memory = info.memory/2
120
- dom.vcpus = 1
121
- info = dom.info
122
- assert_equal(2097152/2, info.memory)
123
- assert_equal(1, info.nr_virt_cpu)
124
-
125
- # pin_vcpu is not implemented in the test driver
126
- # enable this once it becomes available
127
- # dom.pin_vcpu(0,[0])
128
-
129
- dom.free()
130
- assert_raise ArgumentError do
131
- dom.name
132
- end
133
- end
134
-
135
- def test_error
136
- c = connect
137
- raised = false
138
- begin
139
- c.lookup_domain_by_id(42)
140
- rescue Libvirt::RetrieveError => e
141
- raised = true
142
- assert(e.message.size > 0)
143
- assert_equal("virDomainLookupByID", e.libvirt_function_name)
144
- assert_not_nil e.libvirt_message
145
- end
146
- assert(raised)
147
- end
148
-
149
- def test_network
150
- c = connect
151
-
152
- netw = c.lookup_network_by_name("default")
153
- assert_equal("default", netw.name)
154
- assert_equal("brdefault", netw.bridge_name)
155
- uuid = NETWORK_UUID
156
- assert_equal(uuid, netw.uuid)
157
- assert_equal(uuid, c.lookup_network_by_uuid(uuid).uuid)
158
- assert_equal(uuid, c.lookup_network_by_name("default").uuid)
159
- assert_equal(false, netw.autostart)
160
- netw.autostart = true
161
- assert_equal(true, netw.autostart)
162
- netw.autostart = false
163
- assert_equal(false, netw.autostart)
164
-
165
- netw = c.define_network_xml(NETWORK_XML)
166
- assert(netw.xml_desc.size > 0)
167
- assert_equal(c, netw.connection)
168
-
169
- netw.create
170
- assert_equal(1, c.num_of_networks)
171
- assert_equal(["local"], c.list_networks)
172
-
173
- netw.free
174
- assert_raise ArgumentError do
175
- netw.name
176
- end
177
- end
178
- end