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_conn.rb
CHANGED
@@ -2,52 +2,202 @@
|
|
2
2
|
|
3
3
|
# Test the conn methods the bindings support
|
4
4
|
|
5
|
+
$: << File.dirname(__FILE__)
|
6
|
+
|
5
7
|
require 'libvirt'
|
8
|
+
require 'test_utils.rb'
|
9
|
+
|
10
|
+
conn = Libvirt::open("qemu:///system")
|
11
|
+
|
12
|
+
cpu_xml = <<EOF
|
13
|
+
<cpu>
|
14
|
+
<arch>x86_64</arch>
|
15
|
+
<model>athlon</model>
|
16
|
+
</cpu>
|
17
|
+
EOF
|
18
|
+
|
19
|
+
# TESTGROUP: conn.close
|
20
|
+
conn2 = Libvirt::open("qemu:///system")
|
21
|
+
expect_too_many_args(conn2, "close", 1)
|
22
|
+
expect_success(conn2, "no args", "close")
|
23
|
+
|
24
|
+
# TESTGROUP: conn.closed?
|
25
|
+
conn2 = Libvirt::open("qemu:///system")
|
26
|
+
|
27
|
+
expect_too_many_args(conn2, "closed?", 1)
|
28
|
+
expect_success(conn2, "no args", "closed?") {|x| x == false }
|
29
|
+
conn2.close
|
30
|
+
expect_success(conn2, "no args", "closed?") {|x| x == true }
|
31
|
+
|
32
|
+
# TESTGROUP: conn.type
|
33
|
+
expect_too_many_args(conn, "type", 1)
|
34
|
+
|
35
|
+
expect_success(conn, "no args", "type") {|x| x == "QEMU"}
|
36
|
+
|
37
|
+
# TESTGROUP: conn.version
|
38
|
+
expect_too_many_args(conn, "version", 1)
|
39
|
+
|
40
|
+
expect_success(conn, "no args", "version")
|
41
|
+
|
42
|
+
# TESTGROUP: conn.libversion
|
43
|
+
expect_too_many_args(conn, "libversion", 1)
|
44
|
+
|
45
|
+
expect_success(conn, "no args", "libversion")
|
46
|
+
|
47
|
+
# TESTGROUP: conn.hostname
|
48
|
+
expect_too_many_args(conn, "hostname", 1)
|
6
49
|
|
7
|
-
conn
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
50
|
+
expect_success(conn, "no args", "hostname")
|
51
|
+
|
52
|
+
# TESTGROUP: conn.uri
|
53
|
+
expect_too_many_args(conn, "uri", 1)
|
54
|
+
|
55
|
+
expect_success(conn, "no args", "uri") {|x| x == "qemu:///system" }
|
56
|
+
|
57
|
+
# TESTGROUP: conn.max_vcpus
|
58
|
+
expect_too_many_args(conn, "max_vcpus", 'kvm', 1)
|
59
|
+
expect_fail(conn, Libvirt::RetrieveError, "invalid arg", "max_vcpus", "foo")
|
60
|
+
|
61
|
+
expect_success(conn, "no args", "max_vcpus")
|
62
|
+
expect_success(conn, "nil arg", "max_vcpus")
|
63
|
+
expect_success(conn, "kvm arg", "max_vcpus")
|
64
|
+
expect_success(conn, "qemu arg", "max_vcpus")
|
65
|
+
|
66
|
+
# TESTGROUP: conn.node_get_info
|
67
|
+
expect_too_many_args(conn, "node_get_info", 1)
|
68
|
+
|
69
|
+
expect_success(conn, "no args", "node_get_info")
|
70
|
+
|
71
|
+
begin
|
72
|
+
# TESTGROUP: conn.node_free_memory
|
73
|
+
expect_too_many_args(conn, "node_free_memory", 1)
|
74
|
+
|
75
|
+
conn.node_free_memory
|
76
|
+
puts_ok "conn.node_free_memory no args"
|
77
|
+
rescue Libvirt::RetrieveError
|
78
|
+
puts_skipped "conn.node_free_memory not supported on this host"
|
79
|
+
rescue NoMethodError
|
80
|
+
puts_skipped "conn.node_free_memory does not exist"
|
81
|
+
end
|
82
|
+
|
83
|
+
begin
|
84
|
+
# TESTGROUP: conn.node_cells_free_memory
|
85
|
+
expect_too_many_args(conn, "node_cells_free_memory", 1, 2, 3)
|
86
|
+
expect_invalid_arg_type(conn, "node_cells_free_memory", 'start')
|
87
|
+
expect_invalid_arg_type(conn, "node_cells_free_memory", 0, 'end')
|
88
|
+
|
89
|
+
cell_mem = conn.node_cells_free_memory
|
90
|
+
puts_ok "conn.node_cells_free_memory no args = "
|
91
|
+
cell_mem = conn.node_cells_free_memory(0)
|
92
|
+
puts_ok "conn.node_cells_free_memory(0) = "
|
93
|
+
cell_mem = conn.node_cells_free_memory(0, 1)
|
94
|
+
puts_ok "conn.node_cells_free_memory(0, 1) = "
|
95
|
+
rescue Libvirt::RetrieveError
|
96
|
+
puts_skipped "conn.node_cells_free_memory not supported on this host"
|
97
|
+
rescue NoMethodError
|
98
|
+
puts_skipped "conn.node_cells_free_memory does not exist"
|
23
99
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
100
|
+
|
101
|
+
# TESTGROUP: conn.node_get_security_model
|
102
|
+
expect_too_many_args(conn, "node_get_security_model", 1)
|
103
|
+
expect_success(conn, "no args", "node_get_security_model")
|
104
|
+
|
105
|
+
# TESTGROUP: conn.encrypted?
|
106
|
+
expect_too_many_args(conn, "encrypted?", 1)
|
107
|
+
expect_success(conn, "no args", "encrypted?")
|
108
|
+
|
109
|
+
# TESTGROUP: conn.secure?
|
110
|
+
expect_too_many_args(conn, "secure?", 1)
|
111
|
+
expect_success(conn, "no args", "secure?") {|x| x == true}
|
112
|
+
|
113
|
+
# TESTGROUP: conn.capabilities
|
114
|
+
expect_too_many_args(conn, "capabilities", 1)
|
115
|
+
expect_success(conn, "no args", "capabilities")
|
116
|
+
|
117
|
+
# TESTGROUP: conn.compare_cpu
|
118
|
+
expect_too_many_args(conn, "compare_cpu", 1, 2, 3)
|
119
|
+
expect_too_few_args(conn, "compare_cpu")
|
120
|
+
expect_invalid_arg_type(conn, "compare_cpu", 1)
|
121
|
+
expect_invalid_arg_type(conn, "compare_cpu", "hello", 'bar')
|
122
|
+
expect_fail(conn, Libvirt::RetrieveError, "invalid XML", "compare_cpu", "hello")
|
123
|
+
expect_success(conn, "CPU XML", "compare_cpu", cpu_xml)
|
124
|
+
|
125
|
+
# TESTGROUP: conn.baseline_cpu
|
126
|
+
expect_too_many_args(conn, "baseline_cpu", 1, 2, 3)
|
127
|
+
expect_too_few_args(conn, "baseline_cpu")
|
128
|
+
expect_invalid_arg_type(conn, "baseline_cpu", 1)
|
129
|
+
expect_invalid_arg_type(conn, "baseline_cpu", [], "foo")
|
130
|
+
expect_fail(conn, ArgumentError, "empty array", "baseline_cpu", [])
|
131
|
+
expect_success(conn, "CPU XML", "baseline_cpu", [cpu_xml])
|
132
|
+
|
133
|
+
# TESTGROUP: conn.domain_event_register_any
|
134
|
+
dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
|
135
|
+
}
|
136
|
+
|
137
|
+
def dom_event_callback_symbol(conn, dom, event, detail, opaque)
|
28
138
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
139
|
+
|
140
|
+
expect_too_many_args(conn, "domain_event_register_any", 1, 2, 3, 4, 5)
|
141
|
+
expect_too_few_args(conn, "domain_event_register_any")
|
142
|
+
expect_too_few_args(conn, "domain_event_register_any", 1)
|
143
|
+
expect_invalid_arg_type(conn, "domain_event_register_any", "hello", 1)
|
144
|
+
expect_invalid_arg_type(conn, "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, 1)
|
145
|
+
expect_invalid_arg_type(conn, "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, 1)
|
146
|
+
expect_fail(conn, ArgumentError, "invalid event ID", "domain_event_register_any", 456789, dom_event_callback_proc)
|
147
|
+
|
148
|
+
callbackID = expect_success(conn, "eventID and proc", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc)
|
149
|
+
conn.domain_event_deregister_any(callbackID)
|
150
|
+
|
151
|
+
callbackID = expect_success(conn, "eventID and symbol", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, :dom_event_callback_symbol)
|
152
|
+
conn.domain_event_deregister_any(callbackID)
|
153
|
+
|
154
|
+
callbackID = expect_success(conn, "eventID, proc, nil domain", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, nil)
|
155
|
+
conn.domain_event_deregister_any(callbackID)
|
156
|
+
|
157
|
+
callbackID = expect_success(conn, "eventID, proc, nil domain, opaque", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, nil, "opaque user data")
|
158
|
+
conn.domain_event_deregister_any(callbackID)
|
159
|
+
|
160
|
+
# TESTGROUP: conn.domain_event_deregister_any
|
161
|
+
dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
|
162
|
+
}
|
163
|
+
|
164
|
+
callbackID = conn.domain_event_register_any(Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc)
|
165
|
+
|
166
|
+
expect_too_many_args(conn, "domain_event_deregister_any", 1, 2)
|
167
|
+
expect_too_few_args(conn, "domain_event_deregister_any")
|
168
|
+
expect_invalid_arg_type(conn, "domain_event_deregister_any", "hello")
|
169
|
+
|
170
|
+
expect_success(conn, "callbackID", "domain_event_deregister_any", callbackID)
|
171
|
+
|
172
|
+
# TESTGROUP: conn.domain_event_register
|
173
|
+
dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
|
174
|
+
}
|
175
|
+
|
176
|
+
def dom_event_callback_symbol(conn, dom, event, detail, opaque)
|
33
177
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
178
|
+
|
179
|
+
expect_too_many_args(conn, "domain_event_register", 1, 2, 3)
|
180
|
+
expect_too_few_args(conn, "domain_event_register")
|
181
|
+
expect_invalid_arg_type(conn, "domain_event_register", "hello")
|
182
|
+
|
183
|
+
expect_success(conn, "proc", "domain_event_register", dom_event_callback_proc)
|
184
|
+
conn.domain_event_deregister
|
185
|
+
|
186
|
+
expect_success(conn, "symbol", "domain_event_register", :dom_event_callback_symbol)
|
187
|
+
conn.domain_event_deregister
|
188
|
+
|
189
|
+
expect_success(conn, "proc and opaque", "domain_event_register", dom_event_callback_proc, "opaque user data")
|
190
|
+
conn.domain_event_deregister
|
191
|
+
|
192
|
+
# TESTGROUP: conn.domain_event_deregister
|
193
|
+
dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
|
194
|
+
}
|
195
|
+
|
196
|
+
conn.domain_event_register(dom_event_callback_proc)
|
197
|
+
|
198
|
+
expect_too_many_args(conn, "domain_event_deregister", 1)
|
199
|
+
expect_success(conn, "no args", "domain_event_deregister")
|
200
|
+
|
52
201
|
conn.close
|
53
|
-
|
202
|
+
|
203
|
+
finish_tests
|
data/tests/test_domain.rb
CHANGED
@@ -1,20 +1,38 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
# Test the domain methods the bindings support
|
3
|
+
# Test the domain methods the bindings support. Note that this tester requires
|
4
|
+
# the qemu driver to be enabled and available for use.
|
5
|
+
|
6
|
+
# Note that the order of the TESTGROUPs below match the order that the
|
7
|
+
# functions are defined in the ext/libvirt/domain.c file
|
8
|
+
|
9
|
+
$: << File.dirname(__FILE__)
|
4
10
|
|
5
11
|
require 'libvirt'
|
12
|
+
require 'test_utils.rb'
|
13
|
+
|
14
|
+
GUEST_DISK = '/var/lib/libvirt/images/ruby-libvirt-tester.qcow2'
|
15
|
+
UUID = "93a5c045-6457-2c09-e56f-927cdf34e17a"
|
16
|
+
|
17
|
+
conn = Libvirt::open("qemu:///system")
|
6
18
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
19
|
+
# initial cleanup for previous runs
|
20
|
+
begin
|
21
|
+
olddom = conn.lookup_domain_by_name("ruby-libvirt-tester")
|
22
|
+
olddom.destroy
|
23
|
+
olddom.undefine
|
24
|
+
rescue
|
25
|
+
# in case we didn't find it, don't do anything
|
26
|
+
end
|
27
|
+
|
28
|
+
# XML data for later tests
|
11
29
|
new_dom_xml = <<EOF
|
12
30
|
<domain type='kvm'>
|
13
31
|
<name>ruby-libvirt-tester</name>
|
14
|
-
<uuid
|
32
|
+
<uuid>#{UUID}</uuid>
|
15
33
|
<memory>1048576</memory>
|
16
34
|
<currentMemory>1048576</currentMemory>
|
17
|
-
<vcpu>
|
35
|
+
<vcpu>2</vcpu>
|
18
36
|
<os>
|
19
37
|
<type arch='x86_64'>hvm</type>
|
20
38
|
<boot dev='hd'/>
|
@@ -29,15 +47,14 @@ new_dom_xml = <<EOF
|
|
29
47
|
<on_reboot>restart</on_reboot>
|
30
48
|
<on_crash>restart</on_crash>
|
31
49
|
<devices>
|
32
|
-
<emulator>/usr/libexec/qemu-kvm</emulator>
|
33
50
|
<disk type='file' device='disk'>
|
34
|
-
<driver name='qemu' type='
|
35
|
-
<source file='
|
51
|
+
<driver name='qemu' type='qcow2'/>
|
52
|
+
<source file='#{GUEST_DISK}'/>
|
36
53
|
<target dev='vda' bus='virtio'/>
|
37
54
|
</disk>
|
38
55
|
<interface type='bridge'>
|
39
56
|
<mac address='52:54:00:60:3c:95'/>
|
40
|
-
<source bridge='
|
57
|
+
<source bridge='virbr0'/>
|
41
58
|
<model type='virtio'/>
|
42
59
|
<target dev='rl556'/>
|
43
60
|
</interface>
|
@@ -56,110 +73,1058 @@ new_dom_xml = <<EOF
|
|
56
73
|
</domain>
|
57
74
|
EOF
|
58
75
|
|
76
|
+
# qemu command-line that roughly corresponds to the above XML
|
77
|
+
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 #{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"
|
78
|
+
|
79
|
+
# setup for later tests
|
80
|
+
`rm -f #{GUEST_DISK} ; qemu-img create -f qcow2 #{GUEST_DISK} 5G`
|
81
|
+
`rm -f /var/lib/libvirt/images/ruby-libvirt-test.save`
|
82
|
+
|
83
|
+
new_hostdev_xml = <<EOF
|
84
|
+
<hostdev mode='subsystem' type='pci' managed='yes'>
|
85
|
+
<source>
|
86
|
+
<address bus='0x45' slot='0x55' function='0x33'/>
|
87
|
+
</source>
|
88
|
+
</hostdev>
|
89
|
+
EOF
|
90
|
+
|
91
|
+
# start tests
|
92
|
+
|
93
|
+
# TESTGROUP: conn.num_of_domains
|
94
|
+
expect_too_many_args(conn, "num_of_domains", 1)
|
95
|
+
expect_success(conn, "no args", "num_of_domains")
|
96
|
+
|
97
|
+
# TESTGROUP: conn.list_domains
|
98
|
+
expect_too_many_args(conn, "list_domains", 1)
|
99
|
+
expect_success(conn, "no args", "list_domains")
|
100
|
+
|
101
|
+
# TESTGROUP: conn.num_of_defined_domains
|
102
|
+
expect_too_many_args(conn, "num_of_defined_domains", 1)
|
103
|
+
expect_success(conn, "no args", "num_of_defined_domains")
|
104
|
+
|
105
|
+
# TESTGROUP: conn.list_domains
|
106
|
+
expect_too_many_args(conn, "list_defined_domains", 1)
|
107
|
+
expect_success(conn, "no args", "list_defined_domains")
|
108
|
+
|
109
|
+
# TESTGROUP: conn.create_domain_linux
|
110
|
+
expect_too_many_args(conn, "create_domain_linux", new_dom_xml, 0, 1)
|
111
|
+
expect_too_few_args(conn, "create_domain_linux")
|
112
|
+
expect_invalid_arg_type(conn, "create_domain_linux", nil)
|
113
|
+
expect_invalid_arg_type(conn, "create_domain_linux", 1)
|
114
|
+
expect_invalid_arg_type(conn, "create_domain_linux", new_dom_xml, "foo")
|
115
|
+
expect_fail(conn, Libvirt::Error, "invalid xml", "create_domain_linux", "hello")
|
116
|
+
newdom = expect_success(conn, "domain xml", "create_domain_linux", new_dom_xml) {|x| x.class == Libvirt::Domain}
|
117
|
+
sleep 1
|
118
|
+
|
119
|
+
expect_fail(conn, Libvirt::Error, "already existing domain", "create_domain_linux", new_dom_xml)
|
120
|
+
|
121
|
+
newdom.destroy
|
122
|
+
|
123
|
+
# TESTGROUP: conn.create_domain_xml
|
124
|
+
expect_too_many_args(conn, "create_domain_xml", new_dom_xml, 0, 1)
|
125
|
+
expect_too_few_args(conn, "create_domain_xml")
|
126
|
+
expect_invalid_arg_type(conn, "create_domain_xml", nil)
|
127
|
+
expect_invalid_arg_type(conn, "create_domain_xml", 1)
|
128
|
+
expect_invalid_arg_type(conn, "create_domain_xml", new_dom_xml, "foo")
|
129
|
+
expect_fail(conn, Libvirt::Error, "invalid xml", "create_domain_xml", "hello")
|
130
|
+
newdom = expect_success(conn, "domain xml", "create_domain_xml", new_dom_xml) {|x| x.class == Libvirt::Domain}
|
131
|
+
sleep 1
|
132
|
+
|
133
|
+
expect_fail(conn, Libvirt::Error, "already existing domain", "create_domain_xml", new_dom_xml)
|
134
|
+
|
135
|
+
newdom.destroy
|
136
|
+
|
137
|
+
# TESTGROUP: conn.lookup_domain_by_name
|
138
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
139
|
+
sleep 1
|
140
|
+
|
141
|
+
expect_too_many_args(conn, "lookup_domain_by_name", 1, 2)
|
142
|
+
expect_too_few_args(conn, "lookup_domain_by_name")
|
143
|
+
expect_invalid_arg_type(conn, "lookup_domain_by_name", 1)
|
144
|
+
expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_domain_by_name", "foobarbazsucker")
|
145
|
+
|
146
|
+
expect_success(conn, "name arg for running domain", "lookup_domain_by_name", "ruby-libvirt-tester") {|x| x.name == "ruby-libvirt-tester"}
|
147
|
+
newdom.destroy
|
148
|
+
|
149
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
150
|
+
expect_success(conn, "name arg for defined domain", "lookup_domain_by_name", "ruby-libvirt-tester") {|x| x.name == "ruby-libvirt-tester"}
|
151
|
+
newdom.undefine
|
152
|
+
|
153
|
+
# TESTGROUP: conn.lookup_domain_by_id
|
154
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
155
|
+
sleep 1
|
156
|
+
|
157
|
+
expect_too_many_args(conn, "lookup_domain_by_id", 1, 2)
|
158
|
+
expect_too_few_args(conn, "lookup_domain_by_id")
|
159
|
+
expect_invalid_arg_type(conn, "lookup_domain_by_id", "foo")
|
160
|
+
expect_fail(conn, Libvirt::Error, "with negative value", "lookup_domain_by_id", -1)
|
161
|
+
|
162
|
+
expect_success(conn, "id arg for running domain", "lookup_domain_by_id", newdom.id)
|
163
|
+
newdom.destroy
|
164
|
+
|
165
|
+
# TESTGROUP: conn.lookup_domain_by_uuid
|
166
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
167
|
+
sleep 1
|
168
|
+
|
169
|
+
expect_too_many_args(conn, "lookup_domain_by_uuid", 1, 2)
|
170
|
+
expect_too_few_args(conn, "lookup_domain_by_uuid")
|
171
|
+
expect_invalid_arg_type(conn, "lookup_domain_by_uuid", 1)
|
172
|
+
expect_fail(conn, Libvirt::RetrieveError, "invalid UUID", "lookup_domain_by_uuid", "abcd")
|
173
|
+
|
174
|
+
expect_success(conn, "UUID arg for running domain", "lookup_domain_by_uuid", newdom.uuid) {|x| x.uuid == UUID}
|
175
|
+
newdom.destroy
|
176
|
+
|
177
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
178
|
+
expect_success(conn, "UUID arg for defined domain", "lookup_domain_by_uuid", newdom.uuid) {|x| x.uuid == UUID}
|
179
|
+
newdom.undefine
|
180
|
+
|
181
|
+
# TESTGROUP: conn.define_domain_xml
|
182
|
+
expect_too_many_args(conn, "define_domain_xml", 1, 2)
|
183
|
+
expect_too_few_args(conn, "define_domain_xml")
|
184
|
+
expect_invalid_arg_type(conn, "define_domain_xml", 1)
|
185
|
+
expect_invalid_arg_type(conn, "define_domain_xml", nil)
|
186
|
+
expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_domain_xml", "hello")
|
187
|
+
|
188
|
+
newdom = expect_success(conn, "domain xml arg", "define_domain_xml", new_dom_xml)
|
189
|
+
newdom.undefine
|
190
|
+
|
191
|
+
# TESTGROUP: conn.domain_xml_from_native
|
192
|
+
expect_too_many_args(conn, "domain_xml_from_native", 1, 2, 3, 4)
|
193
|
+
expect_too_few_args(conn, "domain_xml_from_native")
|
194
|
+
expect_too_few_args(conn, "domain_xml_from_native", 1)
|
195
|
+
expect_invalid_arg_type(conn, "domain_xml_from_native", 1, 2)
|
196
|
+
expect_invalid_arg_type(conn, "domain_xml_from_native", nil, 2)
|
197
|
+
expect_invalid_arg_type(conn, "domain_xml_from_native", "qemu-argv", 2)
|
198
|
+
expect_invalid_arg_type(conn, "domain_xml_from_native", "qemu-argv", nil)
|
199
|
+
expect_invalid_arg_type(conn, "domain_xml_from_native", "qemu-argv", "foo", "bar")
|
200
|
+
expect_fail(conn, Libvirt::Error, "unsupported first arg", "domain_xml_from_native", "foo", "bar")
|
201
|
+
|
202
|
+
expect_success(conn, "qemu-argv and qemu_cmd_line", "domain_xml_from_native", "qemu-argv", qemu_cmd_line)
|
203
|
+
|
204
|
+
# TESTGROUP: conn.domain_xml_to_native
|
205
|
+
expect_too_many_args(conn, "domain_xml_to_native", 1, 2, 3, 4)
|
206
|
+
expect_too_few_args(conn, "domain_xml_to_native")
|
207
|
+
expect_too_few_args(conn, "domain_xml_to_native", 1)
|
208
|
+
expect_invalid_arg_type(conn, "domain_xml_to_native", 1, 2)
|
209
|
+
expect_invalid_arg_type(conn, "domain_xml_to_native", nil, 2)
|
210
|
+
expect_invalid_arg_type(conn, "domain_xml_to_native", "qemu-argv", 2)
|
211
|
+
expect_invalid_arg_type(conn, "domain_xml_to_native", "qemu-argv", nil)
|
212
|
+
expect_invalid_arg_type(conn, "domain_xml_to_native", "qemu-argv", "foo", "bar")
|
213
|
+
expect_fail(conn, Libvirt::Error, "unsupported first arg", "domain_xml_to_native", "foo", "bar")
|
214
|
+
|
215
|
+
expect_success(conn, "qemu-argv and domain XML", "domain_xml_to_native", "qemu-argv", new_dom_xml)
|
216
|
+
|
217
|
+
# TESTGROUP: dom.migrate
|
218
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
219
|
+
sleep 1
|
220
|
+
|
221
|
+
dconn = Libvirt::open("qemu:///system")
|
222
|
+
|
223
|
+
expect_too_many_args(newdom, "migrate", 1, 2, 3, 4, 5, 6)
|
224
|
+
expect_too_few_args(newdom, "migrate")
|
225
|
+
expect_fail(newdom, ArgumentError, "invalid connection object", "migrate", "foo")
|
226
|
+
expect_invalid_arg_type(newdom, "migrate", dconn, 'foo')
|
227
|
+
expect_invalid_arg_type(newdom, "migrate", dconn, 0, 1)
|
228
|
+
expect_invalid_arg_type(newdom, "migrate", dconn, 0, 'foo', 1)
|
229
|
+
expect_invalid_arg_type(newdom, "migrate", dconn, 0, 'foo', 'bar', 'baz')
|
230
|
+
|
231
|
+
# FIXME: how can we make this work?
|
232
|
+
#expect_success(newdom, "conn arg", "migrate", dconn)
|
233
|
+
|
234
|
+
dconn.close
|
235
|
+
|
236
|
+
newdom.destroy
|
237
|
+
|
238
|
+
# TESTGROUP: dom.migrate_to_uri
|
239
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
240
|
+
sleep 1
|
241
|
+
|
242
|
+
expect_too_many_args(newdom, "migrate_to_uri", 1, 2, 3, 4, 5)
|
243
|
+
expect_too_few_args(newdom, "migrate_to_uri")
|
244
|
+
expect_invalid_arg_type(newdom, "migrate_to_uri", 1)
|
245
|
+
expect_invalid_arg_type(newdom, "migrate_to_uri", "qemu:///system", 'foo')
|
246
|
+
expect_invalid_arg_type(newdom, "migrate_to_uri", "qemu:///system", 0, 1)
|
247
|
+
expect_invalid_arg_type(newdom, "migrate_to_uri", "qemu:///system", 0, 'foo', 'bar')
|
248
|
+
|
249
|
+
#expect_success(newdom, "URI arg", "migrate_to_uri", "qemu://remote/system")
|
250
|
+
|
251
|
+
dconn.close
|
252
|
+
|
253
|
+
newdom.destroy
|
254
|
+
|
255
|
+
# TESTGROUP: dom.migrate_set_max_downtime
|
59
256
|
newdom = conn.define_domain_xml(new_dom_xml)
|
257
|
+
|
258
|
+
expect_too_many_args(newdom, "migrate_set_max_downtime", 1, 2, 3)
|
259
|
+
expect_too_few_args(newdom, "migrate_set_max_downtime")
|
260
|
+
expect_invalid_arg_type(newdom, "migrate_set_max_downtime", 'foo')
|
261
|
+
expect_invalid_arg_type(newdom, "migrate_set_max_downtime", 10, 'foo')
|
262
|
+
expect_fail(newdom, Libvirt::Error, "on off domain", "migrate_set_max_downtime", 10)
|
263
|
+
|
60
264
|
newdom.undefine
|
61
265
|
|
62
|
-
|
266
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
267
|
+
sleep 1
|
268
|
+
expect_fail(newdom, Libvirt::Error, "while no migration in progress", "migrate_set_max_downtime", 10)
|
63
269
|
|
64
|
-
newdom
|
65
|
-
|
66
|
-
|
67
|
-
|
270
|
+
#newdom.migrate_to_uri("qemu://remote/system")
|
271
|
+
#expect_success(newdom, "10 second downtime", "migrate_set_max_downtime", 10)
|
272
|
+
|
273
|
+
newdom.destroy
|
274
|
+
|
275
|
+
# TESTGROUP: dom.shutdown
|
276
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
277
|
+
sleep 1
|
278
|
+
|
279
|
+
expect_too_many_args(newdom, "shutdown", 1)
|
280
|
+
expect_success(newdom, "no args", "shutdown")
|
281
|
+
sleep 1
|
282
|
+
newdom.destroy
|
283
|
+
|
284
|
+
# TESTGROUP: dom.reboot
|
285
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
286
|
+
sleep 1
|
287
|
+
expect_too_many_args(newdom, "reboot", 1, 2)
|
288
|
+
expect_invalid_arg_type(newdom, "reboot", "hello")
|
289
|
+
|
290
|
+
# Qemu driver doesn't currently support reboot, so this is going to fail
|
291
|
+
begin
|
292
|
+
newdom.reboot
|
293
|
+
puts_ok "dom.reboot succeeded"
|
294
|
+
rescue Libvirt::Error => e
|
295
|
+
puts_skipped "dom.reboot not supported, skipped"
|
68
296
|
end
|
69
|
-
|
297
|
+
|
298
|
+
sleep 1
|
70
299
|
newdom.destroy
|
71
300
|
|
301
|
+
# TESTGROUP: dom.destroy
|
302
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
303
|
+
sleep 1
|
304
|
+
|
305
|
+
expect_too_many_args(newdom, "destroy", 1)
|
306
|
+
expect_success(newdom, "no args", "destroy")
|
307
|
+
|
308
|
+
# TESTGROUP: dom.suspend
|
309
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
310
|
+
sleep 1
|
311
|
+
|
312
|
+
expect_too_many_args(newdom, "suspend", 1)
|
313
|
+
expect_success(newdom, "no args", "suspend")
|
314
|
+
newdom.destroy
|
315
|
+
|
316
|
+
# TESTGROUP: dom.resume
|
317
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
318
|
+
sleep 1
|
319
|
+
|
320
|
+
expect_success(newdom, "no args running domain", "resume")
|
321
|
+
|
322
|
+
newdom.suspend
|
323
|
+
expect_too_many_args(newdom, "resume", 1)
|
324
|
+
expect_success(newdom, "no args suspended domain", "resume")
|
325
|
+
newdom.destroy
|
326
|
+
|
327
|
+
# TESTGROUP: dom.save
|
72
328
|
newdom = conn.define_domain_xml(new_dom_xml)
|
73
|
-
info = newdom.info
|
74
329
|
newdom.create
|
75
|
-
sleep
|
76
|
-
|
77
|
-
|
78
|
-
newdom
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
330
|
+
sleep 1
|
331
|
+
|
332
|
+
expect_too_many_args(newdom, "save", 1, 2)
|
333
|
+
expect_too_few_args(newdom, "save")
|
334
|
+
expect_invalid_arg_type(newdom, "save", 1)
|
335
|
+
expect_invalid_arg_type(newdom, "save", nil)
|
336
|
+
expect_fail(newdom, Libvirt::Error, "non-existent path", "save", "/this/path/does/not/exist")
|
337
|
+
|
338
|
+
expect_success(newdom, "path arg", "save", "/var/lib/libvirt/images/ruby-libvirt-test.save")
|
339
|
+
|
340
|
+
`rm -f /var/lib/libvirt/images/ruby-libvirt-test.save`
|
341
|
+
newdom.undefine
|
342
|
+
|
343
|
+
# TESTGROUP: dom.managed_save
|
344
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
345
|
+
newdom.create
|
346
|
+
sleep 1
|
347
|
+
|
348
|
+
expect_too_many_args(newdom, "managed_save", 1, 2)
|
349
|
+
expect_invalid_arg_type(newdom, "managed_save", "hello")
|
350
|
+
expect_success(newdom, "no args", "managed_save")
|
351
|
+
newdom.undefine
|
352
|
+
|
353
|
+
# TESTGROUP: dom.has_managed_save?
|
354
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
355
|
+
newdom.create
|
356
|
+
sleep 1
|
357
|
+
|
358
|
+
expect_too_many_args(newdom, "has_managed_save?", 1, 2)
|
359
|
+
expect_invalid_arg_type(newdom, "has_managed_save?", "hello")
|
360
|
+
|
361
|
+
if newdom.has_managed_save?
|
362
|
+
puts_fail "dom.has_managed_save? reports true on a new domain"
|
363
|
+
else
|
364
|
+
puts_ok "dom.has_managed_save? not true on new domain"
|
365
|
+
end
|
366
|
+
|
367
|
+
newdom.managed_save
|
368
|
+
|
369
|
+
if not newdom.has_managed_save?
|
370
|
+
puts_fail "dom.has_managed_save? reports false after a managed save"
|
371
|
+
else
|
372
|
+
puts_ok "dom.has_managed_save? reports true after a managed save"
|
373
|
+
end
|
374
|
+
|
375
|
+
newdom.undefine
|
376
|
+
|
377
|
+
# TESTGROUP: dom.managed_save_remove
|
378
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
379
|
+
newdom.create
|
380
|
+
sleep 1
|
381
|
+
newdom.managed_save
|
382
|
+
|
383
|
+
expect_too_many_args(newdom, "managed_save_remove", 1, 2)
|
384
|
+
expect_invalid_arg_type(newdom, "managed_save_remove", "hello")
|
385
|
+
|
386
|
+
if not newdom.has_managed_save?
|
387
|
+
puts_fail "prior to dom.managed_save_remove, no managed save file"
|
388
|
+
end
|
389
|
+
expect_success(newdom, "no args", "managed_save_remove")
|
390
|
+
if newdom.has_managed_save?
|
391
|
+
puts_fail "after dom.managed_save_remove, managed save file still exists"
|
392
|
+
else
|
393
|
+
puts_ok "after dom.managed_save_remove, managed save file no longer exists"
|
394
|
+
end
|
395
|
+
|
396
|
+
newdom.undefine
|
397
|
+
|
398
|
+
# TESTGROUP: dom.core_dump
|
399
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
400
|
+
newdom.create
|
401
|
+
sleep 1
|
402
|
+
|
403
|
+
expect_too_many_args(newdom, "core_dump", 1, 2, 3)
|
404
|
+
expect_too_few_args(newdom, "core_dump")
|
405
|
+
expect_invalid_arg_type(newdom, "core_dump", 1, 2)
|
406
|
+
expect_invalid_arg_type(newdom, "core_dump", "/path", "foo")
|
407
|
+
expect_fail(newdom, Libvirt::Error, "invalid path", "core_dump", "/this/path/does/not/exist")
|
408
|
+
|
409
|
+
expect_success(newdom, "live with path arg", "core_dump", "/var/lib/libvirt/images/ruby-libvirt-test.core")
|
410
|
+
|
411
|
+
`rm -f /var/lib/libvirt/images/ruby-libvirt-test.core`
|
412
|
+
|
413
|
+
expect_success(newdom, "crash with path arg", "core_dump", "/var/lib/libvirt/images/ruby-libvirt-test.core", Libvirt::Domain::DUMP_CRASH)
|
414
|
+
|
415
|
+
expect_fail(newdom, Libvirt::Error, "of shut-off domain", "core_dump", "/var/lib/libvirt/images/ruby-libvirt-test.core", Libvirt::Domain::DUMP_CRASH)
|
416
|
+
|
417
|
+
`rm -f /var/lib/libvirt/images/ruby-libvirt-test.core`
|
418
|
+
|
419
|
+
newdom.undefine
|
420
|
+
|
421
|
+
# TESTGROUP: Libvirt::Domain::restore
|
422
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
423
|
+
newdom.create
|
424
|
+
sleep 1
|
425
|
+
newdom.save("/var/lib/libvirt/images/ruby-libvirt-test.save")
|
426
|
+
|
427
|
+
expect_too_many_args(Libvirt::Domain, "restore", 1, 2, 3)
|
428
|
+
expect_too_few_args(Libvirt::Domain, "restore")
|
429
|
+
expect_invalid_arg_type(Libvirt::Domain, "restore", 1, 2)
|
430
|
+
expect_invalid_arg_type(Libvirt::Domain, "restore", conn, 2)
|
431
|
+
expect_fail(Libvirt::Domain, Libvirt::Error, "invalid path", "restore", conn, "/this/path/does/not/exist")
|
432
|
+
`touch /tmp/foo`
|
433
|
+
expect_fail(Libvirt::Domain, Libvirt::Error, "invalid save file", "restore", conn, "/tmp/foo")
|
434
|
+
`rm -f /tmp/foo`
|
435
|
+
|
436
|
+
expect_success(Libvirt::Domain, "2 args", "restore", conn, "/var/lib/libvirt/images/ruby-libvirt-test.save")
|
437
|
+
|
438
|
+
`rm -f /var/lib/libvirt/images/ruby-libvirt-test.save`
|
439
|
+
|
440
|
+
newdom.destroy
|
441
|
+
newdom.undefine
|
442
|
+
|
443
|
+
# TESTGROUP: dom.info
|
444
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
445
|
+
sleep 1
|
446
|
+
|
447
|
+
expect_too_many_args(newdom, "info", 1)
|
448
|
+
|
449
|
+
expect_success(newdom, "no args", "info") {|x| x.state == Libvirt::Domain::RUNNING and x.max_mem == 1048576 and x.memory == 1048576 and x.nr_virt_cpu == 2}
|
450
|
+
|
451
|
+
newdom.destroy
|
452
|
+
|
453
|
+
# TESTGROUP: dom.security_label
|
454
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
455
|
+
sleep 1
|
456
|
+
|
457
|
+
expect_too_many_args(newdom, "security_label", 1)
|
458
|
+
|
459
|
+
expect_success(newdom, "no args", "security_label")
|
460
|
+
|
461
|
+
newdom.destroy
|
462
|
+
|
463
|
+
# TESTGROUP: dom.block_stats
|
464
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
465
|
+
sleep 1
|
466
|
+
|
467
|
+
expect_too_many_args(newdom, "block_stats", 1, 2)
|
468
|
+
expect_too_few_args(newdom, "block_stats")
|
469
|
+
expect_invalid_arg_type(newdom, "block_stats", 1)
|
470
|
+
expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "block_stats", "foo")
|
471
|
+
|
472
|
+
expect_success(newdom, "block device arg", "block_stats", "vda")
|
473
|
+
|
474
|
+
newdom.destroy
|
475
|
+
|
476
|
+
# TESTGROUP: dom.memory_stats
|
477
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
478
|
+
sleep 1
|
479
|
+
|
480
|
+
expect_too_many_args(newdom, "memory_stats", 1, 2)
|
481
|
+
expect_invalid_arg_type(newdom, "memory_stats", "foo")
|
482
|
+
|
483
|
+
expect_success(newdom, "no args", "memory_stats")
|
484
|
+
|
485
|
+
newdom.destroy
|
486
|
+
|
487
|
+
# TESTGROUP: dom.blockinfo
|
488
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
489
|
+
sleep 1
|
490
|
+
|
491
|
+
expect_too_many_args(newdom, "blockinfo", 1, 2, 3)
|
492
|
+
expect_too_few_args(newdom, "blockinfo")
|
493
|
+
expect_invalid_arg_type(newdom, "blockinfo", 1)
|
494
|
+
expect_invalid_arg_type(newdom, "blockinfo", "foo", "bar")
|
495
|
+
expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "blockinfo", "foo")
|
496
|
+
|
497
|
+
expect_success(newdom, "path arg", "blockinfo", GUEST_DISK)
|
498
|
+
|
499
|
+
newdom.destroy
|
500
|
+
|
501
|
+
# TESTGROUP: dom.block_peek
|
502
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
503
|
+
sleep 1
|
504
|
+
|
505
|
+
expect_too_many_args(newdom, "block_peek", 1, 2, 3, 4, 5)
|
506
|
+
expect_too_few_args(newdom, "block_peek")
|
507
|
+
expect_too_few_args(newdom, "block_peek", 1)
|
508
|
+
expect_too_few_args(newdom, "block_peek", 1, 2)
|
509
|
+
expect_invalid_arg_type(newdom, "block_peek", 1, 2, 3)
|
510
|
+
expect_invalid_arg_type(newdom, "block_peek", "foo", "bar", 3)
|
511
|
+
expect_invalid_arg_type(newdom, "block_peek", "foo", 0, "bar")
|
512
|
+
expect_invalid_arg_type(newdom, "block_peek", "foo", 0, 512, "baz")
|
513
|
+
expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "block_peek", "foo", 0, 512)
|
514
|
+
|
515
|
+
blockpeek = newdom.block_peek(GUEST_DISK, 0, 512)
|
516
|
+
|
517
|
+
# 51 46 49 fb are the first 4 bytes of a qcow2 image
|
518
|
+
if blockpeek[0] != 0x51 or blockpeek[1] != 0x46 or blockpeek[2] != 0x49 or
|
519
|
+
blockpeek[3] != 0xfb
|
520
|
+
puts_fail "dom.block_peek read did not return valid data"
|
521
|
+
else
|
522
|
+
puts_ok "dom.block_peek read valid data"
|
523
|
+
end
|
524
|
+
|
525
|
+
newdom.destroy
|
526
|
+
|
527
|
+
# TESTGROUP: dom.memory_peek
|
528
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
529
|
+
sleep 1
|
530
|
+
|
531
|
+
expect_too_many_args(newdom, "memory_peek", 1, 2, 3, 4)
|
532
|
+
expect_too_few_args(newdom, "memory_peek")
|
533
|
+
expect_too_few_args(newdom, "memory_peek", 1)
|
534
|
+
expect_invalid_arg_type(newdom, "memory_peek", "foo", 2)
|
535
|
+
expect_invalid_arg_type(newdom, "memory_peek", 0, "bar")
|
536
|
+
expect_invalid_arg_type(newdom, "memory_peek", 0, 512, "baz")
|
537
|
+
|
538
|
+
expect_success(newdom, "offset and size args", "memory_peek", 0, 512)
|
539
|
+
puts_ok "dom.memory_peek succeeded"
|
540
|
+
|
541
|
+
newdom.destroy
|
542
|
+
|
543
|
+
# TESTGROUP: dom.get_vcpus
|
544
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
545
|
+
sleep 1
|
546
|
+
|
547
|
+
expect_too_many_args(newdom, "get_vcpus", 1)
|
548
|
+
|
549
|
+
expect_success(newdom, "no args", "get_vcpus") {|x| x.length == 2}
|
550
|
+
|
551
|
+
newdom.destroy
|
552
|
+
|
553
|
+
# TESTGROUP: dom.active?
|
554
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
555
|
+
sleep 1
|
556
|
+
|
557
|
+
expect_too_many_args(newdom, "active?", 1)
|
558
|
+
|
559
|
+
expect_success(newdom, "no args", "active?") {|x| x == true}
|
560
|
+
|
561
|
+
newdom.destroy
|
562
|
+
|
563
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
564
|
+
|
565
|
+
expect_success(newdom, "no args", "active?") {|x| x == false}
|
566
|
+
|
567
|
+
newdom.create
|
568
|
+
sleep 1
|
569
|
+
|
570
|
+
expect_success(newdom, "no args", "active?") {|x| x == true}
|
571
|
+
|
572
|
+
newdom.destroy
|
573
|
+
newdom.undefine
|
574
|
+
|
575
|
+
# TESTGROUP: dom.persistent?
|
576
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
577
|
+
sleep 1
|
578
|
+
|
579
|
+
expect_too_many_args(newdom, "persistent?", 1)
|
580
|
+
|
581
|
+
expect_success(newdom, "no args", "persistent?") {|x| x == false}
|
582
|
+
|
583
|
+
newdom.destroy
|
584
|
+
|
585
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
586
|
+
|
587
|
+
expect_success(newdom, "no args", "persistent?") {|x| x == true}
|
588
|
+
|
589
|
+
newdom.undefine
|
590
|
+
|
591
|
+
# TESTGROUP: dom.ifinfo
|
592
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
593
|
+
sleep 1
|
594
|
+
|
595
|
+
expect_too_many_args(newdom, "ifinfo", 1, 2)
|
596
|
+
expect_too_few_args(newdom, "ifinfo")
|
597
|
+
expect_invalid_arg_type(newdom, "ifinfo", 1)
|
598
|
+
expect_fail(newdom, Libvirt::RetrieveError, "invalid arg", "ifinfo", "foo")
|
599
|
+
|
600
|
+
expect_success(newdom, "interface arg", "ifinfo", "rl556")
|
601
|
+
|
602
|
+
newdom.destroy
|
603
|
+
|
604
|
+
# TESTGROUP: dom.name
|
605
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
606
|
+
sleep 1
|
607
|
+
|
608
|
+
expect_too_many_args(newdom, "name", 1)
|
609
|
+
|
610
|
+
expect_success(newdom, "no args", "name") {|x| x == "ruby-libvirt-tester"}
|
611
|
+
|
612
|
+
newdom.destroy
|
613
|
+
|
614
|
+
# TESTGROUP: dom.id
|
615
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
616
|
+
sleep 1
|
617
|
+
|
618
|
+
expect_too_many_args(newdom, "id", 1)
|
619
|
+
|
620
|
+
expect_success(newdom, "no args", "id")
|
621
|
+
|
622
|
+
newdom.destroy
|
623
|
+
|
624
|
+
# TESTGROUP: dom.uuid
|
625
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
626
|
+
sleep 1
|
627
|
+
|
628
|
+
expect_too_many_args(newdom, "uuid", 1)
|
629
|
+
|
630
|
+
expect_success(newdom, "no args", "uuid") {|x| x == UUID}
|
631
|
+
|
632
|
+
newdom.destroy
|
633
|
+
|
634
|
+
# TESTGROUP: dom.os_type
|
635
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
636
|
+
sleep 1
|
637
|
+
|
638
|
+
expect_too_many_args(newdom, "os_type", 1)
|
639
|
+
|
640
|
+
expect_success(newdom, "no args", "os_type") {|x| x == "hvm"}
|
641
|
+
|
642
|
+
newdom.destroy
|
643
|
+
|
644
|
+
# TESTGROUP: dom.max_memory
|
645
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
646
|
+
sleep 1
|
647
|
+
|
648
|
+
expect_too_many_args(newdom, "max_memory", 1)
|
649
|
+
|
650
|
+
expect_success(newdom, "no args", "max_memory") {|x| x == 1048576}
|
651
|
+
|
652
|
+
newdom.destroy
|
653
|
+
|
654
|
+
# TESTGROUP: dom.max_memory=
|
655
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
656
|
+
|
657
|
+
expect_too_many_args(newdom, "max_memory=", 1, 2)
|
658
|
+
expect_too_few_args(newdom, "max_memory=")
|
659
|
+
expect_invalid_arg_type(newdom, "max_memory=", 'foo')
|
660
|
+
|
661
|
+
begin
|
662
|
+
newdom.max_memory = 200000
|
663
|
+
puts_ok "dom.max_memory= succeded"
|
664
|
+
rescue NoMethodError
|
665
|
+
puts_skipped "dom.max_memory does not exist"
|
666
|
+
rescue Libvirt::DefinitionError => e
|
667
|
+
# dom.max_memory is not supported by Qemu; skip
|
668
|
+
puts_skipped "dom.max_memory not supported by connection driver"
|
669
|
+
end
|
670
|
+
|
671
|
+
newdom.undefine
|
672
|
+
|
673
|
+
# TESTGROUP: dom.memory=
|
674
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
675
|
+
|
676
|
+
expect_too_many_args(newdom, "memory=", 1, 2)
|
677
|
+
expect_too_few_args(newdom, "memory=")
|
678
|
+
expect_invalid_arg_type(newdom, "memory=", 'foo')
|
679
|
+
|
680
|
+
expect_fail(newdom, Libvirt::Error, "shutoff domain", "memory=", 2)
|
681
|
+
|
682
|
+
newdom.undefine
|
683
|
+
|
684
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
685
|
+
sleep 1
|
686
|
+
|
687
|
+
expect_success(newdom, "number arg", "memory=", 200000)
|
688
|
+
|
689
|
+
newdom.destroy
|
690
|
+
|
691
|
+
# TESTGROUP: dom.max_vcpus
|
692
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
693
|
+
sleep 1
|
694
|
+
|
695
|
+
expect_too_many_args(newdom, "max_vcpus", 1)
|
696
|
+
|
697
|
+
expect_success(newdom, "no args", "max_vcpus")
|
698
|
+
|
699
|
+
newdom.destroy
|
700
|
+
|
701
|
+
# TESTGROUP: dom.vcpus=
|
702
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
703
|
+
|
704
|
+
expect_too_many_args(newdom, "vcpus=", 1, 2)
|
705
|
+
expect_too_few_args(newdom, "vcpus=")
|
706
|
+
expect_invalid_arg_type(newdom, "vcpus=", 'foo')
|
707
|
+
|
708
|
+
expect_fail(newdom, Libvirt::Error, "shutoff domain", "vcpus=", 2)
|
709
|
+
|
710
|
+
newdom.undefine
|
711
|
+
|
712
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
713
|
+
sleep 1
|
714
|
+
|
715
|
+
# FIXME: this kills the domain for some reason
|
716
|
+
#expect_success(newdom, "number arg", "vcpus=", 2)
|
717
|
+
|
718
|
+
newdom.destroy
|
719
|
+
|
720
|
+
# TESTGROUP: dom.pin_vcpu
|
721
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
722
|
+
sleep 1
|
723
|
+
|
724
|
+
expect_too_many_args(newdom, "pin_vcpu", 1, 2, 3)
|
725
|
+
expect_too_few_args(newdom, "pin_vcpu")
|
726
|
+
expect_invalid_arg_type(newdom, "pin_vcpu", 'foo', [0])
|
727
|
+
expect_invalid_arg_type(newdom, "pin_vcpu", 0, 1)
|
728
|
+
|
729
|
+
expect_success(newdom, "cpu args", "pin_vcpu", 0, [0])
|
730
|
+
|
731
|
+
newdom.destroy
|
732
|
+
|
733
|
+
# TESTGROUP: dom.xml_desc
|
734
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
735
|
+
sleep 1
|
736
|
+
|
737
|
+
expect_too_many_args(newdom, "xml_desc", 1, 2)
|
738
|
+
expect_invalid_arg_type(newdom, "xml_desc", "foo")
|
739
|
+
|
740
|
+
expect_success(newdom, "no args", "xml_desc")
|
741
|
+
|
742
|
+
newdom.destroy
|
743
|
+
|
744
|
+
# TESTGROUP: dom.undefine
|
745
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
746
|
+
|
747
|
+
expect_too_many_args(newdom, "undefine", 1)
|
748
|
+
|
749
|
+
expect_success(newdom, "no args", "undefine")
|
750
|
+
|
751
|
+
# TESTGROUP: dom.create
|
752
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
753
|
+
|
754
|
+
expect_too_many_args(newdom, "create", 1, 2)
|
755
|
+
expect_invalid_arg_type(newdom, "create", "foo")
|
756
|
+
|
757
|
+
expect_success(newdom, "no args", "create")
|
758
|
+
|
759
|
+
expect_fail(newdom, Libvirt::Error, "on already running domain", "create")
|
760
|
+
|
761
|
+
newdom.destroy
|
762
|
+
newdom.undefine
|
763
|
+
|
764
|
+
# TESTGROUP: dom.autostart?
|
765
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
766
|
+
|
767
|
+
expect_too_many_args(newdom, "autostart?", 1)
|
768
|
+
|
769
|
+
expect_success(newdom, "no args", "autostart?") {|x| x == false}
|
770
|
+
|
771
|
+
newdom.autostart = true
|
772
|
+
|
773
|
+
expect_success(newdom, "no args", "autostart?") {|x| x == true}
|
774
|
+
|
775
|
+
newdom.undefine
|
776
|
+
|
777
|
+
# TESTGROUP: dom.autostart=
|
778
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
779
|
+
|
780
|
+
expect_too_many_args(newdom, "autostart=", 1, 2)
|
781
|
+
expect_invalid_arg_type(newdom, "autostart=", 'foo')
|
782
|
+
expect_invalid_arg_type(newdom, "autostart=", nil)
|
783
|
+
expect_invalid_arg_type(newdom, "autostart=", 1234)
|
784
|
+
|
785
|
+
expect_success(newdom, "true arg", "autostart=", true)
|
786
|
+
if not newdom.autostart?
|
787
|
+
puts_fail "dom.autostart= did not set autostart to true"
|
788
|
+
else
|
789
|
+
puts_ok "dom.autostart= set autostart to true"
|
109
790
|
end
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
blockpeek = newdom.block_peek('/var/lib/libvirt/images/ruby-libvirt-test.dsk',
|
117
|
-
0, 512)
|
118
|
-
blockpeek = newdom.block_peek('/var/lib/libvirt/images/ruby-libvirt-test.dsk',
|
119
|
-
0, 512, 0)
|
120
|
-
# 2010-06-30: memory_peek is broken on RHEL-6 libvirt; fixed in upstream
|
121
|
-
#mempeek = newdom.memory_peek(0, 512, Libvirt::Domain::MEMORY_VIRTUAL)
|
122
|
-
|
123
|
-
|
124
|
-
defined = conn.list_defined_domains
|
125
|
-
running = conn.list_domains
|
126
|
-
|
127
|
-
(defined+running).each do |dom|
|
128
|
-
if defined.include? dom
|
129
|
-
domain = conn.lookup_domain_by_name(dom)
|
130
|
-
elsif running.include? dom
|
131
|
-
domain = conn.lookup_domain_by_id(dom)
|
132
|
-
end
|
133
|
-
dom2 = conn.lookup_domain_by_uuid(domain.uuid)
|
134
|
-
puts "Domain #{domain.name}:"
|
135
|
-
puts " UUID: #{domain.uuid}"
|
136
|
-
puts " ID: #{domain.id}"
|
137
|
-
puts " OS Type: #{domain.os_type}"
|
138
|
-
puts " Max Memory: #{domain.max_memory}"
|
139
|
-
puts " Max VCPUs: #{domain.max_vcpus}"
|
140
|
-
puts " Persistent?: #{domain.persistent?}"
|
141
|
-
puts " Active?: #{domain.active?}"
|
142
|
-
info = domain.info
|
143
|
-
puts " Info:"
|
144
|
-
puts " State: #{info.state}"
|
145
|
-
puts " Max Memory: #{info.max_mem}"
|
146
|
-
puts " Memory: #{info.memory}"
|
147
|
-
puts " Number VCPUs: #{info.nr_virt_cpu}"
|
148
|
-
puts " CPU Time: #{info.cpu_time}"
|
149
|
-
puts " Snapshots:"
|
150
|
-
puts " Number: #{domain.num_of_snapshots}"
|
151
|
-
puts " Has Current?: #{domain.has_current_snapshot?}"
|
152
|
-
domain.list_snapshots.each do |snapname|
|
153
|
-
snap = domain.lookup_snapshot_by_name(snapname)
|
154
|
-
puts " Snapshot #{snapname}"
|
155
|
-
puts snap.xml_desc
|
156
|
-
end
|
157
|
-
domain.xml_desc
|
158
|
-
puts " XML:"
|
159
|
-
puts domain.xml_desc(0)
|
791
|
+
|
792
|
+
expect_success(newdom, "false arg", "autostart=", false)
|
793
|
+
if newdom.autostart?
|
794
|
+
puts_fail "dom.autostart= did not set autostart to false"
|
795
|
+
else
|
796
|
+
puts_ok "dom.autostart= set autostart to false"
|
160
797
|
end
|
161
798
|
|
799
|
+
newdom.undefine
|
800
|
+
|
801
|
+
# TESTGROUP: dom.attach_device
|
802
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
803
|
+
|
804
|
+
expect_too_many_args(newdom, "attach_device", 1, 2, 3)
|
805
|
+
expect_too_few_args(newdom, "attach_device")
|
806
|
+
expect_invalid_arg_type(newdom, "attach_device", 1)
|
807
|
+
expect_invalid_arg_type(newdom, "attach_device", 'foo', 'bar')
|
808
|
+
expect_fail(newdom, Libvirt::Error, "invalid XML", "attach_device", "hello")
|
809
|
+
expect_fail(newdom, Libvirt::Error, "shut off domain", "attach_device", new_hostdev_xml)
|
810
|
+
|
811
|
+
newdom.undefine
|
812
|
+
|
813
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
814
|
+
sleep 1
|
815
|
+
|
816
|
+
#expect_success(newdom, "hostdev XML", "attach_device", new_hostdev_xml)
|
817
|
+
|
162
818
|
newdom.destroy
|
819
|
+
|
820
|
+
# TESTGROUP: dom.detach_device
|
821
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
822
|
+
|
823
|
+
expect_too_many_args(newdom, "detach_device", 1, 2, 3)
|
824
|
+
expect_too_few_args(newdom, "detach_device")
|
825
|
+
expect_invalid_arg_type(newdom, "detach_device", 1)
|
826
|
+
expect_invalid_arg_type(newdom, "detach_device", 'foo', 'bar')
|
827
|
+
expect_fail(newdom, Libvirt::Error, "invalid XML", "detach_device", "hello")
|
828
|
+
expect_fail(newdom, Libvirt::Error, "shut off domain", "detach_device", new_hostdev_xml)
|
829
|
+
|
163
830
|
newdom.undefine
|
164
831
|
|
832
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
833
|
+
sleep 1
|
834
|
+
|
835
|
+
#expect_success(newdom, "hostdev XML", "detach_device", new_hostdev_xml)
|
836
|
+
|
837
|
+
newdom.destroy
|
838
|
+
|
839
|
+
# TESTGROUP: dom.update_device
|
840
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
841
|
+
|
842
|
+
expect_too_many_args(newdom, "update_device", 1, 2, 3)
|
843
|
+
expect_too_few_args(newdom, "update_device")
|
844
|
+
expect_invalid_arg_type(newdom, "update_device", 1)
|
845
|
+
expect_invalid_arg_type(newdom, "update_device", 'foo', 'bar')
|
846
|
+
expect_fail(newdom, Libvirt::Error, "invalid XML", "update_device", "hello")
|
847
|
+
expect_fail(newdom, Libvirt::Error, "shut off domain", "update_device", new_hostdev_xml)
|
848
|
+
|
849
|
+
newdom.undefine
|
850
|
+
|
851
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
852
|
+
sleep 1
|
853
|
+
|
854
|
+
#expect_success(newdom, "hostdev XML", "update_device", new_hostdev_xml)
|
855
|
+
|
856
|
+
newdom.destroy
|
857
|
+
|
858
|
+
# TESTGROUP: dom.free
|
859
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
860
|
+
newdom.undefine
|
861
|
+
expect_too_many_args(newdom, "free", 1)
|
862
|
+
|
863
|
+
newdom.free
|
864
|
+
puts_ok "dom.free succeeded"
|
865
|
+
|
866
|
+
# TESTGROUP: dom.snapshot_create_xml
|
867
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
868
|
+
|
869
|
+
expect_too_many_args(newdom, "snapshot_create_xml", 1, 2, 3)
|
870
|
+
expect_too_few_args(newdom, "snapshot_create_xml")
|
871
|
+
expect_invalid_arg_type(newdom, "snapshot_create_xml", 1)
|
872
|
+
expect_invalid_arg_type(newdom, "snapshot_create_xml", nil)
|
873
|
+
expect_invalid_arg_type(newdom, "snapshot_create_xml", 'foo', 'bar')
|
874
|
+
|
875
|
+
expect_success(newdom, "simple XML arg", "snapshot_create_xml", "<domainsnapshot/>")
|
876
|
+
|
877
|
+
snaps = newdom.num_of_snapshots
|
878
|
+
if snaps != 1
|
879
|
+
puts_fail "dom.snapshot_create_xml after one snapshot has #{snaps} snapshots"
|
880
|
+
else
|
881
|
+
puts_ok "dom.snapshot_create_xml after one snapshot has 1 snapshot"
|
882
|
+
end
|
883
|
+
|
884
|
+
newdom.undefine
|
885
|
+
|
886
|
+
# TESTGROUP: dom.num_of_snapshots
|
887
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
888
|
+
|
889
|
+
expect_too_many_args(newdom, "num_of_snapshots", 1, 2)
|
890
|
+
expect_invalid_arg_type(newdom, "num_of_snapshots", 'foo')
|
891
|
+
|
892
|
+
expect_success(newdom, "no args", "num_of_snapshots") {|x| x == 0}
|
893
|
+
|
894
|
+
newdom.snapshot_create_xml("<domainsnapshot/>")
|
895
|
+
|
896
|
+
expect_success(newdom, "no args", "num_of_snapshots") {|x| x == 1}
|
897
|
+
|
898
|
+
newdom.undefine
|
899
|
+
|
900
|
+
# TESTGROUP: dom.list_snapshots
|
901
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
902
|
+
|
903
|
+
expect_too_many_args(newdom, "list_snapshots", 1, 2)
|
904
|
+
expect_invalid_arg_type(newdom, "list_snapshots", 'foo')
|
905
|
+
|
906
|
+
expect_success(newdom, "no args", "list_snapshots") {|x| x.length == 0}
|
907
|
+
|
908
|
+
newdom.snapshot_create_xml("<domainsnapshot/>")
|
909
|
+
|
910
|
+
expect_success(newdom, "no args", "list_snapshots") {|x| x.length == 1}
|
911
|
+
|
912
|
+
newdom.undefine
|
913
|
+
|
914
|
+
# TESTGROUP: dom.lookup_snapshot_by_name
|
915
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
916
|
+
newdom.snapshot_create_xml("<domainsnapshot><name>foo</name></domainsnapshot>")
|
917
|
+
|
918
|
+
expect_too_many_args(newdom, "lookup_snapshot_by_name", 1, 2, 3)
|
919
|
+
expect_too_few_args(newdom, "lookup_snapshot_by_name")
|
920
|
+
expect_invalid_arg_type(newdom, "lookup_snapshot_by_name", 1)
|
921
|
+
expect_invalid_arg_type(newdom, "lookup_snapshot_by_name", 'foo', 'bar')
|
922
|
+
|
923
|
+
expect_success(newdom, "name arg", "lookup_snapshot_by_name", "foo")
|
924
|
+
|
925
|
+
newdom.undefine
|
926
|
+
|
927
|
+
# TESTGROUP: dom.has_current_snapshot?
|
928
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
929
|
+
|
930
|
+
expect_too_many_args(newdom, "has_current_snapshot?", 1, 2)
|
931
|
+
expect_invalid_arg_type(newdom, "has_current_snapshot?", 'foo')
|
932
|
+
|
933
|
+
expect_success(newdom, "no args", "has_current_snapshot?") {|x| x == false}
|
934
|
+
|
935
|
+
newdom.snapshot_create_xml("<domainsnapshot><name>foo</name></domainsnapshot>")
|
936
|
+
|
937
|
+
expect_success(newdom, "no args", "has_current_snapshot?") {|x| x == true}
|
938
|
+
|
939
|
+
newdom.undefine
|
940
|
+
|
941
|
+
# TESTGROUP: dom.revert_to_snapshot
|
942
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
943
|
+
|
944
|
+
expect_too_many_args(newdom, "revert_to_snapshot", 1, 2, 3)
|
945
|
+
expect_too_few_args(newdom, "revert_to_snapshot")
|
946
|
+
expect_invalid_arg_type(newdom, "revert_to_snapshot", 1)
|
947
|
+
expect_invalid_arg_type(newdom, "revert_to_snapshot", nil)
|
948
|
+
expect_invalid_arg_type(newdom, "revert_to_snapshot", 'foo')
|
949
|
+
|
950
|
+
snap = newdom.snapshot_create_xml("<domainsnapshot><name>foo</name></domainsnapshot>")
|
951
|
+
sleep 1
|
952
|
+
|
953
|
+
expect_invalid_arg_type(newdom, "revert_to_snapshot", snap, 'foo')
|
954
|
+
|
955
|
+
expect_success(newdom, "snapshot arg", "revert_to_snapshot", snap)
|
956
|
+
|
957
|
+
newdom.undefine
|
958
|
+
|
959
|
+
# TESTGROUP: dom.current_snapshot
|
960
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
961
|
+
|
962
|
+
expect_too_many_args(newdom, "current_snapshot", 1, 2)
|
963
|
+
expect_invalid_arg_type(newdom, "current_snapshot", 'foo')
|
964
|
+
expect_fail(newdom, Libvirt::RetrieveError, "with no snapshots", "current_snapshot")
|
965
|
+
|
966
|
+
newdom.snapshot_create_xml("<domainsnapshot><name>foo</name></domainsnapshot>")
|
967
|
+
|
968
|
+
expect_success(newdom, "no args", "current_snapshot")
|
969
|
+
|
970
|
+
newdom.undefine
|
971
|
+
|
972
|
+
# TESTGROUP: snapshot.xml_desc
|
973
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
974
|
+
snap = newdom.snapshot_create_xml("<domainsnapshot/>")
|
975
|
+
|
976
|
+
expect_too_many_args(snap, "xml_desc", 1, 2)
|
977
|
+
expect_invalid_arg_type(snap, "xml_desc", 'foo')
|
978
|
+
|
979
|
+
expect_success(newdom, "no args", "xml_desc")
|
980
|
+
|
981
|
+
newdom.undefine
|
982
|
+
|
983
|
+
# TESTGROUP: snapshot.delete
|
984
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
985
|
+
snap = newdom.snapshot_create_xml("<domainsnapshot/>")
|
986
|
+
|
987
|
+
expect_too_many_args(snap, "delete", 1, 2)
|
988
|
+
expect_invalid_arg_type(snap, "delete", 'foo')
|
989
|
+
|
990
|
+
expect_success(snap, "no args", "delete")
|
991
|
+
|
992
|
+
newdom.undefine
|
993
|
+
|
994
|
+
# TESTGROUP: snapshot.free
|
995
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
996
|
+
newdom.undefine
|
997
|
+
expect_too_many_args(newdom, "free", 1)
|
998
|
+
|
999
|
+
expect_success(newdom, "no args", "free")
|
1000
|
+
|
1001
|
+
# TESTGROUP: dom.job_info
|
1002
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
1003
|
+
|
1004
|
+
expect_too_many_args(newdom, "job_info", 1)
|
1005
|
+
|
1006
|
+
expect_fail(newdom, Libvirt::RetrieveError, "shutoff domain", "job_info")
|
1007
|
+
|
1008
|
+
newdom.undefine
|
1009
|
+
|
1010
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
1011
|
+
sleep 1
|
1012
|
+
|
1013
|
+
expect_success(newdom, "no args", "job_info")
|
1014
|
+
|
1015
|
+
newdom.destroy
|
1016
|
+
|
1017
|
+
# TESTGROUP: dom.abort_job
|
1018
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
1019
|
+
|
1020
|
+
expect_too_many_args(newdom, "abort_job", 1)
|
1021
|
+
|
1022
|
+
expect_fail(newdom, Libvirt::Error, "not running domain", "abort_job")
|
1023
|
+
|
1024
|
+
newdom.undefine
|
1025
|
+
|
1026
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
1027
|
+
sleep 1
|
1028
|
+
|
1029
|
+
expect_fail(newdom, Libvirt::Error, "no active job", "abort_job")
|
1030
|
+
|
1031
|
+
# FIXME: need to start long running job here
|
1032
|
+
#expect_success(newdom, "no args", "abort_job")
|
1033
|
+
|
1034
|
+
newdom.destroy
|
1035
|
+
|
1036
|
+
# TESTGROUP: dom.scheduler_type
|
1037
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
1038
|
+
|
1039
|
+
expect_too_many_args(newdom, "scheduler_type", 1)
|
1040
|
+
|
1041
|
+
begin
|
1042
|
+
newdom.scheduler_type
|
1043
|
+
puts_ok "dom.scheduler_type succeeded"
|
1044
|
+
rescue NoMethodError
|
1045
|
+
puts_skipped "dom.scheduler_type does not exist"
|
1046
|
+
rescue Libvirt::RetrieveError
|
1047
|
+
# this may not be supported (if cgroups aren't configured), so skip it
|
1048
|
+
puts_skipped "dom.scheduler_type not supported"
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
newdom.undefine
|
1052
|
+
|
1053
|
+
# TESTGROUP: dom.scheduler_parameters
|
1054
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
1055
|
+
|
1056
|
+
expect_too_many_args(newdom, "scheduler_parameters", 1)
|
1057
|
+
|
1058
|
+
begin
|
1059
|
+
newdom.scheduler_parameters
|
1060
|
+
puts_ok "dom.scheduler_parameters succeeded"
|
1061
|
+
rescue NoMethodError
|
1062
|
+
puts_skipped "dom.scheduler_parameters does not exist"
|
1063
|
+
rescue Libvirt::RetrieveError
|
1064
|
+
# this may not be supported (if cgroups aren't configured), so skip it
|
1065
|
+
puts_ok "dom.scheduler_parameters not supported"
|
1066
|
+
end
|
1067
|
+
|
1068
|
+
newdom.undefine
|
1069
|
+
|
1070
|
+
# TESTGROUP: dom.scheduler_parameters=
|
1071
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
1072
|
+
|
1073
|
+
expect_too_many_args(newdom, "scheduler_parameters=", 1, 2)
|
1074
|
+
expect_too_few_args(newdom, "scheduler_parameters=")
|
1075
|
+
expect_invalid_arg_type(newdom, "scheduler_parameters=", 0)
|
1076
|
+
|
1077
|
+
# FIXME: set scheduler_parameters here
|
1078
|
+
|
1079
|
+
newdom.undefine
|
1080
|
+
|
1081
|
+
# TESTGROUP: dom.num_vcpus
|
1082
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
1083
|
+
|
1084
|
+
expect_too_many_args(newdom, "num_vcpus", 1, 2)
|
1085
|
+
expect_too_few_args(newdom, "num_vcpus")
|
1086
|
+
expect_invalid_arg_type(newdom, "num_vcpus", 'foo')
|
1087
|
+
expect_fail(newdom, Libvirt::Error, "zero flags", "num_vcpus", 0)
|
1088
|
+
expect_fail(newdom, Libvirt::Error, "active flag on shutoff domain", "num_vcpus", Libvirt::Domain::VCPU_LIVE)
|
1089
|
+
expect_fail(newdom, Libvirt::Error, "live and config flags", "num_vcpus", Libvirt::Domain::VCPU_LIVE | Libvirt::Domain::VCPU_CONFIG)
|
1090
|
+
expect_success(newdom, "config flag", "num_vcpus", Libvirt::Domain::VCPU_CONFIG) {|x| x == 2}
|
1091
|
+
|
1092
|
+
newdom.undefine
|
1093
|
+
|
1094
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
1095
|
+
sleep 1
|
1096
|
+
|
1097
|
+
expect_success(newdom, "config flag on transient domain", "num_vcpus", Libvirt::Domain::VCPU_CONFIG)
|
1098
|
+
expect_success(newdom, "live flag on transient domain", "num_vcpus", Libvirt::Domain::VCPU_LIVE)
|
1099
|
+
|
1100
|
+
newdom.destroy
|
1101
|
+
|
1102
|
+
# TESTGROUP: dom.vcpus_flags=
|
1103
|
+
newdom = conn.define_domain_xml(new_dom_xml)
|
1104
|
+
|
1105
|
+
expect_too_many_args(newdom, "vcpus_flags=", 1, 2, 3)
|
1106
|
+
expect_too_few_args(newdom, "vcpus_flags=")
|
1107
|
+
expect_invalid_arg_type(newdom, "vcpus_flags=", 1)
|
1108
|
+
expect_invalid_arg_type(newdom, "vcpus_flags=", ['foo', 2])
|
1109
|
+
expect_invalid_arg_type(newdom, "vcpus_flags=", [2, 'foo'])
|
1110
|
+
expect_fail(newdom, Libvirt::Error, "zero flags", "vcpus_flags=", [2, 0])
|
1111
|
+
expect_fail(newdom, Libvirt::Error, "zero vcpus", "vcpus_flags=", [0, Libvirt::Domain::VCPU_CONFIG])
|
1112
|
+
expect_fail(newdom, Libvirt::Error, "live vcpu on shutoff domain", "vcpus_flags=", [2, Libvirt::Domain::VCPU_LIVE])
|
1113
|
+
expect_success(newdom, "2 vcpu config", "vcpus_flags=", [2, Libvirt::Domain::VCPU_CONFIG])
|
1114
|
+
|
1115
|
+
newdom.undefine
|
1116
|
+
|
1117
|
+
newdom = conn.create_domain_xml(new_dom_xml)
|
1118
|
+
sleep 1
|
1119
|
+
|
1120
|
+
expect_fail(newdom, Libvirt::Error, "vcpu config on transient domain", "vcpus_flags=", [2, Libvirt::Domain::VCPU_CONFIG])
|
1121
|
+
expect_fail(newdom, Libvirt::Error, "too many vcpus", "vcpus_flags=", [4, Libvirt::Domain::VCPU_LIVE])
|
1122
|
+
|
1123
|
+
# FIXME: this doesn't work for some reason
|
1124
|
+
#expect_success(newdom, "vcpus to 1", "vcpus_flags", [1,Libvirt::Domain::VCPU_LIVE])
|
1125
|
+
|
1126
|
+
newdom.destroy
|
1127
|
+
|
165
1128
|
conn.close
|
1129
|
+
|
1130
|
+
finish_tests
|