ruby-libvirt 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/libvirt/stream.h CHANGED
@@ -1,7 +1,9 @@
1
1
  #ifndef STREAM_H
2
2
  #define STREAM_H
3
3
 
4
- virStreamPtr stream_get(VALUE s);
5
- void init_stream();
4
+ void ruby_libvirt_stream_init(void);
5
+
6
+ VALUE ruby_libvirt_stream_new(virStreamPtr s, VALUE conn);
7
+ virStreamPtr ruby_libvirt_stream_get(VALUE s);
6
8
 
7
9
  #endif
data/tests/test_conn.rb CHANGED
@@ -7,18 +7,22 @@ $: << File.dirname(__FILE__)
7
7
  require 'libvirt'
8
8
  require 'test_utils.rb'
9
9
 
10
+ set_test_object("connect")
11
+
12
+ conn = Libvirt::open("qemu:///system")
13
+
14
+ cleanup_test_domain(conn)
15
+ cleanup_test_network(conn)
16
+
10
17
  # test setup
11
18
  begin
12
19
  `rm -f /etc/sysconfig/network-scripts/ifcfg-ruby-libvirt-tester`
13
20
  `brctl delbr ruby-libvirt-tester >& /dev/null`
14
21
  rescue
15
22
  end
16
- `rm -f #{$GUEST_DISK} ; qemu-img create -f qcow2 #{$GUEST_DISK} 5G`
17
- `rm -f /var/lib/libvirt/images/ruby-libvirt-test.save`
23
+ `qemu-img create -f qcow2 #{$GUEST_DISK} 5G`
18
24
  `rm -rf #{$POOL_PATH}; mkdir #{$POOL_PATH} ; echo $?`
19
25
 
20
- conn = Libvirt::open("qemu:///system")
21
-
22
26
  cpu_xml = <<EOF
23
27
  <cpu>
24
28
  <arch>x86_64</arch>
@@ -78,35 +82,19 @@ expect_too_many_args(conn, "node_get_info", 1)
78
82
 
79
83
  expect_success(conn, "no args", "node_get_info")
80
84
 
81
- begin
82
- # TESTGROUP: conn.node_free_memory
83
- expect_too_many_args(conn, "node_free_memory", 1)
84
-
85
- conn.node_free_memory
86
- puts_ok "conn.node_free_memory no args"
87
- rescue Libvirt::RetrieveError
88
- puts_skipped "conn.node_free_memory not supported on this host"
89
- rescue NoMethodError
90
- puts_skipped "conn.node_free_memory does not exist"
91
- end
85
+ # TESTGROUP: conn.node_free_memory
86
+ expect_too_many_args(conn, "node_free_memory", 1)
92
87
 
93
- begin
94
- # TESTGROUP: conn.node_cells_free_memory
95
- expect_too_many_args(conn, "node_cells_free_memory", 1, 2, 3)
96
- expect_invalid_arg_type(conn, "node_cells_free_memory", 'start')
97
- expect_invalid_arg_type(conn, "node_cells_free_memory", 0, 'end')
98
-
99
- cell_mem = conn.node_cells_free_memory
100
- puts_ok "conn.node_cells_free_memory no args = "
101
- cell_mem = conn.node_cells_free_memory(0)
102
- puts_ok "conn.node_cells_free_memory(0) = "
103
- cell_mem = conn.node_cells_free_memory(0, 1)
104
- puts_ok "conn.node_cells_free_memory(0, 1) = "
105
- rescue Libvirt::RetrieveError
106
- puts_skipped "conn.node_cells_free_memory not supported on this host"
107
- rescue NoMethodError
108
- puts_skipped "conn.node_cells_free_memory does not exist"
109
- end
88
+ expect_success(conn, "no args", "node_free_memory")
89
+
90
+ # TESTGROUP: conn.node_cells_free_memory
91
+ expect_too_many_args(conn, "node_cells_free_memory", 1, 2, 3)
92
+ expect_invalid_arg_type(conn, "node_cells_free_memory", 'start')
93
+ expect_invalid_arg_type(conn, "node_cells_free_memory", 0, 'end')
94
+
95
+ expect_success(conn, "no args", "node_cells_free_memory")
96
+ expect_success(conn, "start cell", "node_cells_free_memory", 0)
97
+ expect_success(conn, "start cell and max cells", "node_cells_free_memory", 0, 1)
110
98
 
111
99
  # TESTGROUP: conn.node_get_security_model
112
100
  expect_too_many_args(conn, "node_get_security_model", 1)
@@ -136,7 +124,7 @@ expect_success(conn, "CPU XML", "compare_cpu", cpu_xml)
136
124
  expect_too_many_args(conn, "baseline_cpu", 1, 2, 3)
137
125
  expect_too_few_args(conn, "baseline_cpu")
138
126
  expect_invalid_arg_type(conn, "baseline_cpu", 1)
139
- expect_invalid_arg_type(conn, "baseline_cpu", [], "foo")
127
+ expect_invalid_arg_type(conn, "baseline_cpu", [cpu_xml], "foo")
140
128
  expect_fail(conn, ArgumentError, "empty array", "baseline_cpu", [])
141
129
  expect_success(conn, "CPU XML", "baseline_cpu", [cpu_xml])
142
130
 
@@ -144,8 +132,8 @@ expect_success(conn, "CPU XML", "baseline_cpu", [cpu_xml])
144
132
  dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
145
133
  }
146
134
 
147
- def dom_event_callback_symbol(conn, dom, event, detail, opaque)
148
- end
135
+ # def dom_event_callback_symbol(conn, dom, event, detail, opaque)
136
+ # end
149
137
 
150
138
  expect_too_many_args(conn, "domain_event_register_any", 1, 2, 3, 4, 5)
151
139
  expect_too_few_args(conn, "domain_event_register_any")
@@ -155,58 +143,58 @@ expect_invalid_arg_type(conn, "domain_event_register_any", Libvirt::Connect::DOM
155
143
  expect_invalid_arg_type(conn, "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, 1)
156
144
  expect_fail(conn, ArgumentError, "invalid event ID", "domain_event_register_any", 456789, dom_event_callback_proc)
157
145
 
158
- callbackID = expect_success(conn, "eventID and proc", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc)
159
- conn.domain_event_deregister_any(callbackID)
146
+ # callbackID = expect_success(conn, "eventID and proc", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc)
147
+ # conn.domain_event_deregister_any(callbackID)
160
148
 
161
- callbackID = expect_success(conn, "eventID and symbol", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, :dom_event_callback_symbol)
162
- conn.domain_event_deregister_any(callbackID)
149
+ # callbackID = expect_success(conn, "eventID and symbol", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, :dom_event_callback_symbol)
150
+ # conn.domain_event_deregister_any(callbackID)
163
151
 
164
- callbackID = expect_success(conn, "eventID, proc, nil domain", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, nil)
165
- conn.domain_event_deregister_any(callbackID)
152
+ # callbackID = expect_success(conn, "eventID, proc, nil domain", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, nil)
153
+ # conn.domain_event_deregister_any(callbackID)
166
154
 
167
- 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")
168
- conn.domain_event_deregister_any(callbackID)
155
+ # 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")
156
+ # conn.domain_event_deregister_any(callbackID)
169
157
 
170
- # TESTGROUP: conn.domain_event_deregister_any
171
- dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
172
- }
158
+ # # TESTGROUP: conn.domain_event_deregister_any
159
+ # dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
160
+ # }
173
161
 
174
- callbackID = conn.domain_event_register_any(Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc)
162
+ # callbackID = conn.domain_event_register_any(Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc)
175
163
 
176
164
  expect_too_many_args(conn, "domain_event_deregister_any", 1, 2)
177
165
  expect_too_few_args(conn, "domain_event_deregister_any")
178
166
  expect_invalid_arg_type(conn, "domain_event_deregister_any", "hello")
179
167
 
180
- expect_success(conn, "callbackID", "domain_event_deregister_any", callbackID)
168
+ # expect_success(conn, "callbackID", "domain_event_deregister_any", callbackID)
181
169
 
182
170
  # TESTGROUP: conn.domain_event_register
183
- dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
184
- }
171
+ # dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
172
+ # }
185
173
 
186
- def dom_event_callback_symbol(conn, dom, event, detail, opaque)
187
- end
174
+ # def dom_event_callback_symbol(conn, dom, event, detail, opaque)
175
+ # end
188
176
 
189
177
  expect_too_many_args(conn, "domain_event_register", 1, 2, 3)
190
178
  expect_too_few_args(conn, "domain_event_register")
191
179
  expect_invalid_arg_type(conn, "domain_event_register", "hello")
192
180
 
193
- expect_success(conn, "proc", "domain_event_register", dom_event_callback_proc)
194
- conn.domain_event_deregister
181
+ # expect_success(conn, "proc", "domain_event_register", dom_event_callback_proc)
182
+ # conn.domain_event_deregister
195
183
 
196
- expect_success(conn, "symbol", "domain_event_register", :dom_event_callback_symbol)
197
- conn.domain_event_deregister
184
+ # expect_success(conn, "symbol", "domain_event_register", :dom_event_callback_symbol)
185
+ # conn.domain_event_deregister
198
186
 
199
- expect_success(conn, "proc and opaque", "domain_event_register", dom_event_callback_proc, "opaque user data")
200
- conn.domain_event_deregister
187
+ # expect_success(conn, "proc and opaque", "domain_event_register", dom_event_callback_proc, "opaque user data")
188
+ # conn.domain_event_deregister
201
189
 
202
- # TESTGROUP: conn.domain_event_deregister
203
- dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
204
- }
190
+ # # TESTGROUP: conn.domain_event_deregister
191
+ # dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque|
192
+ # }
205
193
 
206
- conn.domain_event_register(dom_event_callback_proc)
194
+ # conn.domain_event_register(dom_event_callback_proc)
207
195
 
208
196
  expect_too_many_args(conn, "domain_event_deregister", 1)
209
- expect_success(conn, "no args", "domain_event_deregister")
197
+ # expect_success(conn, "no args", "domain_event_deregister")
210
198
 
211
199
  # TESTGROUP: conn.num_of_domains
212
200
  expect_too_many_args(conn, "num_of_domains", 1)
@@ -216,6 +204,13 @@ expect_success(conn, "no args", "num_of_domains")
216
204
  expect_too_many_args(conn, "list_domains", 1)
217
205
  expect_success(conn, "no args", "list_domains")
218
206
 
207
+ newdom = conn.create_domain_xml($new_dom_xml)
208
+ sleep 1
209
+
210
+ expect_success(conn, "no args", "list_domains")
211
+
212
+ newdom.destroy
213
+
219
214
  # TESTGROUP: conn.num_of_defined_domains
220
215
  expect_too_many_args(conn, "num_of_defined_domains", 1)
221
216
  expect_success(conn, "no args", "num_of_defined_domains")
@@ -372,10 +367,9 @@ expect_too_few_args(conn, "lookup_interface_by_mac")
372
367
  expect_invalid_arg_type(conn, "lookup_interface_by_mac", 1)
373
368
  expect_fail(conn, Libvirt::RetrieveError, "non-existent mac arg", "lookup_interface_by_mac", "foobarbazsucker")
374
369
 
375
- testiface = find_valid_iface(conn)
376
- if not testiface.nil?
377
- expect_success(conn, "name arg", "lookup_interface_by_mac", testiface.mac) {|x| x.mac == testiface.mac}
378
- end
370
+ # FIXME: we can't look up an interface by MAC address on an inactive interface,
371
+ # but we also can't start up the interface without a /etc/sysconfig file.
372
+ #expect_success(conn, "mac arg", "lookup_interface_by_mac", $NEW_INTERFACE_MAC) {|x| x.mac == $NEW_INTERFACE_MAC}
379
373
 
380
374
  newiface.undefine
381
375
 
@@ -668,6 +662,159 @@ expect_invalid_arg_type(conn, "sys_info", "foo")
668
662
 
669
663
  expect_success(conn, "system info", "sys_info")
670
664
 
665
+ # TESTGROUP: conn.interface_change_begin
666
+ expect_too_many_args(conn, "interface_change_begin", 1, 2)
667
+ expect_invalid_arg_type(conn, "interface_change_begin", 'hello')
668
+
669
+ expect_success(conn, "interface change begin", "interface_change_begin")
670
+
671
+ conn.interface_change_rollback
672
+
673
+ # TESTGROUP: conn.interface_change_commit
674
+ expect_too_many_args(conn, "interface_change_commit", 1, 2)
675
+ expect_invalid_arg_type(conn, "interface_change_commit", 'foo')
676
+
677
+ # FIXME: libvirt throws an error on commit with no changes. What changes can
678
+ # we do here?
679
+ #expect_success(conn, "interface change commit", "interface_change_commit")
680
+
681
+ # TESTGROUP: conn.interface_change_rollback
682
+ conn.interface_change_begin
683
+
684
+ expect_too_many_args(conn, "interface_change_rollback", 1, 2)
685
+ expect_invalid_arg_type(conn, "interface_change_rollback", 'foo')
686
+
687
+ expect_success(conn, "interface change rollback", "interface_change_rollback")
688
+
689
+ # TESTGROUP: conn.node_cpu_stats
690
+ expect_too_many_args(conn, "node_cpu_stats", 1, 2, 3)
691
+ expect_invalid_arg_type(conn, "node_cpu_stats", 'foo')
692
+ expect_invalid_arg_type(conn, "node_cpu_stats", 1, 'bar')
693
+
694
+ expect_success(conn, "node cpu stats", "node_cpu_stats")
695
+
696
+ # TESTGROUP: conn.node_memory_stats
697
+ expect_too_many_args(conn, "node_memory_stats", 1, 2, 3)
698
+ expect_invalid_arg_type(conn, "node_memory_stats", 'foo')
699
+ expect_invalid_arg_type(conn, "node_memory_stats", 1, 'bar')
700
+
701
+ expect_success(conn, "node memory status", "node_memory_stats")
702
+
703
+ # TESTGROUP: conn.save_image_xml_desc
704
+ newdom = conn.define_domain_xml($new_dom_xml)
705
+ newdom.create
706
+ sleep 1
707
+ newdom.save($GUEST_SAVE)
708
+
709
+ expect_too_many_args(conn, "save_image_xml_desc", 1, 2, 3)
710
+ expect_too_few_args(conn, "save_image_xml_desc")
711
+ expect_invalid_arg_type(conn, "save_image_xml_desc", nil)
712
+ expect_invalid_arg_type(conn, "save_image_xml_desc", 1)
713
+ expect_invalid_arg_type(conn, "save_image_xml_desc", 'foo', 'bar')
714
+
715
+ expect_success(conn, "save image path", "save_image_xml_desc", $GUEST_SAVE)
716
+ `rm -f #{$GUEST_SAVE}`
717
+
718
+ # TESTGROUP: conn.define_save_image_xml
719
+ expect_too_many_args(conn, "define_save_image_xml", 1, 2, 3, 4)
720
+ expect_too_few_args(conn, "define_save_image_xml")
721
+ expect_too_few_args(conn, "define_save_image_xml", 'foo')
722
+ expect_invalid_arg_type(conn, "define_save_image_xml", nil, 'foo')
723
+ expect_invalid_arg_type(conn, "define_save_image_xml", 1, 'foo')
724
+ expect_invalid_arg_type(conn, "define_save_image_xml", 'foo', nil)
725
+ expect_invalid_arg_type(conn, "define_save_image_xml", 'foo', 1)
726
+ expect_invalid_arg_type(conn, "define_save_image_xml", 'foo', 'bar', 'baz')
727
+
728
+ # TESTGROUP: conn.alive?
729
+ expect_too_many_args(conn, "alive?", 1)
730
+
731
+ expect_success(conn, "alive connection", "alive?") {|x| x == true}
732
+
733
+ # TESTGROUP: conn.list_all_nwfilters
734
+ expect_too_many_args(conn, "list_all_nwfilters", 1, 2)
735
+ expect_invalid_arg_type(conn, "list_all_nwfilters", "foo")
736
+
737
+ expect_success(conn, "no args", "list_all_nwfilters")
738
+
739
+ # TESTGROUP: conn.list_all_storage_pools
740
+ expect_too_many_args(conn, "list_all_storage_pools", 1, 2)
741
+ expect_invalid_arg_type(conn, "list_all_storage_pools", "foo")
742
+
743
+ expect_success(conn, "no args", "list_all_storage_pools")
744
+
745
+ # TESTGROUP: conn.list_all_nodedevices
746
+ expect_too_many_args(conn, "list_all_nodedevices", 1, 2)
747
+ expect_invalid_arg_type(conn, "list_all_nodedevices", "foo")
748
+
749
+ expect_success(conn, "no args", "list_all_nodedevices")
750
+
751
+ # TESTGROUP: conn.list_all_secrets
752
+ expect_too_many_args(conn, "list_all_secrets", 1, 2)
753
+ expect_invalid_arg_type(conn, "list_all_secrets", "foo")
754
+
755
+ expect_success(conn, "no args", "list_all_secrets")
756
+
757
+ # TESTGROUP: conn.list_all_interfaces
758
+ expect_too_many_args(conn, "list_all_interfaces", 1, 2)
759
+ expect_invalid_arg_type(conn, "list_all_interfaces", "foo")
760
+
761
+ expect_success(conn, "no args", "list_all_interfaces")
762
+
763
+ # TESTGROUP: conn.list_all_networks
764
+ expect_too_many_args(conn, "list_all_networks", 1, 2)
765
+ expect_invalid_arg_type(conn, "list_all_networks", "foo")
766
+
767
+ expect_success(conn, "no args", "list_all_networks")
768
+
769
+ # TESTGROUP: conn.list_all_domains
770
+ expect_too_many_args(conn, "list_all_domains", 1, 2)
771
+ expect_invalid_arg_type(conn, "list_all_domains", "foo")
772
+
773
+ expect_success(conn, "no args", "list_all_domains")
774
+
775
+ # TESTGROUP: conn.set_keepalive
776
+ expect_too_many_args(conn, "set_keepalive", 1, 2, 3, 4)
777
+ expect_too_few_args(conn, "set_keepalive")
778
+ expect_too_few_args(conn, "set_keepalive", 1)
779
+ expect_invalid_arg_type(conn, "set_keepalive", 'foo', 0)
780
+ expect_invalid_arg_type(conn, "set_keepalive", 0, 'foo')
781
+
782
+ # FIXME: somehow we need an event loop implementation for this to work
783
+ #expect_success(conn, "interval and count", "set_keepalive", 1, 10)
784
+
785
+ # TESTGROUP: conn.node_suspend_for_duration
786
+ expect_too_many_args(conn, "node_suspend_for_duration", 1, 2, 3, 4)
787
+ expect_too_few_args(conn, "node_suspend_for_duration")
788
+ expect_too_few_args(conn, "node_suspend_for_duration", 1)
789
+ expect_invalid_arg_type(conn, "node_suspend_for_duration", 'foo', 1)
790
+ expect_invalid_arg_type(conn, "node_suspend_for_duration", 1, 'foo')
791
+ expect_invalid_arg_type(conn, "node_suspend_for_duration", 1, 2, 'foo')
792
+
793
+ # TESTGROUP: conn.node_memory_parameters
794
+ expect_too_many_args(conn, "node_memory_parameters", 1, 2)
795
+ expect_invalid_arg_type(conn, "node_memory_parameters", 'foo')
796
+
797
+ expect_success(conn, "no args", "node_memory_parameters")
798
+
799
+ # TESTGROUP: conn.node_memory_paramters=
800
+ expect_too_many_args(conn, "node_memory_parameters=", 1, 2)
801
+ expect_invalid_arg_type(conn, "node_memory_parameters=", nil)
802
+ expect_invalid_arg_type(conn, "node_memory_parameters=", ['foo', 0])
803
+ expect_invalid_arg_type(conn, "node_memory_parameters=", [{}, 'foo'])
804
+
805
+ # TESTGROUP: conn.keepalive=
806
+ expect_too_many_args(conn, "keepalive=", 1, 2)
807
+ expect_too_few_args(conn, "keepalive=", [])
808
+ expect_too_few_args(conn, "keepalive=", [1])
809
+ expect_invalid_arg_type(conn, "keepalive=", 1)
810
+ expect_invalid_arg_type(conn, "keepalive=", ['foo', 1])
811
+ expect_invalid_arg_type(conn, "keepalive=", [1, 'foo'])
812
+
813
+ # FIXME: somehow we need an event loop implementation for this to work
814
+ #expect_success(conn, "interval and count", "keepalive=", 1, 10)
815
+
816
+ # END TESTS
817
+
671
818
  conn.close
672
819
 
673
820
  finish_tests
data/tests/test_domain.rb CHANGED
@@ -11,20 +11,14 @@ $: << File.dirname(__FILE__)
11
11
  require 'libvirt'
12
12
  require 'test_utils.rb'
13
13
 
14
+ set_test_object("domain")
15
+
14
16
  conn = Libvirt::open("qemu:///system")
15
17
 
16
- # initial cleanup for previous runs
17
- begin
18
- olddom = conn.lookup_domain_by_name("ruby-libvirt-tester")
19
- olddom.destroy
20
- olddom.undefine
21
- rescue
22
- # in case we didn't find it, don't do anything
23
- end
18
+ cleanup_test_domain(conn)
24
19
 
25
20
  # setup for later tests
26
- `rm -f #{$GUEST_DISK} ; qemu-img create -f qcow2 #{$GUEST_DISK} 5G`
27
- `rm -f /var/lib/libvirt/images/ruby-libvirt-test.save`
21
+ `qemu-img create -f qcow2 #{$GUEST_DISK} 5G`
28
22
 
29
23
  new_hostdev_xml = <<EOF
30
24
  <hostdev mode='subsystem' type='pci' managed='yes'>
@@ -36,6 +30,145 @@ EOF
36
30
 
37
31
  # start tests
38
32
 
33
+ # TESTGROUP: dom.migrate_max_speed
34
+ newdom = conn.create_domain_xml($new_dom_xml)
35
+ sleep 1
36
+
37
+ expect_too_many_args(newdom, "migrate_max_speed", 1, 2)
38
+ expect_invalid_arg_type(newdom, "migrate_max_speed", 'foo')
39
+ expect_invalid_arg_type(newdom, "migrate_max_speed", [])
40
+ expect_invalid_arg_type(newdom, "migrate_max_speed", {})
41
+
42
+ expect_success(newdom, "no args", "migrate_max_speed")
43
+
44
+ newdom.destroy
45
+
46
+ # TESTGROUP: dom.reset
47
+ newdom = conn.create_domain_xml($new_dom_xml)
48
+ sleep 1
49
+
50
+ expect_too_many_args(newdom, "reset", 1, 2)
51
+ expect_invalid_arg_type(newdom, "reset", 'foo')
52
+ expect_invalid_arg_type(newdom, "reset", [])
53
+ expect_invalid_arg_type(newdom, "reset", {})
54
+
55
+ expect_success(newdom, "no args", "reset")
56
+
57
+ newdom.destroy
58
+
59
+ # TESTGROUP: dom.hostname
60
+ newdom = conn.create_domain_xml($new_dom_xml)
61
+ sleep 1
62
+
63
+ expect_too_many_args(newdom, "hostname", 1, 2)
64
+ expect_invalid_arg_type(newdom, "hostname", 'foo')
65
+ expect_invalid_arg_type(newdom, "hostname", [])
66
+ expect_invalid_arg_type(newdom, "hostname", {})
67
+
68
+ # FIXME: spits an error "this function is not supported by the connection driver"
69
+ #expect_success(newdom, "no args", "hostname")
70
+
71
+ newdom.destroy
72
+
73
+ # TESTGROUP: dom.metadata
74
+ newdom = conn.create_domain_xml($new_dom_xml)
75
+ sleep 1
76
+
77
+ expect_too_many_args(newdom, "metadata", 1, 2, 3, 4)
78
+ expect_too_few_args(newdom, "metadata")
79
+ expect_invalid_arg_type(newdom, "metadata", 'foo')
80
+ expect_invalid_arg_type(newdom, "metadata", nil)
81
+ expect_invalid_arg_type(newdom, "metadata", [])
82
+ expect_invalid_arg_type(newdom, "metadata", {})
83
+ expect_invalid_arg_type(newdom, "metadata", 1, 1)
84
+ expect_invalid_arg_type(newdom, "metadata", 1, 'foo', 'bar')
85
+
86
+ expect_success(newdom, "no args", "metadata", Libvirt::Domain::METADATA_DESCRIPTION) {|x| x == "Ruby Libvirt Tester"}
87
+
88
+ newdom.destroy
89
+
90
+ # TESTGROUP: dom.metadata=
91
+ newdom = conn.create_domain_xml($new_dom_xml)
92
+ sleep 1
93
+
94
+ expect_too_many_args(newdom, "metadata=", 1, 2, 3, 4, 5, 6)
95
+ expect_too_few_args(newdom, "metadata=")
96
+ expect_too_few_args(newdom, "metadata=", [1])
97
+ expect_invalid_arg_type(newdom, "metadata=", 1)
98
+ expect_invalid_arg_type(newdom, "metadata=", 'foo')
99
+ expect_invalid_arg_type(newdom, "metadata=", nil)
100
+ expect_invalid_arg_type(newdom, "metadata=", {})
101
+ expect_invalid_arg_type(newdom, "metadata=", ['foo', nil])
102
+ expect_invalid_arg_type(newdom, "metadata=", [nil, nil])
103
+ expect_invalid_arg_type(newdom, "metadata=", [[], nil])
104
+ expect_invalid_arg_type(newdom, "metadata=", [{}, nil])
105
+ expect_invalid_arg_type(newdom, "metadata=", [1, 1])
106
+ expect_invalid_arg_type(newdom, "metadata=", [1, []])
107
+ expect_invalid_arg_type(newdom, "metadata=", [1, {}])
108
+
109
+ expect_success(newdom, "no args", "metadata=", [Libvirt::Domain::METADATA_DESCRIPTION, 'foo'])
110
+ expect_success(newdom, "no args", "metadata=", [Libvirt::Domain::METADATA_DESCRIPTION, 'foo', nil, nil, 0])
111
+
112
+ expect_success(newdom, "no args", "metadata", Libvirt::Domain::METADATA_DESCRIPTION) {|x| x == "foo"}
113
+
114
+ newdom.destroy
115
+
116
+ # TESTGROUP: dom.updated?
117
+ newdom = conn.create_domain_xml($new_dom_xml)
118
+ sleep 1
119
+
120
+ expect_too_many_args(newdom, "updated?", 1)
121
+
122
+ expect_success(newdom, "no args", "updated?")
123
+
124
+ newdom.destroy
125
+
126
+ # TESTGROUP: dom.inject_nmi
127
+ newdom = conn.create_domain_xml($new_dom_xml)
128
+ sleep 1
129
+
130
+ expect_too_many_args(newdom, "inject_nmi", 1, 2)
131
+ expect_invalid_arg_type(newdom, "inject_nmi", 'foo')
132
+
133
+ expect_success(newdom, "no args", "inject_nmi")
134
+
135
+ newdom.destroy
136
+
137
+ # TESTGROUP: dom.control_info
138
+ newdom = conn.create_domain_xml($new_dom_xml)
139
+ sleep 1
140
+
141
+ expect_too_many_args(newdom, "control_info", 1, 2)
142
+ expect_invalid_arg_type(newdom, "control_info", 'foo')
143
+
144
+ expect_success(newdom, "no args", "control_info")
145
+
146
+ newdom.destroy
147
+
148
+ # TESTGROUP: dom.send_key
149
+ newdom = conn.create_domain_xml($new_dom_xml)
150
+ sleep 30
151
+
152
+ expect_too_many_args(newdom, "send_key", 1, 2, 3, 4)
153
+ expect_too_few_args(newdom, "send_key")
154
+ expect_too_few_args(newdom, "send_key", 1)
155
+ expect_too_few_args(newdom, "send_key", 1, 2)
156
+ expect_invalid_arg_type(newdom, "send_key", nil, 0, [])
157
+ expect_invalid_arg_type(newdom, "send_key", nil, 0, [1])
158
+ expect_invalid_arg_type(newdom, "send_key", 'foo', 0, [])
159
+ expect_invalid_arg_type(newdom, "send_key", 0, nil, [])
160
+ expect_invalid_arg_type(newdom, "send_key", 0, 'foo', [])
161
+ expect_invalid_arg_type(newdom, "send_key", 0, 1, nil)
162
+ expect_invalid_arg_type(newdom, "send_key", 0, 1, 'foo')
163
+ expect_invalid_arg_type(newdom, "send_key", 0, 1, 2)
164
+ expect_invalid_arg_type(newdom, "send_key", nil, 0, [nil])
165
+ expect_invalid_arg_type(newdom, "send_key", nil, 0, ['foo'])
166
+
167
+ # FIXME: this fails for reasons that are unclear to me
168
+ #expect_success(newdom, "codeset, holdtime, keycodes args", "send_key", 0, 1, [])
169
+
170
+ newdom.destroy
171
+
39
172
  # TESTGROUP: dom.migrate
40
173
  newdom = conn.create_domain_xml($new_dom_xml)
41
174
  sleep 1
@@ -94,11 +227,60 @@ expect_fail(newdom, Libvirt::Error, "while no migration in progress", "migrate_s
94
227
 
95
228
  newdom.destroy
96
229
 
230
+ # TESTGROUP: dom.migrate2
231
+ newdom = conn.create_domain_xml($new_dom_xml)
232
+ sleep 1
233
+
234
+ dconn = Libvirt::open("qemu:///system")
235
+
236
+ expect_too_many_args(newdom, "migrate2", 1, 2, 3, 4, 5, 6, 7)
237
+ expect_too_few_args(newdom, "migrate2")
238
+ expect_fail(newdom, ArgumentError, "invalid connection object", "migrate2", "foo")
239
+ expect_invalid_arg_type(newdom, "migrate2", dconn, 0)
240
+
241
+ # FIXME: how can we make this work?
242
+ #expect_success(newdom, "conn arg", "migrate2", dconn)
243
+
244
+ dconn.close
245
+
246
+ newdom.destroy
247
+
248
+ # TESTGROUP: dom.migrate_to_uri2
249
+ newdom = conn.create_domain_xml($new_dom_xml)
250
+ sleep 1
251
+
252
+ expect_too_many_args(newdom, "migrate_to_uri2", 1, 2, 3, 4, 5, 6, 7)
253
+ expect_invalid_arg_type(newdom, "migrate_to_uri2", 1)
254
+ expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 1)
255
+ expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 'foo', 1)
256
+ expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 'foo', 'bar', 'baz')
257
+ expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 'foo', 'bar', 0, 1)
258
+ expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 'foo', 'bar', 0, 'foo', 'baz')
259
+
260
+ #expect_success(newdom, "URI arg", "migrate_to_uri2", "qemu://remote/system")
261
+
262
+ dconn.close
263
+
264
+ newdom.destroy
265
+
266
+ # TESTGROUP: dom.migrate_set_max_speed
267
+ newdom = conn.create_domain_xml($new_dom_xml)
268
+ sleep 1
269
+
270
+ expect_too_many_args(newdom, "migrate_set_max_speed", 1, 2, 3)
271
+ expect_too_few_args(newdom, "migrate_set_max_speed")
272
+ expect_invalid_arg_type(newdom, "migrate_set_max_speed", 'foo')
273
+ expect_invalid_arg_type(newdom, "migrate_set_max_speed", 5, 'foo')
274
+
275
+ #expect_success(newdom, "Bandwidth arg", "migrate_set_max_speed", 5)
276
+
277
+ newdom.destroy
278
+
97
279
  # TESTGROUP: dom.shutdown
98
280
  newdom = conn.create_domain_xml($new_dom_xml)
99
281
  sleep 1
100
282
 
101
- expect_too_many_args(newdom, "shutdown", 1)
283
+ expect_too_many_args(newdom, "shutdown", 1, 2)
102
284
  expect_success(newdom, "no args", "shutdown")
103
285
  sleep 1
104
286
  newdom.destroy
@@ -109,22 +291,19 @@ sleep 1
109
291
  expect_too_many_args(newdom, "reboot", 1, 2)
110
292
  expect_invalid_arg_type(newdom, "reboot", "hello")
111
293
 
112
- # Qemu driver doesn't currently support reboot, so this is going to fail
113
- begin
114
- newdom.reboot
115
- puts_ok "dom.reboot succeeded"
116
- rescue Libvirt::Error => e
117
- puts_skipped "dom.reboot not supported, skipped"
118
- end
294
+ expect_success(newdom, "no args", "reboot")
295
+ sleep 1
119
296
 
297
+ expect_success(newdom, "flags arg", "reboot", 0)
120
298
  sleep 1
299
+
121
300
  newdom.destroy
122
301
 
123
302
  # TESTGROUP: dom.destroy
124
303
  newdom = conn.create_domain_xml($new_dom_xml)
125
304
  sleep 1
126
305
 
127
- expect_too_many_args(newdom, "destroy", 1)
306
+ expect_too_many_args(newdom, "destroy", 1, 2)
128
307
  expect_success(newdom, "no args", "destroy")
129
308
 
130
309
  # TESTGROUP: dom.suspend
@@ -147,20 +326,18 @@ expect_success(newdom, "no args suspended domain", "resume")
147
326
  newdom.destroy
148
327
 
149
328
  # TESTGROUP: dom.save
150
- newdom = conn.define_domain_xml($new_dom_xml)
151
- newdom.create
329
+ newdom = conn.create_domain_xml($new_dom_xml)
152
330
  sleep 1
153
331
 
154
- expect_too_many_args(newdom, "save", 1, 2)
332
+ expect_too_many_args(newdom, "save", 1, 2, 3, 4)
155
333
  expect_too_few_args(newdom, "save")
156
334
  expect_invalid_arg_type(newdom, "save", 1)
157
335
  expect_invalid_arg_type(newdom, "save", nil)
158
336
  expect_fail(newdom, Libvirt::Error, "non-existent path", "save", "/this/path/does/not/exist")
159
337
 
160
- expect_success(newdom, "path arg", "save", "/var/lib/libvirt/images/ruby-libvirt-test.save")
338
+ expect_success(newdom, "path arg", "save", $GUEST_SAVE)
161
339
 
162
- `rm -f /var/lib/libvirt/images/ruby-libvirt-test.save`
163
- newdom.undefine
340
+ `rm -f #{$GUEST_SAVE}`
164
341
 
165
342
  # TESTGROUP: dom.managed_save
166
343
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -170,7 +347,7 @@ sleep 1
170
347
  expect_too_many_args(newdom, "managed_save", 1, 2)
171
348
  expect_invalid_arg_type(newdom, "managed_save", "hello")
172
349
  expect_success(newdom, "no args", "managed_save")
173
- newdom.undefine
350
+ newdom.undefine(Libvirt::Domain::UNDEFINE_MANAGED_SAVE)
174
351
 
175
352
  # TESTGROUP: dom.has_managed_save?
176
353
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -181,20 +358,20 @@ expect_too_many_args(newdom, "has_managed_save?", 1, 2)
181
358
  expect_invalid_arg_type(newdom, "has_managed_save?", "hello")
182
359
 
183
360
  if newdom.has_managed_save?
184
- puts_fail "dom.has_managed_save? reports true on a new domain"
361
+ puts_fail "domain.has_managed_save? reports true on a new domain"
185
362
  else
186
- puts_ok "dom.has_managed_save? not true on new domain"
363
+ puts_ok "domain.has_managed_save? not true on new domain"
187
364
  end
188
365
 
189
366
  newdom.managed_save
190
367
 
191
368
  if not newdom.has_managed_save?
192
- puts_fail "dom.has_managed_save? reports false after a managed save"
369
+ puts_fail "domain.has_managed_save? reports false after a managed save"
193
370
  else
194
- puts_ok "dom.has_managed_save? reports true after a managed save"
371
+ puts_ok "domain.has_managed_save? reports true after a managed save"
195
372
  end
196
373
 
197
- newdom.undefine
374
+ newdom.undefine(Libvirt::Domain::UNDEFINE_MANAGED_SAVE)
198
375
 
199
376
  # TESTGROUP: dom.managed_save_remove
200
377
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -206,13 +383,13 @@ expect_too_many_args(newdom, "managed_save_remove", 1, 2)
206
383
  expect_invalid_arg_type(newdom, "managed_save_remove", "hello")
207
384
 
208
385
  if not newdom.has_managed_save?
209
- puts_fail "prior to dom.managed_save_remove, no managed save file"
386
+ puts_fail "prior to domain.managed_save_remove, no managed save file"
210
387
  end
211
388
  expect_success(newdom, "no args", "managed_save_remove")
212
389
  if newdom.has_managed_save?
213
- puts_fail "after dom.managed_save_remove, managed save file still exists"
390
+ puts_fail "after domain.managed_save_remove, managed save file still exists"
214
391
  else
215
- puts_ok "after dom.managed_save_remove, managed save file no longer exists"
392
+ puts_ok "after domain.managed_save_remove, managed save file no longer exists"
216
393
  end
217
394
 
218
395
  newdom.undefine
@@ -244,7 +421,7 @@ newdom.undefine
244
421
  newdom = conn.define_domain_xml($new_dom_xml)
245
422
  newdom.create
246
423
  sleep 1
247
- newdom.save("/var/lib/libvirt/images/ruby-libvirt-test.save")
424
+ newdom.save($GUEST_SAVE)
248
425
 
249
426
  expect_too_many_args(Libvirt::Domain, "restore", 1, 2, 3)
250
427
  expect_too_few_args(Libvirt::Domain, "restore")
@@ -255,9 +432,9 @@ expect_fail(Libvirt::Domain, Libvirt::Error, "invalid path", "restore", conn, "/
255
432
  expect_fail(Libvirt::Domain, Libvirt::Error, "invalid save file", "restore", conn, "/tmp/foo")
256
433
  `rm -f /tmp/foo`
257
434
 
258
- expect_success(Libvirt::Domain, "2 args", "restore", conn, "/var/lib/libvirt/images/ruby-libvirt-test.save")
435
+ expect_success(Libvirt::Domain, "2 args", "restore", conn, $GUEST_SAVE)
259
436
 
260
- `rm -f /var/lib/libvirt/images/ruby-libvirt-test.save`
437
+ `rm -f #{$GUEST_SAVE}`
261
438
 
262
439
  newdom.destroy
263
440
  newdom.undefine
@@ -336,12 +513,12 @@ expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "block_peek", "foo",
336
513
 
337
514
  blockpeek = newdom.block_peek($GUEST_DISK, 0, 512)
338
515
 
339
- # 51 46 49 fb are the first 4 bytes of a qcow2 image
340
- if blockpeek[0] != 0x51 or blockpeek[1] != 0x46 or blockpeek[2] != 0x49 or
341
- blockpeek[3] != 0xfb
342
- puts_fail "dom.block_peek read did not return valid data"
516
+ # 0x51 0x46 0x49 0xfb are the first 4 bytes of a qcow2 image
517
+ if blockpeek[0].unpack('C')[0] != 0x51 or blockpeek[1].unpack('C')[0] != 0x46 or
518
+ blockpeek[2].unpack('C')[0] != 0x49 or blockpeek[3].unpack('C')[0] != 0xfb
519
+ puts_fail "domain.block_peek read did not return valid data"
343
520
  else
344
- puts_ok "dom.block_peek read valid data"
521
+ puts_ok "domain.block_peek read valid data"
345
522
  end
346
523
 
347
524
  newdom.destroy
@@ -362,24 +539,22 @@ expect_success(newdom, "offset and size args", "memory_peek", 0, 512)
362
539
  newdom.destroy
363
540
 
364
541
  # TESTGROUP: dom.get_vcpus
365
- newdom = conn.create_domain_xml($new_dom_xml)
366
- sleep 1
367
-
368
542
  expect_too_many_args(newdom, "get_vcpus", 1)
369
543
 
370
- expect_success(newdom, "no args", "get_vcpus") {|x| x.length == 2}
544
+ newdom = conn.define_domain_xml($new_dom_xml)
371
545
 
372
- newdom.destroy
546
+ expect_success(newdom, "get_vcpus on shutoff domain", "get_vcpus") {|x| x.length == 2}
373
547
 
374
- # TESTGROUP: dom.active?
375
- newdom = conn.create_domain_xml($new_dom_xml)
548
+ newdom.create
376
549
  sleep 1
377
550
 
378
- expect_too_many_args(newdom, "active?", 1)
379
-
380
- expect_success(newdom, "no args", "active?") {|x| x == true}
551
+ expect_success(newdom, "no args", "get_vcpus") {|x| x.length == 2}
381
552
 
382
553
  newdom.destroy
554
+ newdom.undefine
555
+
556
+ # TESTGROUP: dom.active?
557
+ expect_too_many_args(newdom, "active?", 1)
383
558
 
384
559
  newdom = conn.define_domain_xml($new_dom_xml)
385
560
 
@@ -479,15 +654,7 @@ expect_too_many_args(newdom, "max_memory=", 1, 2)
479
654
  expect_too_few_args(newdom, "max_memory=")
480
655
  expect_invalid_arg_type(newdom, "max_memory=", 'foo')
481
656
 
482
- begin
483
- newdom.max_memory = 200000
484
- puts_ok "dom.max_memory= succeded"
485
- rescue NoMethodError
486
- puts_skipped "dom.max_memory does not exist"
487
- rescue Libvirt::DefinitionError => e
488
- # dom.max_memory is not supported by Qemu; skip
489
- puts_skipped "dom.max_memory not supported by connection driver"
490
- end
657
+ expect_success(newdom, "memory arg", "max_memory=", 200000)
491
658
 
492
659
  newdom.undefine
493
660
 
@@ -495,10 +662,11 @@ newdom.undefine
495
662
  newdom = conn.define_domain_xml($new_dom_xml)
496
663
 
497
664
  expect_too_many_args(newdom, "memory=", 1, 2)
665
+ expect_too_many_args(newdom, "memory=", [1, 2, 3])
498
666
  expect_too_few_args(newdom, "memory=")
667
+ expect_too_few_args(newdom, "memory=", [])
499
668
  expect_invalid_arg_type(newdom, "memory=", 'foo')
500
-
501
- expect_fail(newdom, Libvirt::Error, "shutoff domain", "memory=", 2)
669
+ expect_fail(newdom, Libvirt::Error, "shutoff domain", "memory=", [2, Libvirt::Domain::AFFECT_LIVE])
502
670
 
503
671
  newdom.undefine
504
672
 
@@ -523,18 +691,18 @@ newdom.destroy
523
691
  newdom = conn.define_domain_xml($new_dom_xml)
524
692
 
525
693
  expect_too_many_args(newdom, "vcpus=", 1, 2)
694
+ expect_too_many_args(newdom, "vcpus=", [0, 1, 2])
526
695
  expect_too_few_args(newdom, "vcpus=")
696
+ expect_too_few_args(newdom, "vcpus=", [])
527
697
  expect_invalid_arg_type(newdom, "vcpus=", 'foo')
528
-
529
- expect_fail(newdom, Libvirt::Error, "shutoff domain", "vcpus=", 2)
698
+ expect_fail(newdom, Libvirt::Error, "shutoff domain", "vcpus=", [2, Libvirt::Domain::AFFECT_LIVE])
530
699
 
531
700
  newdom.undefine
532
701
 
533
702
  newdom = conn.create_domain_xml($new_dom_xml)
534
703
  sleep 1
535
704
 
536
- # FIXME: this kills the domain for some reason
537
- #expect_success(newdom, "number arg", "vcpus=", 2)
705
+ expect_success(newdom, "number arg", "vcpus=", 2)
538
706
 
539
707
  newdom.destroy
540
708
 
@@ -542,7 +710,7 @@ newdom.destroy
542
710
  newdom = conn.create_domain_xml($new_dom_xml)
543
711
  sleep 1
544
712
 
545
- expect_too_many_args(newdom, "pin_vcpu", 1, 2, 3)
713
+ expect_too_many_args(newdom, "pin_vcpu", 1, 2, 3, 4)
546
714
  expect_too_few_args(newdom, "pin_vcpu")
547
715
  expect_invalid_arg_type(newdom, "pin_vcpu", 'foo', [0])
548
716
  expect_invalid_arg_type(newdom, "pin_vcpu", 0, 1)
@@ -565,7 +733,7 @@ newdom.destroy
565
733
  # TESTGROUP: dom.undefine
566
734
  newdom = conn.define_domain_xml($new_dom_xml)
567
735
 
568
- expect_too_many_args(newdom, "undefine", 1)
736
+ expect_too_many_args(newdom, "undefine", 1, 2)
569
737
 
570
738
  expect_success(newdom, "no args", "undefine")
571
739
 
@@ -605,16 +773,16 @@ expect_invalid_arg_type(newdom, "autostart=", 1234)
605
773
 
606
774
  expect_success(newdom, "true arg", "autostart=", true)
607
775
  if not newdom.autostart?
608
- puts_fail "dom.autostart= did not set autostart to true"
776
+ puts_fail "domain.autostart= did not set autostart to true"
609
777
  else
610
- puts_ok "dom.autostart= set autostart to true"
778
+ puts_ok "domain.autostart= set autostart to true"
611
779
  end
612
780
 
613
781
  expect_success(newdom, "false arg", "autostart=", false)
614
782
  if newdom.autostart?
615
- puts_fail "dom.autostart= did not set autostart to false"
783
+ puts_fail "domain.autostart= did not set autostart to false"
616
784
  else
617
- puts_ok "dom.autostart= set autostart to false"
785
+ puts_ok "domain.autostart= set autostart to false"
618
786
  end
619
787
 
620
788
  newdom.undefine
@@ -681,8 +849,7 @@ newdom = conn.define_domain_xml($new_dom_xml)
681
849
  newdom.undefine
682
850
  expect_too_many_args(newdom, "free", 1)
683
851
 
684
- newdom.free
685
- puts_ok "dom.free succeeded"
852
+ expect_success(newdom, "free", "free")
686
853
 
687
854
  # TESTGROUP: dom.snapshot_create_xml
688
855
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -697,12 +864,12 @@ expect_success(newdom, "simple XML arg", "snapshot_create_xml", "<domainsnapshot
697
864
 
698
865
  snaps = newdom.num_of_snapshots
699
866
  if snaps != 1
700
- puts_fail "dom.snapshot_create_xml after one snapshot has #{snaps} snapshots"
867
+ puts_fail "domain.snapshot_create_xml after one snapshot has #{snaps} snapshots"
701
868
  else
702
- puts_ok "dom.snapshot_create_xml after one snapshot has 1 snapshot"
869
+ puts_ok "domain.snapshot_create_xml after one snapshot has 1 snapshot"
703
870
  end
704
871
 
705
- newdom.undefine
872
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
706
873
 
707
874
  # TESTGROUP: dom.num_of_snapshots
708
875
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -716,7 +883,7 @@ newdom.snapshot_create_xml("<domainsnapshot/>")
716
883
 
717
884
  expect_success(newdom, "no args", "num_of_snapshots") {|x| x == 1}
718
885
 
719
- newdom.undefine
886
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
720
887
 
721
888
  # TESTGROUP: dom.list_snapshots
722
889
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -730,7 +897,7 @@ newdom.snapshot_create_xml("<domainsnapshot/>")
730
897
 
731
898
  expect_success(newdom, "no args", "list_snapshots") {|x| x.length == 1}
732
899
 
733
- newdom.undefine
900
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
734
901
 
735
902
  # TESTGROUP: dom.lookup_snapshot_by_name
736
903
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -743,7 +910,7 @@ expect_invalid_arg_type(newdom, "lookup_snapshot_by_name", 'foo', 'bar')
743
910
 
744
911
  expect_success(newdom, "name arg", "lookup_snapshot_by_name", "foo")
745
912
 
746
- newdom.undefine
913
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
747
914
 
748
915
  # TESTGROUP: dom.has_current_snapshot?
749
916
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -757,7 +924,7 @@ newdom.snapshot_create_xml("<domainsnapshot><name>foo</name></domainsnapshot>")
757
924
 
758
925
  expect_success(newdom, "no args", "has_current_snapshot?") {|x| x == true}
759
926
 
760
- newdom.undefine
927
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
761
928
 
762
929
  # TESTGROUP: dom.revert_to_snapshot
763
930
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -775,7 +942,7 @@ expect_invalid_arg_type(newdom, "revert_to_snapshot", snap, 'foo')
775
942
 
776
943
  expect_success(newdom, "snapshot arg", "revert_to_snapshot", snap)
777
944
 
778
- newdom.undefine
945
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
779
946
 
780
947
  # TESTGROUP: dom.current_snapshot
781
948
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -788,36 +955,7 @@ newdom.snapshot_create_xml("<domainsnapshot><name>foo</name></domainsnapshot>")
788
955
 
789
956
  expect_success(newdom, "no args", "current_snapshot")
790
957
 
791
- newdom.undefine
792
-
793
- # TESTGROUP: snapshot.xml_desc
794
- newdom = conn.define_domain_xml($new_dom_xml)
795
- snap = newdom.snapshot_create_xml("<domainsnapshot/>")
796
-
797
- expect_too_many_args(snap, "xml_desc", 1, 2)
798
- expect_invalid_arg_type(snap, "xml_desc", 'foo')
799
-
800
- expect_success(newdom, "no args", "xml_desc")
801
-
802
- newdom.undefine
803
-
804
- # TESTGROUP: snapshot.delete
805
- newdom = conn.define_domain_xml($new_dom_xml)
806
- snap = newdom.snapshot_create_xml("<domainsnapshot/>")
807
-
808
- expect_too_many_args(snap, "delete", 1, 2)
809
- expect_invalid_arg_type(snap, "delete", 'foo')
810
-
811
- expect_success(snap, "no args", "delete")
812
-
813
- newdom.undefine
814
-
815
- # TESTGROUP: snapshot.free
816
- newdom = conn.define_domain_xml($new_dom_xml)
817
- newdom.undefine
818
- expect_too_many_args(newdom, "free", 1)
819
-
820
- expect_success(newdom, "no args", "free")
958
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
821
959
 
822
960
  # TESTGROUP: dom.job_info
823
961
  newdom = conn.define_domain_xml($new_dom_xml)
@@ -859,32 +997,16 @@ newdom = conn.define_domain_xml($new_dom_xml)
859
997
 
860
998
  expect_too_many_args(newdom, "scheduler_type", 1)
861
999
 
862
- begin
863
- newdom.scheduler_type
864
- puts_ok "dom.scheduler_type succeeded"
865
- rescue NoMethodError
866
- puts_skipped "dom.scheduler_type does not exist"
867
- rescue Libvirt::RetrieveError
868
- # this may not be supported (if cgroups aren't configured), so skip it
869
- puts_skipped "dom.scheduler_type not supported"
870
- end
1000
+ expect_success(newdom, "no args", "scheduler_type")
871
1001
 
872
1002
  newdom.undefine
873
1003
 
874
1004
  # TESTGROUP: dom.scheduler_parameters
875
1005
  newdom = conn.define_domain_xml($new_dom_xml)
876
1006
 
877
- expect_too_many_args(newdom, "scheduler_parameters", 1)
1007
+ expect_too_many_args(newdom, "scheduler_parameters", 1, 1)
878
1008
 
879
- begin
880
- newdom.scheduler_parameters
881
- puts_ok "dom.scheduler_parameters succeeded"
882
- rescue NoMethodError
883
- puts_skipped "dom.scheduler_parameters does not exist"
884
- rescue Libvirt::RetrieveError
885
- # this may not be supported (if cgroups aren't configured), so skip it
886
- puts_ok "dom.scheduler_parameters not supported"
887
- end
1009
+ expect_success(newdom, "no args", "scheduler_parameters")
888
1010
 
889
1011
  newdom.undefine
890
1012
 
@@ -895,14 +1017,7 @@ expect_too_many_args(newdom, "scheduler_parameters=", 1, 2)
895
1017
  expect_too_few_args(newdom, "scheduler_parameters=")
896
1018
  expect_invalid_arg_type(newdom, "scheduler_parameters=", 0)
897
1019
 
898
- begin
899
- newdom.scheduler_parameters={"cpu_shares"=>512}
900
- rescue NoMethodError
901
- puts_skipped "dom.scheduler_parameters= does not exist"
902
- rescue Libvirt::RetrieveError
903
- # this may not be supported (if cgroups aren't configured), so skip it
904
- puts_ok "dom.scheduler_parameters= not supported"
905
- end
1020
+ expect_success(newdom, "cpu shares arg", "scheduler_parameters=", {"cpu_shares" => 512})
906
1021
 
907
1022
  newdom.undefine
908
1023
 
@@ -942,11 +1057,12 @@ expect_too_many_args(newdom, "qemu_monitor_command", 1, 2, 3)
942
1057
  expect_too_few_args(newdom, "qemu_monitor_command")
943
1058
  expect_invalid_arg_type(newdom, "qemu_monitor_command", 1)
944
1059
  expect_invalid_arg_type(newdom, "qemu_monitor_command", "foo", "bar")
945
- testconn = Libvirt::open("test:///default")
946
- fakedom = testconn.create_domain_xml(new_test_xml)
947
- expect_invalid_arg_type(fakedom, "qemu_monitor_command", "foo")
948
- fakedom.destroy
949
- testconn.close
1060
+ # FIXME: the test driver doesn't support virDomainDestroyFlags() presently
1061
+ #testconn = Libvirt::open("test:///default")
1062
+ #fakedom = testconn.create_domain_xml(new_test_xml)
1063
+ #expect_invalid_arg_type(fakedom, "qemu_monitor_command", "foo")
1064
+ #fakedom.destroy
1065
+ #testconn.close
950
1066
  expect_fail(newdom, Libvirt::RetrieveError, "invalid command", "qemu_monitor_command", "foo")
951
1067
 
952
1068
  expect_success(newdom, "monitor command", "qemu_monitor_command", '{"execute":"query-cpus"}')
@@ -959,7 +1075,6 @@ newdom = conn.define_domain_xml($new_dom_xml)
959
1075
  expect_too_many_args(newdom, "num_vcpus", 1, 2)
960
1076
  expect_too_few_args(newdom, "num_vcpus")
961
1077
  expect_invalid_arg_type(newdom, "num_vcpus", 'foo')
962
- expect_fail(newdom, Libvirt::Error, "zero flags", "num_vcpus", 0)
963
1078
  expect_fail(newdom, Libvirt::Error, "active flag on shutoff domain", "num_vcpus", Libvirt::Domain::VCPU_LIVE)
964
1079
  expect_fail(newdom, Libvirt::Error, "live and config flags", "num_vcpus", Libvirt::Domain::VCPU_LIVE | Libvirt::Domain::VCPU_CONFIG)
965
1080
  expect_success(newdom, "config flag", "num_vcpus", Libvirt::Domain::VCPU_CONFIG) {|x| x == 2}
@@ -969,55 +1084,27 @@ newdom.undefine
969
1084
  newdom = conn.create_domain_xml($new_dom_xml)
970
1085
  sleep 1
971
1086
 
972
- expect_success(newdom, "config flag on transient domain", "num_vcpus", Libvirt::Domain::VCPU_CONFIG)
1087
+ expect_fail(newdom, Libvirt::RetrieveError, "config flag on transient domain", "num_vcpus", Libvirt::Domain::VCPU_CONFIG)
973
1088
  expect_success(newdom, "live flag on transient domain", "num_vcpus", Libvirt::Domain::VCPU_LIVE)
974
1089
 
975
1090
  newdom.destroy
976
1091
 
977
1092
  # TESTGROUP: dom.vcpus_flags=
978
- newdom = conn.define_domain_xml($new_dom_xml)
979
-
980
- expect_too_many_args(newdom, "vcpus_flags=", 1, 2, 3)
981
- expect_too_few_args(newdom, "vcpus_flags=")
982
- expect_invalid_arg_type(newdom, "vcpus_flags=", 1)
983
- expect_invalid_arg_type(newdom, "vcpus_flags=", ['foo', 2])
984
- expect_invalid_arg_type(newdom, "vcpus_flags=", [2, 'foo'])
985
- expect_fail(newdom, Libvirt::Error, "zero flags", "vcpus_flags=", [2, 0])
986
- expect_fail(newdom, Libvirt::Error, "zero vcpus", "vcpus_flags=", [0, Libvirt::Domain::VCPU_CONFIG])
987
- expect_fail(newdom, Libvirt::Error, "live vcpu on shutoff domain", "vcpus_flags=", [2, Libvirt::Domain::VCPU_LIVE])
988
- expect_success(newdom, "2 vcpu config", "vcpus_flags=", [2, Libvirt::Domain::VCPU_CONFIG])
989
-
990
- newdom.undefine
991
-
992
- newdom = conn.create_domain_xml($new_dom_xml)
993
- sleep 1
994
-
995
- expect_fail(newdom, Libvirt::Error, "vcpu config on transient domain", "vcpus_flags=", [2, Libvirt::Domain::VCPU_CONFIG])
996
- expect_fail(newdom, Libvirt::Error, "too many vcpus", "vcpus_flags=", [4, Libvirt::Domain::VCPU_LIVE])
997
-
998
- # FIXME: this doesn't work for some reason
999
- #expect_success(newdom, "vcpus to 1", "vcpus_flags=", [1, Libvirt::Domain::VCPU_LIVE])
1000
-
1001
- newdom.destroy
1093
+ # dom.vcpus_flags= is deprecated in favor of dom.vcpus=, so we don't do any
1094
+ # tests here for it
1002
1095
 
1003
1096
  # TESTGROUP: dom.memory_parameters=
1004
1097
  newdom = conn.define_domain_xml($new_dom_xml)
1005
1098
 
1006
1099
  expect_too_many_args(newdom, "memory_parameters=", 1, 2, 3)
1100
+ expect_too_many_args(newdom, "memory_parameters=", [1, 2, 3])
1007
1101
  expect_too_few_args(newdom, "memory_parameters=")
1102
+ expect_too_few_args(newdom, "memory_parameters=", [])
1008
1103
  expect_invalid_arg_type(newdom, "memory_parameters=", 0)
1009
- expect_fail(newdom, ArgumentError, "empty array", "memory_parameters=", [])
1010
1104
  expect_invalid_arg_type(newdom, "memory_parameters=", [1, 0])
1011
1105
  expect_invalid_arg_type(newdom, "memory_parameters=", [{}, "foo"])
1012
1106
 
1013
- begin
1014
- newdom.memory_parameters={"soft_limit" => 9007199254740999, "swap_hard_limit" => 9007199254740999}
1015
- rescue NoMethodError
1016
- puts_skipped "dom.memory_parameters= does not exist"
1017
- rescue Libvirt::RetrieveError
1018
- # this may not be supported (if cgroups aren't configured), so skip it
1019
- puts_skipped "memory_parameters= not supported"
1020
- end
1107
+ expect_success(newdom, "soft and hard limit", "memory_parameters=", {"soft_limit" => 9007199254740999, "swap_hard_limit" => 9007199254740999})
1021
1108
 
1022
1109
  newdom.undefine
1023
1110
 
@@ -1026,15 +1113,7 @@ newdom = conn.define_domain_xml($new_dom_xml)
1026
1113
 
1027
1114
  expect_too_many_args(newdom, "memory_parameters", 1, 2)
1028
1115
 
1029
- begin
1030
- newdom.memory_parameters
1031
- puts_ok "dom.memory_parameters succeeded"
1032
- rescue NoMethodError
1033
- puts_skipped "memory_parameters does not exist"
1034
- rescue Libvirt::RetrieveError
1035
- # this may not be supported (if cgroups aren't configured), so skip it
1036
- puts_skipped "memory_parameters not supported"
1037
- end
1116
+ expect_success(newdom, "no args", "memory_parameters")
1038
1117
 
1039
1118
  newdom.undefine
1040
1119
 
@@ -1042,20 +1121,14 @@ newdom.undefine
1042
1121
  newdom = conn.define_domain_xml($new_dom_xml)
1043
1122
 
1044
1123
  expect_too_many_args(newdom, "blkio_parameters=", 1, 2, 3)
1124
+ expect_too_many_args(newdom, "blkio_parameters=", [1, 2, 3])
1045
1125
  expect_too_few_args(newdom, "blkio_parameters=")
1126
+ expect_too_few_args(newdom, "blkio_parameters=", [])
1046
1127
  expect_invalid_arg_type(newdom, "blkio_parameters=", 0)
1047
- expect_fail(newdom, ArgumentError, "empty array", "blkio_parameters=", [])
1048
1128
  expect_invalid_arg_type(newdom, "blkio_parameters=", [1, 0])
1049
1129
  expect_invalid_arg_type(newdom, "blkio_parameters=", [{}, "foo"])
1050
1130
 
1051
- begin
1052
- newdom.blkio_parameters={"weight" => 1}
1053
- rescue NoMethodError
1054
- puts_skipped "blkio_parameters= does not exist"
1055
- rescue Libvirt::RetrieveError
1056
- # this may not be supported (if cgroups aren't configured), so skip it
1057
- puts_skipped "blkio_parameters= not supported"
1058
- end
1131
+ expect_success(newdom, "hash", "blkio_parameters=", {"weight" => 100})
1059
1132
 
1060
1133
  newdom.undefine
1061
1134
 
@@ -1064,20 +1137,12 @@ newdom = conn.define_domain_xml($new_dom_xml)
1064
1137
 
1065
1138
  expect_too_many_args(newdom, "blkio_parameters", 1, 2)
1066
1139
 
1067
- begin
1068
- newdom.blkio_parameters
1069
- puts_ok "dom.blkio_parameters succeeded"
1070
- rescue NoMethodError
1071
- puts_skipped "blkio_parameters does not exist"
1072
- rescue Libvirt::RetrieveError
1073
- # this may not be supported (if cgroups aren't configured), so skip it
1074
- puts_skipped "blkio_parameters not supported"
1075
- end
1140
+ expect_success(newdom, "no args", "blkio_parameters")
1076
1141
 
1077
1142
  newdom.undefine
1078
1143
 
1079
1144
  # TESTGROUP: dom.open_console
1080
- newdom = conn.create_domain_xml(new_dom_xml)
1145
+ newdom = conn.create_domain_xml($new_dom_xml)
1081
1146
  stream = conn.stream
1082
1147
 
1083
1148
  expect_too_many_args(newdom, "open_console", 1, 2, 3, 4)
@@ -1087,10 +1152,289 @@ expect_invalid_arg_type(newdom, "open_console", 1, stream)
1087
1152
  expect_invalid_arg_type(newdom, "open_console", "pty", 1)
1088
1153
  expect_invalid_arg_type(newdom, "open_console", "pty", stream, "wow")
1089
1154
 
1090
- expect_success(newdom, "device and stream args", "open_console", "pty", stream)
1155
+ #expect_success(newdom, "device and stream args", "open_console", "pty", stream)
1156
+
1157
+ newdom.destroy
1158
+
1159
+ # TESTGROUP: dom.block_rebase
1160
+ newdom = conn.create_domain_xml($new_dom_xml)
1161
+
1162
+ expect_too_many_args(newdom, "block_rebase", 1, 2, 3, 4, 5)
1163
+ expect_too_few_args(newdom, "block_rebase")
1164
+ expect_invalid_arg_type(newdom, "block_rebase", 1)
1165
+ expect_invalid_arg_type(newdom, "block_rebase", "foo", 1)
1166
+ expect_invalid_arg_type(newdom, "block_rebase", "foo", "bar", "baz")
1167
+ expect_invalid_arg_type(newdom, "block_rebase", "foo", "bar", 1, "boom")
1168
+
1169
+ # FIXME: I don't know how to make block_rebase work
1170
+ #expect_success(newdom, "disk", "block_rebase", diskname)
1171
+
1172
+ newdom.destroy
1173
+
1174
+ # TESTGROUP: dom.migrate_max_downtime=
1175
+ newdom = conn.define_domain_xml($new_dom_xml)
1176
+
1177
+ expect_too_many_args(newdom, "migrate_max_downtime=", 1, 2)
1178
+ expect_too_many_args(newdom, "migrate_max_downtime=", [1, 2, 3])
1179
+ expect_too_few_args(newdom, "migrate_max_downtime=")
1180
+ expect_too_few_args(newdom, "migrate_max_downtime=", [])
1181
+ expect_invalid_arg_type(newdom, "migrate_max_downtime=", 'foo')
1182
+ expect_invalid_arg_type(newdom, "migrate_max_downtime=", nil)
1183
+ expect_fail(newdom, Libvirt::Error, "on off domain", "migrate_max_downtime=", 10)
1184
+ expect_fail(newdom, Libvirt::Error, "on off domain, two args", "migrate_max_downtime=", [10, 10])
1185
+
1186
+ newdom.undefine
1187
+
1188
+ newdom = conn.create_domain_xml($new_dom_xml)
1189
+ sleep 1
1190
+ expect_fail(newdom, Libvirt::Error, "while no migration in progress", "migrate_max_downtime=", 10)
1191
+
1192
+ # FIXME: get this working
1193
+ #newdom.migrate_to_uri("qemu://remote/system")
1194
+ #expect_success(newdom, "10 second downtime", "migrate_max_downtime=", 10)
1195
+
1196
+ newdom.destroy
1197
+
1198
+ # TESTGROUP: dom.migrate_max_speed=
1199
+ newdom = conn.create_domain_xml($new_dom_xml)
1200
+ sleep 1
1201
+
1202
+ expect_too_many_args(newdom, "migrate_max_speed=", 1, 2)
1203
+ expect_too_many_args(newdom, "migrate_max_speed=", [1, 2, 3])
1204
+ expect_too_few_args(newdom, "migrate_max_speed=")
1205
+ expect_too_few_args(newdom, "migrate_max_speed=", [])
1206
+ expect_invalid_arg_type(newdom, "migrate_max_speed=", 'foo')
1207
+ expect_invalid_arg_type(newdom, "migrate_max_speed=", nil)
1208
+ expect_invalid_arg_type(newdom, "migrate_max_speed=", ['foo', 1])
1209
+ expect_invalid_arg_type(newdom, "migrate_max_speed=", [1, 'foo'])
1210
+
1211
+ #expect_success(newdom, "Bandwidth arg", "migrate_max_speed=", 5)
1212
+
1213
+ newdom.destroy
1214
+
1215
+ # TESTGROUP: dom.state
1216
+ newdom = conn.create_domain_xml($new_dom_xml)
1217
+ sleep 1
1218
+
1219
+ expect_too_many_args(newdom, "state", 1, 2)
1220
+ expect_invalid_arg_type(newdom, "state", 'foo')
1221
+
1222
+ expect_success(newdom, "no arg", "state")
1091
1223
 
1092
1224
  newdom.destroy
1093
1225
 
1226
+ # TESTGROUP: dom.screenshot
1227
+ newdom = conn.create_domain_xml($new_dom_xml)
1228
+ sleep 1
1229
+
1230
+ stream = conn.stream
1231
+
1232
+ expect_too_many_args(newdom, "screenshot", 1, 2, 3, 4)
1233
+ expect_too_few_args(newdom, "screenshot")
1234
+ expect_too_few_args(newdom, "screenshot", stream)
1235
+ expect_invalid_arg_type(newdom, "screenshot", 1, 0)
1236
+ expect_invalid_arg_type(newdom, "screenshot", nil, 0)
1237
+ expect_invalid_arg_type(newdom, "screenshot", stream, nil)
1238
+ expect_invalid_arg_type(newdom, "screenshot", stream, 'foo')
1239
+ expect_invalid_arg_type(newdom, "screenshot", stream, 0, 'foo')
1240
+
1241
+ expect_success(newdom, "stream and screen arg", "screenshot", stream, 0)
1242
+
1243
+ newdom.destroy
1244
+
1245
+ # TESTGROUP: dom.vcpus_flags=
1246
+ newdom = conn.define_domain_xml($new_dom_xml)
1247
+
1248
+ expect_too_many_args(newdom, "vcpus_flags=", 1, 2)
1249
+ expect_too_many_args(newdom, "vcpus_flags=", [0, 1, 2])
1250
+ expect_too_few_args(newdom, "vcpus_flags=")
1251
+ expect_too_few_args(newdom, "vcpus_flags=", [])
1252
+ expect_invalid_arg_type(newdom, "vcpus_flags=", 'foo')
1253
+ expect_fail(newdom, Libvirt::Error, "shutoff domain", "vcpus_flags=", [2, Libvirt::Domain::AFFECT_LIVE])
1254
+
1255
+ newdom.undefine
1256
+
1257
+ newdom = conn.create_domain_xml($new_dom_xml)
1258
+ sleep 1
1259
+
1260
+ expect_success(newdom, "number arg", "vcpus_flags=", 2)
1261
+
1262
+ newdom.destroy
1263
+
1264
+ # TESTGROUP: domain.list_all_snapshots
1265
+ newdom = conn.define_domain_xml($new_dom_xml)
1266
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1267
+
1268
+ expect_too_many_args(newdom, "list_all_snapshots", 1, 2)
1269
+ expect_invalid_arg_type(newdom, "list_all_snapshots", 'foo')
1270
+
1271
+ expect_success(newdom, "no args", "list_all_snapshots")
1272
+
1273
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1274
+ sleep 1
1275
+
1276
+ # TESTGROUP: domain.open_graphics
1277
+ newdom = conn.create_domain_xml($new_dom_xml)
1278
+ sleep 1
1279
+
1280
+ expect_too_many_args(newdom, "open_graphics", 1, 2, 3, 4)
1281
+ expect_too_few_args(newdom, "open_graphics")
1282
+ expect_invalid_arg_type(newdom, "open_graphics", nil)
1283
+ expect_invalid_arg_type(newdom, "open_graphics", 'foo')
1284
+ expect_invalid_arg_type(newdom, "open_graphics", [])
1285
+ expect_invalid_arg_type(newdom, "open_graphics", {})
1286
+ expect_invalid_arg_type(newdom, "open_graphics", 4, 'foo')
1287
+ expect_invalid_arg_type(newdom, "open_graphics", 4, [])
1288
+ expect_invalid_arg_type(newdom, "open_graphics", 4, {})
1289
+ expect_invalid_arg_type(newdom, "open_graphics", 4, 0, 'foo')
1290
+ expect_invalid_arg_type(newdom, "open_graphics", 4, 0, [])
1291
+ expect_invalid_arg_type(newdom, "open_graphics", 4, 0, {})
1292
+
1293
+ #expect_success(newdom, "fd arg", "open_graphics", fd)
1294
+
1295
+ set_test_object("snapshot")
1296
+
1297
+ # TESTGROUP: snapshot.xml_desc
1298
+ newdom = conn.define_domain_xml($new_dom_xml)
1299
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1300
+
1301
+ expect_too_many_args(snap, "xml_desc", 1, 2)
1302
+ expect_invalid_arg_type(snap, "xml_desc", 'foo')
1303
+
1304
+ expect_success(newdom, "no args", "xml_desc")
1305
+
1306
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1307
+ sleep 1
1308
+
1309
+ # TESTGROUP: snapshot.delete
1310
+ newdom = conn.define_domain_xml($new_dom_xml)
1311
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1312
+
1313
+ expect_too_many_args(snap, "delete", 1, 2)
1314
+ expect_invalid_arg_type(snap, "delete", 'foo')
1315
+
1316
+ expect_success(snap, "no args", "delete")
1317
+
1318
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1319
+ sleep 1
1320
+
1321
+ # TESTGROUP: snapshot.name
1322
+ newdom = conn.define_domain_xml($new_dom_xml)
1323
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1324
+
1325
+ expect_too_many_args(snap, "name", 1)
1326
+
1327
+ expect_success(snap, "no args", "name")
1328
+
1329
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1330
+ sleep 1
1331
+
1332
+ # TESTGROUP: snapshot.num_children
1333
+ newdom = conn.define_domain_xml($new_dom_xml)
1334
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1335
+
1336
+ expect_too_many_args(snap, "num_children", 1, 2)
1337
+
1338
+ expect_success(snap, "no args, no children", "num_children") {|x| x == 0}
1339
+
1340
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1341
+ sleep 1
1342
+
1343
+ # TESTGROUP: snapshot.list_children_names
1344
+ newdom = conn.define_domain_xml($new_dom_xml)
1345
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1346
+
1347
+ expect_too_many_args(snap, "list_children_names", 1, 2)
1348
+
1349
+ expect_success(snap, "no args, no children", "num_children") {|x| x == 0}
1350
+
1351
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1352
+ sleep 1
1353
+
1354
+ # TESTGROUP: snapshot.free
1355
+ newdom = conn.define_domain_xml($new_dom_xml)
1356
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1357
+
1358
+ expect_too_many_args(snap, "free", 1)
1359
+
1360
+ expect_success(snap, "no args", "free")
1361
+
1362
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1363
+ sleep 1
1364
+
1365
+ # TESTGROUP: snapshot.has_metadata?
1366
+ newdom = conn.define_domain_xml($new_dom_xml)
1367
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1368
+
1369
+ expect_too_many_args(snap, "has_metadata?", 1, 2)
1370
+ expect_invalid_arg_type(snap, "has_metadata?", "foo")
1371
+
1372
+ expect_success(snap, "no args", "has_metadata?") {|x| x == true}
1373
+
1374
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1375
+ sleep 1
1376
+
1377
+ # TESTGROUP: snapshot.list_children_names
1378
+ newdom = conn.define_domain_xml($new_dom_xml)
1379
+ snap = newdom.snapshot_create_xml("<domainsnapshot><name>snap</name></domainsnapshot>")
1380
+ snap2 = newdom.snapshot_create_xml("<domainsnapshot><name>snap2</name></domainsnapshot>")
1381
+
1382
+ expect_too_many_args(snap, "list_children_names", 1, 2)
1383
+ expect_invalid_arg_type(snap, "list_children_names", "foo")
1384
+ expect_invalid_arg_type(snap, "list_children_names", [])
1385
+ expect_invalid_arg_type(snap, "list_children_names", {})
1386
+
1387
+ expect_success(snap, "no args", "list_children_names")
1388
+
1389
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1390
+ sleep 1
1391
+
1392
+ # TESTGROUP: snapshot.list_all_children
1393
+ newdom = conn.define_domain_xml($new_dom_xml)
1394
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1395
+
1396
+ expect_too_many_args(snap, "list_all_children", 1, 2)
1397
+ expect_invalid_arg_type(snap, "list_all_children", "foo")
1398
+ expect_invalid_arg_type(snap, "list_all_children", [])
1399
+ expect_invalid_arg_type(snap, "list_all_children", {})
1400
+
1401
+ expect_success(snap, "no args", "list_all_children")
1402
+
1403
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1404
+ sleep 1
1405
+
1406
+ # TESTGROUP: snapshot.parent
1407
+ newdom = conn.define_domain_xml($new_dom_xml)
1408
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1409
+ snap2 = newdom.snapshot_create_xml("<domainsnapshot/>")
1410
+
1411
+ expect_too_many_args(snap2, "parent", 1, 2)
1412
+ expect_invalid_arg_type(snap2, "parent", "foo")
1413
+ expect_invalid_arg_type(snap2, "parent", [])
1414
+ expect_invalid_arg_type(snap2, "parent", {})
1415
+
1416
+ expect_success(snap2, "no args", "parent")
1417
+ expect_success(snap, "no args", "parent")
1418
+
1419
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1420
+ sleep 1
1421
+
1422
+ # TESTGROUP: snapshot.current?
1423
+ newdom = conn.define_domain_xml($new_dom_xml)
1424
+ snap = newdom.snapshot_create_xml("<domainsnapshot/>")
1425
+
1426
+ expect_too_many_args(snap, "current?", 1, 2)
1427
+ expect_invalid_arg_type(snap, "current?", "foo")
1428
+ expect_invalid_arg_type(snap, "current?", [])
1429
+ expect_invalid_arg_type(snap, "current?", {})
1430
+
1431
+ expect_success(snap, "no args", "current?")
1432
+
1433
+ newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA)
1434
+ sleep 1
1435
+
1436
+ # END TESTS
1437
+
1094
1438
  conn.close
1095
1439
 
1096
1440
  finish_tests