virtualbox 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/Readme.md +5 -21
- data/VERSION +1 -1
- data/docs/WhatsNew.md +9 -47
- data/lib/virtualbox.rb +7 -30
- data/lib/virtualbox/abstract_model.rb +25 -5
- data/lib/virtualbox/abstract_model/attributable.rb +5 -1
- data/lib/virtualbox/abstract_model/dirty.rb +2 -0
- data/lib/virtualbox/abstract_model/interface_attributes.rb +96 -0
- data/lib/virtualbox/abstract_model/relatable.rb +19 -8
- data/lib/virtualbox/appliance.rb +59 -0
- data/lib/virtualbox/audio_adapter.rb +44 -0
- data/lib/virtualbox/bios.rb +44 -0
- data/lib/virtualbox/com.rb +23 -0
- data/lib/virtualbox/com/abstract_enum.rb +42 -0
- data/lib/virtualbox/com/abstract_implementer.rb +43 -0
- data/lib/virtualbox/com/abstract_interface.rb +165 -0
- data/lib/virtualbox/com/ffi/interface.rb +141 -0
- data/lib/virtualbox/com/ffi/interfaces.rb +42 -0
- data/lib/virtualbox/com/ffi/util.rb +101 -0
- data/lib/virtualbox/com/ffi/vboxxpcomc.rb +31 -0
- data/lib/virtualbox/com/ffi_interface.rb +65 -0
- data/lib/virtualbox/com/implementer/base.rb +52 -0
- data/lib/virtualbox/com/implementer/ffi.rb +350 -0
- data/lib/virtualbox/com/implementer/mscom.rb +165 -0
- data/lib/virtualbox/com/implementer/nil.rb +10 -0
- data/lib/virtualbox/com/interface/appliance.rb +20 -0
- data/lib/virtualbox/com/interface/audio_adapter.rb +13 -0
- data/lib/virtualbox/com/interface/audio_controller_type.rb +9 -0
- data/lib/virtualbox/com/interface/audio_driver_type.rb +9 -0
- data/lib/virtualbox/com/interface/bios_boot_menu_mode.rb +9 -0
- data/lib/virtualbox/com/interface/bios_settings.rb +19 -0
- data/lib/virtualbox/com/interface/clipboard_mode.rb +9 -0
- data/lib/virtualbox/com/interface/console.rb +48 -0
- data/lib/virtualbox/com/interface/cpu_property_type.rb +9 -0
- data/lib/virtualbox/com/interface/device_type.rb +9 -0
- data/lib/virtualbox/com/interface/dhcp_server.rb +20 -0
- data/lib/virtualbox/com/interface/firmware_type.rb +9 -0
- data/lib/virtualbox/com/interface/guest_os_type.rb +21 -0
- data/lib/virtualbox/com/interface/host.rb +40 -0
- data/lib/virtualbox/com/interface/host_network_interface.rb +28 -0
- data/lib/virtualbox/com/interface/host_network_interface_medium_type.rb +9 -0
- data/lib/virtualbox/com/interface/host_network_interface_status.rb +9 -0
- data/lib/virtualbox/com/interface/host_network_interface_type.rb +9 -0
- data/lib/virtualbox/com/interface/host_usb_device.rb +11 -0
- data/lib/virtualbox/com/interface/host_usb_device_filter.rb +11 -0
- data/lib/virtualbox/com/interface/hw_virt_ex_property_type.rb +9 -0
- data/lib/virtualbox/com/interface/machine.rb +103 -0
- data/lib/virtualbox/com/interface/machine_state.rb +12 -0
- data/lib/virtualbox/com/interface/medium.rb +48 -0
- data/lib/virtualbox/com/interface/medium_attachment.rb +16 -0
- data/lib/virtualbox/com/interface/medium_format.rb +16 -0
- data/lib/virtualbox/com/interface/medium_state.rb +9 -0
- data/lib/virtualbox/com/interface/medium_type.rb +9 -0
- data/lib/virtualbox/com/interface/medium_variant.rb +9 -0
- data/lib/virtualbox/com/interface/network_adapter.rb +28 -0
- data/lib/virtualbox/com/interface/network_adapter_type.rb +9 -0
- data/lib/virtualbox/com/interface/network_attachment_type.rb +9 -0
- data/lib/virtualbox/com/interface/nsiexception.rb +21 -0
- data/lib/virtualbox/com/interface/nsisupports.rb +13 -0
- data/lib/virtualbox/com/interface/parallel_port.rb +15 -0
- data/lib/virtualbox/com/interface/port_mode.rb +9 -0
- data/lib/virtualbox/com/interface/progress.rb +58 -0
- data/lib/virtualbox/com/interface/serial_port.rb +17 -0
- data/lib/virtualbox/com/interface/session.rb +16 -0
- data/lib/virtualbox/com/interface/session_state.rb +9 -0
- data/lib/virtualbox/com/interface/session_type.rb +9 -0
- data/lib/virtualbox/com/interface/shared_folder.rb +15 -0
- data/lib/virtualbox/com/interface/snapshot.rb +18 -0
- data/lib/virtualbox/com/interface/storage_bus.rb +9 -0
- data/lib/virtualbox/com/interface/storage_controller.rb +21 -0
- data/lib/virtualbox/com/interface/storage_controller_type.rb +9 -0
- data/lib/virtualbox/com/interface/system_properties.rb +35 -0
- data/lib/virtualbox/com/interface/usb_controller.rb +18 -0
- data/lib/virtualbox/com/interface/usb_device.rb +22 -0
- data/lib/virtualbox/com/interface/usb_device_filter.rb +21 -0
- data/lib/virtualbox/com/interface/usb_device_filter_action.rb +9 -0
- data/lib/virtualbox/com/interface/usb_device_state.rb +9 -0
- data/lib/virtualbox/com/interface/virtual_box_error_info.rb +15 -0
- data/lib/virtualbox/com/interface/virtual_system_description.rb +17 -0
- data/lib/virtualbox/com/interface/virtual_system_description_type.rb +12 -0
- data/lib/virtualbox/com/interface/virtual_system_description_value_type.rb +9 -0
- data/lib/virtualbox/com/interface/virtualbox.rb +54 -0
- data/lib/virtualbox/com/interface/vrdp_auth_type.rb +9 -0
- data/lib/virtualbox/com/interface/vrdp_server.rb +17 -0
- data/lib/virtualbox/com/mscom_interface.rb +22 -0
- data/lib/virtualbox/com/util.rb +18 -0
- data/lib/virtualbox/dvd.rb +7 -94
- data/lib/virtualbox/exceptions.rb +24 -0
- data/lib/virtualbox/ext/glob_loader.rb +22 -0
- data/lib/virtualbox/ext/logger.rb +38 -0
- data/lib/virtualbox/ext/platform.rb +1 -1
- data/lib/virtualbox/extra_data.rb +25 -37
- data/lib/virtualbox/forwarded_port.rb +35 -13
- data/lib/virtualbox/global.rb +22 -80
- data/lib/virtualbox/hard_drive.rb +30 -97
- data/lib/virtualbox/lib.rb +82 -0
- data/lib/virtualbox/media.rb +7 -6
- data/lib/virtualbox/medium.rb +138 -0
- data/lib/virtualbox/medium_attachment.rb +61 -0
- data/lib/virtualbox/network_adapter.rb +134 -0
- data/lib/virtualbox/shared_folder.rb +53 -78
- data/lib/virtualbox/storage_controller.rb +76 -20
- data/lib/virtualbox/system_properties.rb +74 -0
- data/lib/virtualbox/usb_controller.rb +55 -0
- data/lib/virtualbox/version.rb +15 -0
- data/lib/virtualbox/virtual_system_description.rb +47 -0
- data/lib/virtualbox/vm.rb +160 -272
- data/test/test_helper.rb +0 -108
- data/test/virtualbox/abstract_model/attributable_test.rb +7 -1
- data/test/virtualbox/abstract_model/dirty_test.rb +1 -1
- data/test/virtualbox/abstract_model/interface_attributes_test.rb +169 -0
- data/test/virtualbox/abstract_model/relatable_test.rb +20 -0
- data/test/virtualbox/abstract_model_test.rb +40 -5
- data/test/virtualbox/appliance_test.rb +152 -0
- data/test/virtualbox/audio_adapter_test.rb +83 -0
- data/test/virtualbox/bios_test.rb +83 -0
- data/test/virtualbox/com/abstract_enum_test.rb +48 -0
- data/test/virtualbox/com/abstract_implementer_test.rb +39 -0
- data/test/virtualbox/com/abstract_interface_test.rb +139 -0
- data/test/virtualbox/com/ffi/interface_test.rb +249 -0
- data/test/virtualbox/com/ffi/util_test.rb +86 -0
- data/test/virtualbox/com/ffi_interface_test.rb +42 -0
- data/test/virtualbox/com/implementer/base_test.rb +37 -0
- data/test/virtualbox/com/implementer/ffi_test.rb +519 -0
- data/test/virtualbox/com/implementer/mscom_test.rb +208 -0
- data/test/virtualbox/com/mscom_interface_test.rb +17 -0
- data/test/virtualbox/com/util_test.rb +17 -0
- data/test/virtualbox/dvd_test.rb +4 -95
- data/test/virtualbox/ext/platform_test.rb +8 -0
- data/test/virtualbox/extra_data_test.rb +78 -102
- data/test/virtualbox/forwarded_port_test.rb +57 -7
- data/test/virtualbox/global_test.rb +25 -115
- data/test/virtualbox/hard_drive_test.rb +49 -212
- data/test/virtualbox/lib_test.rb +93 -0
- data/test/virtualbox/medium_attachment_test.rb +147 -0
- data/test/virtualbox/medium_test.rb +192 -0
- data/test/virtualbox/network_adapter_test.rb +160 -0
- data/test/virtualbox/shared_folder_test.rb +144 -160
- data/test/virtualbox/storage_controller_test.rb +166 -45
- data/test/virtualbox/system_properties_test.rb +87 -0
- data/test/virtualbox/usb_controller_test.rb +104 -0
- data/test/virtualbox/version_test.rb +34 -0
- data/test/virtualbox/virtual_system_description_test.rb +61 -0
- data/test/virtualbox/vm_test.rb +288 -322
- data/test/virtualbox_test.rb +1 -9
- data/virtualbox.gemspec +139 -23
- metadata +143 -27
- data/lib/virtualbox/attached_device.rb +0 -249
- data/lib/virtualbox/command.rb +0 -109
- data/lib/virtualbox/image.rb +0 -137
- data/lib/virtualbox/nic.rb +0 -111
- data/lib/virtualbox/system_property.rb +0 -55
- data/lib/virtualbox/usb.rb +0 -72
- data/test/virtualbox/attached_device_test.rb +0 -303
- data/test/virtualbox/command_test.rb +0 -152
- data/test/virtualbox/image_test.rb +0 -190
- data/test/virtualbox/nic_test.rb +0 -76
- data/test/virtualbox/system_property_test.rb +0 -71
- data/test/virtualbox/usb_test.rb +0 -35
|
@@ -2,7 +2,14 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
|
2
2
|
|
|
3
3
|
class ForwardedPortTest < Test::Unit::TestCase
|
|
4
4
|
setup do
|
|
5
|
+
@nic = mock("nic")
|
|
6
|
+
@nic.stubs(:adapter_type).returns(:foo)
|
|
7
|
+
@nics = [@nic]
|
|
8
|
+
|
|
5
9
|
@caller = mock("caller")
|
|
10
|
+
@caller.stubs(:network_adapters).returns(@nics)
|
|
11
|
+
|
|
12
|
+
@interface = mock("interface")
|
|
6
13
|
end
|
|
7
14
|
|
|
8
15
|
context "validations" do
|
|
@@ -55,6 +62,54 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
|
55
62
|
@caller.stubs(:extra_data).returns(@ed)
|
|
56
63
|
end
|
|
57
64
|
|
|
65
|
+
context "device" do
|
|
66
|
+
setup do
|
|
67
|
+
@port.new_record!
|
|
68
|
+
@port.added_to_relationship(@caller)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
should "return the value set if it was set" do
|
|
72
|
+
@port.device = "foo"
|
|
73
|
+
assert_equal "foo", @port.device
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
should "return the default if parent is nil" do
|
|
77
|
+
@port.expects(:parent).returns(nil)
|
|
78
|
+
assert_equal "pcnet", @port.device
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
should "return the default if the record is existing" do
|
|
82
|
+
@nic.expects(:adapter_type).never
|
|
83
|
+
@port.existing_record!
|
|
84
|
+
assert_equal "pcnet", @port.device
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
should "return pcnet if card is a Am79C970A type" do
|
|
88
|
+
@nic.expects(:adapter_type).returns(:Am79C970A)
|
|
89
|
+
assert_equal "pcnet", @port.device
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
should "return pcnet if card is a Am79C973 type" do
|
|
93
|
+
@nic.expects(:adapter_type).returns(:Am79C973)
|
|
94
|
+
assert_equal "pcnet", @port.device
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
should "return e1000 if card is a 82540EM type" do
|
|
98
|
+
@nic.expects(:adapter_type).returns(:I82540EM)
|
|
99
|
+
assert_equal "e1000", @port.device
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
should "return e1000 if card is a 82543GC type" do
|
|
103
|
+
@nic.expects(:adapter_type).returns(:I82543GC)
|
|
104
|
+
assert_equal "e1000", @port.device
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
should "return e1000 if card is a 82545EM type" do
|
|
108
|
+
@nic.expects(:adapter_type).returns(:I82545EM)
|
|
109
|
+
assert_equal "e1000", @port.device
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
58
113
|
context "saving" do
|
|
59
114
|
context "an existing record" do
|
|
60
115
|
setup do
|
|
@@ -87,6 +142,7 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
|
87
142
|
|
|
88
143
|
context "a new record" do
|
|
89
144
|
setup do
|
|
145
|
+
@port.stubs(:valid?).returns(true)
|
|
90
146
|
assert @port.new_record!
|
|
91
147
|
end
|
|
92
148
|
|
|
@@ -95,16 +151,10 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
|
95
151
|
assert !@port.new_record?
|
|
96
152
|
end
|
|
97
153
|
|
|
98
|
-
should "return false and do nothing if invalid" do
|
|
99
|
-
@caller.expects(:extra_data).never
|
|
100
|
-
@port.expects(:valid?).returns(false)
|
|
101
|
-
assert !@port.save
|
|
102
|
-
end
|
|
103
|
-
|
|
104
154
|
should "raise a ValidationFailedException if invalid and raise_errors is true" do
|
|
105
155
|
@port.expects(:valid?).returns(false)
|
|
106
156
|
assert_raises(VirtualBox::Exceptions::ValidationFailedException) {
|
|
107
|
-
@port.save
|
|
157
|
+
@port.save
|
|
108
158
|
}
|
|
109
159
|
end
|
|
110
160
|
|
|
@@ -1,136 +1,46 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
2
2
|
|
|
3
3
|
class GlobalTest < Test::Unit::TestCase
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
VirtualBox::Global.vboxconfig = nil
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
teardown do
|
|
10
|
-
VirtualBox::Global.vboxconfig = "foo"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
should "return the path if its set" do
|
|
14
|
-
VirtualBox::Global.vboxconfig = "foo"
|
|
15
|
-
File.expects(:expand_path).with("foo").returns("foo")
|
|
16
|
-
assert_equal "foo", VirtualBox::Global.vboxconfig
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
should "return Mac-path if on mac" do
|
|
20
|
-
result = "~/Library/VirtualBox/VirtualBox.xml"
|
|
21
|
-
VirtualBox::Platform.stubs(:mac?).returns(true)
|
|
22
|
-
|
|
23
|
-
expanded_result = result + result
|
|
24
|
-
File.expects(:expand_path).with(result).returns(expanded_result)
|
|
25
|
-
assert_equal expanded_result, VirtualBox::Global.vboxconfig
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
should "return Windows-path if on windows" do
|
|
29
|
-
result = "~/.VirtualBox/VirtualBox.xml"
|
|
30
|
-
VirtualBox::Platform.stubs(:mac?).returns(false)
|
|
31
|
-
VirtualBox::Platform.stubs(:windows?).returns(true)
|
|
32
|
-
|
|
33
|
-
expanded_result = result + result
|
|
34
|
-
File.expects(:expand_path).with(result).returns(expanded_result)
|
|
35
|
-
assert_equal expanded_result, VirtualBox::Global.vboxconfig
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
should "return Linux-path if on linux" do
|
|
39
|
-
result = "~/.VirtualBox/VirtualBox.xml"
|
|
40
|
-
VirtualBox::Platform.stubs(:mac?).returns(false)
|
|
41
|
-
VirtualBox::Platform.stubs(:windows?).returns(false)
|
|
42
|
-
VirtualBox::Platform.stubs(:linux?).returns(true)
|
|
43
|
-
|
|
44
|
-
expanded_result = result + result
|
|
45
|
-
File.expects(:expand_path).with(result).returns(expanded_result)
|
|
46
|
-
assert_equal expanded_result, VirtualBox::Global.vboxconfig
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
should "return 'unknown' otherwise" do
|
|
50
|
-
result = "Unknown"
|
|
51
|
-
VirtualBox::Platform.stubs(:mac?).returns(false)
|
|
52
|
-
VirtualBox::Platform.stubs(:windows?).returns(false)
|
|
53
|
-
VirtualBox::Platform.stubs(:linux?).returns(false)
|
|
54
|
-
|
|
55
|
-
expanded_result = result + result
|
|
56
|
-
File.expects(:expand_path).with(result).returns(expanded_result)
|
|
57
|
-
assert_equal expanded_result, VirtualBox::Global.vboxconfig
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
context "getting the global config" do
|
|
62
|
-
should "only get it once, then cache" do
|
|
63
|
-
VirtualBox::Global.expects(:config).returns(mock_xml_doc).once
|
|
64
|
-
result = VirtualBox::Global.global(true)
|
|
65
|
-
assert result
|
|
66
|
-
assert result.equal?(VirtualBox::Global.global)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
should "reload if reload is true" do
|
|
70
|
-
VirtualBox::Global.expects(:config).returns(mock_xml_doc).twice
|
|
71
|
-
result = VirtualBox::Global.global(true)
|
|
72
|
-
assert result
|
|
73
|
-
assert !result.equal?(VirtualBox::Global.global(true))
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
should "reload if global reload flag is set" do
|
|
77
|
-
VirtualBox::Global.reload!
|
|
78
|
-
VirtualBox::Global.expects(:config).returns(mock_xml_doc).once
|
|
79
|
-
VirtualBox::Global.global
|
|
80
|
-
assert !VirtualBox::Global.reload?
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
context "testingn the config path" do
|
|
85
|
-
setup do
|
|
86
|
-
@result = "foo"
|
|
87
|
-
VirtualBox::Global.stubs(:vboxconfig).returns(@result)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
should "return true if it is a file" do
|
|
91
|
-
File.expects(:file?).with(@result).returns(true)
|
|
92
|
-
assert VirtualBox::Global.vboxconfig?
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
should "return false if it is not a file" do
|
|
96
|
-
File.expects(:file?).with(@result).returns(false)
|
|
97
|
-
assert !VirtualBox::Global.vboxconfig?
|
|
98
|
-
end
|
|
4
|
+
setup do
|
|
5
|
+
@klass = VirtualBox::Global
|
|
99
6
|
end
|
|
100
7
|
|
|
101
|
-
context "
|
|
8
|
+
context "getting the global object" do
|
|
102
9
|
setup do
|
|
103
|
-
@
|
|
104
|
-
VirtualBox::
|
|
105
|
-
|
|
10
|
+
@lib = mock('lib')
|
|
11
|
+
VirtualBox::Lib.stubs(:lib).returns(@lib)
|
|
12
|
+
@klass.reset!
|
|
106
13
|
end
|
|
107
14
|
|
|
108
|
-
should "
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
15
|
+
should "initialize the object with the lib once" do
|
|
16
|
+
instance = mock("instance")
|
|
17
|
+
@klass.expects(:new).with(@lib).once.returns(instance)
|
|
18
|
+
assert_equal instance, @klass.global
|
|
19
|
+
assert_equal instance, @klass.global
|
|
20
|
+
assert_equal instance, @klass.global
|
|
114
21
|
end
|
|
115
22
|
|
|
116
|
-
should "
|
|
117
|
-
|
|
118
|
-
|
|
23
|
+
should "initialize the object if reload is set" do
|
|
24
|
+
instance = mock("instance")
|
|
25
|
+
@klass.expects(:new).with(@lib).twice.returns(instance)
|
|
26
|
+
assert_equal instance, @klass.global
|
|
27
|
+
assert_equal instance, @klass.global(true)
|
|
28
|
+
assert_equal instance, @klass.global
|
|
119
29
|
end
|
|
120
30
|
end
|
|
121
31
|
|
|
122
|
-
context "
|
|
32
|
+
context "with an instance" do
|
|
123
33
|
setup do
|
|
124
|
-
|
|
34
|
+
@lib = mock("lib")
|
|
35
|
+
@instance = @klass.new(@lib)
|
|
125
36
|
end
|
|
126
37
|
|
|
127
|
-
should "
|
|
128
|
-
|
|
38
|
+
should "be an existing record, always" do
|
|
39
|
+
assert !@instance.new_record?
|
|
129
40
|
end
|
|
130
41
|
|
|
131
|
-
should "
|
|
132
|
-
|
|
133
|
-
VirtualBox::Global.expand_path("foo")
|
|
42
|
+
should "setup the lib attribute on initialization" do
|
|
43
|
+
assert_equal @lib, @instance.lib
|
|
134
44
|
end
|
|
135
45
|
end
|
|
136
46
|
end
|
|
@@ -2,245 +2,82 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
|
2
2
|
|
|
3
3
|
class HardDriveTest < Test::Unit::TestCase
|
|
4
4
|
setup do
|
|
5
|
-
VirtualBox::
|
|
6
|
-
|
|
7
|
-
@find_raw = <<-raw
|
|
8
|
-
UUID: 11dedd14-57a1-4bdb-adeb-dd1d67f066e1
|
|
9
|
-
Accessible: yes
|
|
10
|
-
Description:
|
|
11
|
-
Logical size: 20480 MBytes
|
|
12
|
-
Current size on disk: 1218 MBytes
|
|
13
|
-
Type: normal (base)
|
|
14
|
-
Storage format: VDI
|
|
15
|
-
In use by VMs: FooVM (UUID: 696249ad-00b6-4087-b47f-9b82629efc31)
|
|
16
|
-
Location: /Users/mitchellh/Library/VirtualBox/HardDisks/foo.vdi
|
|
17
|
-
raw
|
|
18
|
-
@name = "foo"
|
|
19
|
-
VirtualBox::Command.stubs(:vboxmanage).with("showhdinfo", @name).returns(@find_raw)
|
|
5
|
+
@klass = VirtualBox::HardDrive
|
|
6
|
+
@interface = mock("interface")
|
|
20
7
|
end
|
|
21
8
|
|
|
22
|
-
context "
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<MediaRegistry>
|
|
26
|
-
<HardDisks>
|
|
27
|
-
<HardDisk uuid="{9d2e4353-d1e9-466c-ac58-f2249264147b}" location="HardDisks/TestJeOS.vdi" format="VDI" type="Normal"/>
|
|
28
|
-
<HardDisk uuid="{5f7ccd06-78ef-47e9-b2bc-515aedd2f288}" location="HardDisks/hobobase.vdi" format="VDI" type="Normal"/>
|
|
29
|
-
</HardDisks>
|
|
30
|
-
</MediaRegistry>
|
|
31
|
-
xml
|
|
32
|
-
@doc = Nokogiri::XML(@xml)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
should "create an object for each hard disk entry" do
|
|
36
|
-
result = VirtualBox::HardDrive.populate_relationship(nil, @doc)
|
|
37
|
-
assert_equal 2, result.length
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
should "properly extract uuid, location, and format" do
|
|
41
|
-
VirtualBox::Global.vboxconfig = "/foo/rawr.rb"
|
|
42
|
-
result = VirtualBox::HardDrive.populate_relationship(nil, @doc)
|
|
43
|
-
result = result[0]
|
|
44
|
-
assert_equal "9d2e4353-d1e9-466c-ac58-f2249264147b", result.uuid
|
|
45
|
-
assert_equal "VDI", result.format
|
|
46
|
-
assert_equal "/foo/HardDisks/TestJeOS.vdi", result.location
|
|
9
|
+
context "device type" do
|
|
10
|
+
should "be :hard_disk" do
|
|
11
|
+
assert_equal :hard_disk, @klass.device_type
|
|
47
12
|
end
|
|
48
13
|
end
|
|
49
14
|
|
|
50
|
-
context "
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
should "be invalid if size is nil" do
|
|
61
|
-
@hd.size = nil
|
|
62
|
-
assert !@hd.valid?
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
should "clear validations when rechecking" do
|
|
66
|
-
@hd.size = nil
|
|
67
|
-
assert !@hd.valid?
|
|
68
|
-
@hd.size = 700
|
|
69
|
-
assert @hd.valid?
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
context "destroying a hard drive" do
|
|
74
|
-
setup do
|
|
75
|
-
@hd = VirtualBox::HardDrive.find(@name)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
should "call vboxmanage to destroy it" do
|
|
79
|
-
VirtualBox::Command.expects(:vboxmanage).with("closemedium", "disk", @hd.uuid, "--delete")
|
|
80
|
-
assert @hd.destroy
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
should "return false if destroy failed" do
|
|
84
|
-
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
|
85
|
-
assert !@hd.destroy
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
should "raise an exception if failed and flag is set" do
|
|
89
|
-
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
|
90
|
-
assert_raises(VirtualBox::Exceptions::CommandFailedException) {
|
|
91
|
-
@hd.destroy(true)
|
|
92
|
-
}
|
|
15
|
+
context "retrieving all hard drives" do
|
|
16
|
+
should "return an array of HardDrive objects" do
|
|
17
|
+
media = mock("media")
|
|
18
|
+
media.expects(:hard_drives).returns("foo")
|
|
19
|
+
global = mock("global")
|
|
20
|
+
global.expects(:media).returns(media)
|
|
21
|
+
VirtualBox::Global.expects(:global).returns(global)
|
|
22
|
+
assert_equal "foo", VirtualBox::HardDrive.all
|
|
93
23
|
end
|
|
94
24
|
end
|
|
95
25
|
|
|
96
|
-
context "
|
|
26
|
+
context "finding a hard drive" do
|
|
97
27
|
setup do
|
|
98
|
-
@
|
|
99
|
-
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
should "call vboxmanage with the clone command" do
|
|
103
|
-
VirtualBox::HardDrive.expects(:find).returns(nil)
|
|
104
|
-
@hd.clone("bar")
|
|
28
|
+
@all = []
|
|
29
|
+
@klass.stubs(:all).returns(@all)
|
|
105
30
|
end
|
|
106
31
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
32
|
+
def mock_drive(uuid)
|
|
33
|
+
drive = mock("hd-#{uuid}")
|
|
34
|
+
drive.stubs(:uuid).returns(uuid)
|
|
35
|
+
drive
|
|
111
36
|
end
|
|
112
37
|
|
|
113
|
-
should "return
|
|
114
|
-
|
|
115
|
-
|
|
38
|
+
should "return nil if it doesn't exist" do
|
|
39
|
+
@all << mock_drive("foo")
|
|
40
|
+
assert_nil @klass.find("bar")
|
|
116
41
|
end
|
|
117
42
|
|
|
118
|
-
should "
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
43
|
+
should "return the matching drive if it is found" do
|
|
44
|
+
drive = mock_drive("foo")
|
|
45
|
+
@all << mock_drive("bar")
|
|
46
|
+
@all << drive
|
|
47
|
+
assert_equal drive, @klass.find("foo")
|
|
123
48
|
end
|
|
124
49
|
end
|
|
125
50
|
|
|
126
|
-
context "
|
|
51
|
+
context "with an instance" do
|
|
127
52
|
setup do
|
|
128
|
-
@
|
|
129
|
-
@
|
|
130
|
-
@format = "VDI"
|
|
131
|
-
|
|
132
|
-
@hd = VirtualBox::HardDrive.new
|
|
133
|
-
@hd.location = @location
|
|
134
|
-
@hd.size = @size
|
|
135
|
-
|
|
136
|
-
@fake_hd = mock("hd")
|
|
137
|
-
@fake_hd.stubs(:attributes).returns({
|
|
138
|
-
:uuid => "foo"
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
VirtualBox::HardDrive.stubs(:find).returns(@fake_hd)
|
|
142
|
-
VirtualBox::Command.stubs(:vboxmanage).returns("UUID: FOO")
|
|
53
|
+
@klass.any_instance.stubs(:initialize_attributes)
|
|
54
|
+
@instance = @klass.new(@interface)
|
|
143
55
|
end
|
|
144
56
|
|
|
145
|
-
|
|
146
|
-
|
|
57
|
+
context "cloning" do
|
|
58
|
+
setup do
|
|
59
|
+
@system_properties = mock("system_properties")
|
|
60
|
+
@virtualbox = mock("virtualbox")
|
|
61
|
+
@lib = mock("lib")
|
|
147
62
|
|
|
148
|
-
|
|
149
|
-
@hd.save
|
|
150
|
-
end
|
|
63
|
+
@hard_disk_folder = "foobar"
|
|
151
64
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
@hd.expects(:create).never
|
|
157
|
-
@hd.save
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
should "call createhd" do
|
|
161
|
-
VirtualBox::Command.expects(:vboxmanage).with("createhd", "--filename", @location, "--size", @size, "--format", @format, "--remember")
|
|
162
|
-
@hd.save
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
should "replace attributes with those of the newly created hard drive" do
|
|
166
|
-
@hd.save
|
|
167
|
-
|
|
168
|
-
assert_equal "foo", @hd.uuid
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
should "return true if the command was a success" do
|
|
172
|
-
assert @hd.save
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
should "return failure if the command failed" do
|
|
176
|
-
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
|
177
|
-
assert !@hd.save
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
should "raise an exception if flag is set" do
|
|
181
|
-
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
|
182
|
-
assert_raises(VirtualBox::Exceptions::CommandFailedException) {
|
|
183
|
-
@hd.save(true)
|
|
184
|
-
}
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
should "not run if invalid" do
|
|
188
|
-
@hd.expects(:valid?).returns(false)
|
|
189
|
-
VirtualBox::Command.expects(:vboxmanage).never
|
|
190
|
-
assert !@hd.save
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
should "raise a ValidationFailedException if invalid and raise_errors is true" do
|
|
194
|
-
@hd.expects(:valid?).returns(false)
|
|
195
|
-
assert_raises(VirtualBox::Exceptions::ValidationFailedException) {
|
|
196
|
-
@hd.save(true)
|
|
197
|
-
}
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
context "finding a single hard drive" do
|
|
202
|
-
should "parse proper fields" do
|
|
203
|
-
VirtualBox::Command.expects(:vboxmanage).with("showhdinfo", @name).returns(@find_raw)
|
|
204
|
-
|
|
205
|
-
@expected = {
|
|
206
|
-
:uuid => "11dedd14-57a1-4bdb-adeb-dd1d67f066e1",
|
|
207
|
-
:accessible => "yes",
|
|
208
|
-
:size => "20480",
|
|
209
|
-
:location => "/Users/mitchellh/Library/VirtualBox/HardDisks/foo.vdi"
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
hd = VirtualBox::HardDrive.find(@name)
|
|
213
|
-
assert hd.is_a?(VirtualBox::HardDrive)
|
|
214
|
-
|
|
215
|
-
@expected.each do |k,v|
|
|
216
|
-
assert_equal v, hd.send(k)
|
|
65
|
+
VirtualBox::Lib.stubs(:lib).returns(@lib)
|
|
66
|
+
@lib.stubs(:virtualbox).returns(@virtualbox)
|
|
67
|
+
@virtualbox.stubs(:system_properties).returns(@system_properties)
|
|
68
|
+
@system_properties.stubs(:default_hard_disk_folder).returns(@hard_disk_folder)
|
|
217
69
|
end
|
|
218
|
-
end
|
|
219
70
|
|
|
220
|
-
|
|
221
|
-
|
|
71
|
+
should "clone the hard drive" do
|
|
72
|
+
format = "VDI"
|
|
73
|
+
new_medium = mock("new_medium")
|
|
74
|
+
progress = mock("progress")
|
|
75
|
+
@virtualbox.expects(:create_hard_disk).with(format, "/foo.vdi").returns(new_medium)
|
|
76
|
+
@interface.expects(:clone_to).with(new_medium, :standard, nil).returns(progress)
|
|
77
|
+
progress.expects(:wait_for_completion).with(-1)
|
|
222
78
|
|
|
223
|
-
|
|
224
|
-
assert_nil VirtualBox::HardDrive.find(12)
|
|
79
|
+
@instance.clone("/foo.vdi")
|
|
225
80
|
end
|
|
226
81
|
end
|
|
227
|
-
|
|
228
|
-
should "raise an exception if flag is set" do
|
|
229
|
-
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
|
230
|
-
assert_raises(VirtualBox::Exceptions::CommandFailedException) {
|
|
231
|
-
VirtualBox::HardDrive.find(12, true)
|
|
232
|
-
}
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
context "retrieving all hard drives" do
|
|
237
|
-
should "return an array of HardDrive objects" do
|
|
238
|
-
media = mock("media")
|
|
239
|
-
media.expects(:hard_drives).returns("foo")
|
|
240
|
-
global = mock("global")
|
|
241
|
-
global.expects(:media).returns(media)
|
|
242
|
-
VirtualBox::Global.expects(:global).returns(global)
|
|
243
|
-
assert_equal "foo", VirtualBox::HardDrive.all
|
|
244
|
-
end
|
|
245
82
|
end
|
|
246
83
|
end
|