virtualbox 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -3
- data/Gemfile +8 -8
- data/Rakefile +2 -0
- data/Readme.md +11 -2
- data/VERSION +1 -1
- data/docs/WhatsNew.md +40 -24
- data/lib/virtualbox.rb +9 -0
- data/lib/virtualbox/abstract_model.rb +80 -10
- data/lib/virtualbox/abstract_model/attributable.rb +61 -1
- data/lib/virtualbox/abstract_model/relatable.rb +88 -6
- data/lib/virtualbox/attached_device.rb +18 -10
- data/lib/virtualbox/command.rb +13 -0
- data/lib/virtualbox/dvd.rb +35 -0
- data/lib/virtualbox/exceptions.rb +1 -0
- data/lib/virtualbox/extra_data.rb +10 -21
- data/lib/virtualbox/global.rb +126 -0
- data/lib/virtualbox/hard_drive.rb +33 -9
- data/lib/virtualbox/image.rb +2 -3
- data/lib/virtualbox/media.rb +19 -0
- data/lib/virtualbox/nic.rb +28 -67
- data/lib/virtualbox/shared_folder.rb +7 -12
- data/lib/virtualbox/storage_controller.rb +8 -36
- data/lib/virtualbox/system_property.rb +55 -0
- data/lib/virtualbox/usb.rb +72 -0
- data/lib/virtualbox/vm.rb +126 -25
- data/test/test_helper.rb +118 -12
- data/test/virtualbox/abstract_model/attributable_test.rb +55 -5
- data/test/virtualbox/abstract_model/relatable_test.rb +66 -4
- data/test/virtualbox/abstract_model_test.rb +140 -8
- data/test/virtualbox/attached_device_test.rb +10 -7
- data/test/virtualbox/command_test.rb +13 -0
- data/test/virtualbox/dvd_test.rb +50 -28
- data/test/virtualbox/extra_data_test.rb +11 -51
- data/test/virtualbox/global_test.rb +78 -0
- data/test/virtualbox/hard_drive_test.rb +34 -57
- data/test/virtualbox/image_test.rb +0 -5
- data/test/virtualbox/nic_test.rb +11 -64
- data/test/virtualbox/shared_folder_test.rb +5 -5
- data/test/virtualbox/storage_controller_test.rb +15 -30
- data/test/virtualbox/system_property_test.rb +71 -0
- data/test/virtualbox/usb_test.rb +35 -0
- data/test/virtualbox/vm_test.rb +62 -121
- data/virtualbox.gemspec +15 -2
- metadata +23 -4
@@ -34,11 +34,6 @@ class ImageTest < Test::Unit::TestCase
|
|
34
34
|
assert result.empty_drive?
|
35
35
|
end
|
36
36
|
|
37
|
-
should "return nil if uuid is nil and medium isn't empty" do
|
38
|
-
result = VirtualBox::Image.populate_relationship(@model, {})
|
39
|
-
assert result.nil?
|
40
|
-
end
|
41
|
-
|
42
37
|
should "result a matching image from subclasses if uuid" do
|
43
38
|
uuid = "foo'"
|
44
39
|
|
data/test/virtualbox/nic_test.rb
CHANGED
@@ -2,25 +2,13 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class NicTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@data = {
|
6
|
-
:nic1 => "bridged",
|
7
|
-
:nic2 => "foo",
|
8
|
-
:nic3 => "bar"
|
9
|
-
}
|
10
|
-
|
11
5
|
@caller = mock("caller")
|
12
6
|
@caller.stubs(:name).returns("foo")
|
13
|
-
|
14
|
-
VirtualBox::VM.stubs(:human_info).returns(<<-raw)
|
15
|
-
NIC 1: MAC: 08002745B49F, Attachment: Bridged Interface 'en0: Ethernet', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps
|
16
|
-
NIC 2: MAC: 08002745B49F, Attachment: Bridged Interface 'en0: Ethernet', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps
|
17
|
-
NIC 3: MAC: 08002745B49F, Attachment: Bridged Interface 'en0: Ethernet', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps
|
18
|
-
raw
|
19
7
|
end
|
20
8
|
|
21
9
|
context "saving" do
|
22
10
|
setup do
|
23
|
-
@nic = VirtualBox::Nic.populate_relationship(@caller,
|
11
|
+
@nic = VirtualBox::Nic.populate_relationship(@caller, mock_xml_doc)
|
24
12
|
@vmname = "myvm"
|
25
13
|
end
|
26
14
|
|
@@ -62,68 +50,27 @@ raw
|
|
62
50
|
|
63
51
|
context "populating relationships" do
|
64
52
|
setup do
|
65
|
-
@value = VirtualBox::Nic.populate_relationship(@caller,
|
53
|
+
@value = VirtualBox::Nic.populate_relationship(@caller, mock_xml_doc)
|
66
54
|
end
|
67
55
|
|
68
56
|
should "create the correct amount of objects" do
|
69
|
-
assert_equal
|
70
|
-
end
|
71
|
-
|
72
|
-
should "parse the type" do
|
73
|
-
assert_equal "Am79C973", @value[0].nictype
|
57
|
+
assert_equal 8, @value.length
|
74
58
|
end
|
75
|
-
end
|
76
59
|
|
77
|
-
|
78
|
-
|
79
|
-
@raw = "NIC 1: MAC: 08002745B49F, Attachment: Bridged Interface 'en0: Ethernet', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps"
|
80
|
-
|
81
|
-
@multiline_raw = <<-raw
|
82
|
-
Storage Controller Port Count (0): 2
|
83
|
-
Storage Controller Name (1): Floppy Controller
|
84
|
-
Storage Controller Type (1): I82078
|
85
|
-
Storage Controller Instance Number (1): 0
|
86
|
-
Storage Controller Max Port Count (1): 1
|
87
|
-
Storage Controller Port Count (1): 1
|
88
|
-
IDE Controller (0, 0): /Users/mitchellh/Library/VirtualBox/HardDisks/HoboBase.vmdk (UUID: fb0256a9-5685-4bc2-98ff-5b7503586bf3)
|
89
|
-
IDE Controller (1, 0): Empty
|
90
|
-
Floppy Controller (0, 0): Empty
|
91
|
-
NIC 1: MAC: 08002745B49F, Attachment: Bridged Interface 'en0: Ethernet', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps
|
92
|
-
NIC 2: disabled
|
93
|
-
raw
|
60
|
+
should "not be dirty initially" do
|
61
|
+
assert !@value[0].changed?
|
94
62
|
end
|
95
63
|
|
96
|
-
should "
|
97
|
-
|
98
|
-
result = VirtualBox::Nic.nic_data("foo")
|
99
|
-
assert result.is_a?(Hash)
|
100
|
-
assert_equal 1, result.length
|
64
|
+
should "be an existing record" do
|
65
|
+
assert !@value[0].new_record?
|
101
66
|
end
|
102
67
|
|
103
|
-
should "
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
should "return proper data for valid string" do
|
108
|
-
@name = :nic1
|
109
|
-
@expected = {
|
110
|
-
:mac => "08002745B49F",
|
111
|
-
:attachment => "Bridged Interface 'en0: Ethernet'",
|
112
|
-
:trace => "off (file: none)",
|
113
|
-
:type => "Am79C973"
|
114
|
-
}
|
115
|
-
|
116
|
-
name, result = VirtualBox::Nic.parse_nic(@raw)
|
117
|
-
assert_equal @name, name
|
118
|
-
assert result.is_a?(Hash)
|
119
|
-
|
120
|
-
@expected.each do |k,v|
|
121
|
-
assert_equal v, result[k]
|
122
|
-
end
|
68
|
+
should "parse the type" do
|
69
|
+
assert_equal "Am79C973", @value[0].nictype
|
123
70
|
end
|
124
71
|
|
125
|
-
should "
|
126
|
-
|
72
|
+
should "correctly turn adapters which aren't enabled into 'none'" do
|
73
|
+
assert_equal "none", @value[2].nic
|
127
74
|
end
|
128
75
|
end
|
129
76
|
end
|
@@ -45,7 +45,7 @@ class SharedFolderTest < Test::Unit::TestCase
|
|
45
45
|
|
46
46
|
context "saving an existing shared folder" do
|
47
47
|
setup do
|
48
|
-
@value = VirtualBox::SharedFolder.populate_relationship(@caller,
|
48
|
+
@value = VirtualBox::SharedFolder.populate_relationship(@caller, mock_xml_doc)
|
49
49
|
@value = @value[0]
|
50
50
|
@value.name = "different"
|
51
51
|
assert @value.changed?
|
@@ -170,7 +170,7 @@ class SharedFolderTest < Test::Unit::TestCase
|
|
170
170
|
|
171
171
|
context "destroying" do
|
172
172
|
setup do
|
173
|
-
@value = VirtualBox::SharedFolder.populate_relationship(@caller,
|
173
|
+
@value = VirtualBox::SharedFolder.populate_relationship(@caller, mock_xml_doc)
|
174
174
|
@value = @value[0]
|
175
175
|
end
|
176
176
|
|
@@ -200,7 +200,7 @@ class SharedFolderTest < Test::Unit::TestCase
|
|
200
200
|
|
201
201
|
context "populating relationships" do
|
202
202
|
setup do
|
203
|
-
@value = VirtualBox::SharedFolder.populate_relationship(@caller,
|
203
|
+
@value = VirtualBox::SharedFolder.populate_relationship(@caller, mock_xml_doc)
|
204
204
|
end
|
205
205
|
|
206
206
|
should "be a 'collection'" do
|
@@ -213,11 +213,11 @@ class SharedFolderTest < Test::Unit::TestCase
|
|
213
213
|
|
214
214
|
should "parse the proper data" do
|
215
215
|
value = @value[0]
|
216
|
-
assert_equal "
|
216
|
+
assert_equal "foo", value.name
|
217
217
|
assert_equal "/foo", value.hostpath
|
218
218
|
|
219
219
|
value = @value[1]
|
220
|
-
assert_equal "
|
220
|
+
assert_equal "bar", value.name
|
221
221
|
assert_equal "/bar", value.hostpath
|
222
222
|
end
|
223
223
|
end
|
@@ -17,7 +17,7 @@ class StorageControllerTest < Test::Unit::TestCase
|
|
17
17
|
|
18
18
|
context "saving" do
|
19
19
|
setup do
|
20
|
-
@value = VirtualBox::StorageController.populate_relationship(@caller,
|
20
|
+
@value = VirtualBox::StorageController.populate_relationship(@caller, mock_xml_doc)
|
21
21
|
@value = @value[0]
|
22
22
|
end
|
23
23
|
|
@@ -29,7 +29,7 @@ class StorageControllerTest < Test::Unit::TestCase
|
|
29
29
|
|
30
30
|
context "destroying" do
|
31
31
|
setup do
|
32
|
-
@value = VirtualBox::StorageController.populate_relationship(@caller,
|
32
|
+
@value = VirtualBox::StorageController.populate_relationship(@caller, mock_xml_doc)
|
33
33
|
@value = @value[0]
|
34
34
|
end
|
35
35
|
|
@@ -52,40 +52,25 @@ class StorageControllerTest < Test::Unit::TestCase
|
|
52
52
|
end
|
53
53
|
|
54
54
|
context "populating relationships" do
|
55
|
-
|
56
|
-
|
57
|
-
assert_equal 2, value.length
|
58
|
-
end
|
59
|
-
|
60
|
-
should "use populate keys when extracting keys" do
|
61
|
-
value = VirtualBox::StorageController.new(0, @caller, @data)
|
62
|
-
assert_equal "foo", value.name
|
63
|
-
assert_equal 7, value.max_ports
|
55
|
+
setup do
|
56
|
+
@sc = mock_xml_doc.css("StorageControllers StorageController").first
|
64
57
|
end
|
65
58
|
|
66
|
-
should "
|
67
|
-
VirtualBox::StorageController.
|
68
|
-
value
|
69
|
-
assert_equal "BAR", value.name
|
59
|
+
should "create a collection proxy" do
|
60
|
+
value = VirtualBox::StorageController.populate_relationship(@caller, mock_xml_doc)
|
61
|
+
assert value.is_a?(VirtualBox::Proxies::Collection)
|
70
62
|
end
|
71
|
-
end
|
72
63
|
|
73
|
-
|
74
|
-
|
75
|
-
|
64
|
+
should "create the correct amount of objects" do
|
65
|
+
value = VirtualBox::StorageController.populate_relationship(@caller, mock_xml_doc)
|
66
|
+
assert_equal 1, value.length
|
76
67
|
end
|
77
68
|
|
78
|
-
should "
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
assert !data.has_key?(:"bar-0-0")
|
84
|
-
|
85
|
-
data = @controller.extract_devices(1, @data)
|
86
|
-
assert data
|
87
|
-
assert !data.has_key?(:"foo-0-0")
|
88
|
-
assert data.has_key?(:"bar-0-0")
|
69
|
+
should "use populate keys when extracting keys" do
|
70
|
+
value = VirtualBox::StorageController.new(0, @caller, @sc)
|
71
|
+
assert_equal "foo", value.name
|
72
|
+
assert_equal "2", value.ports
|
73
|
+
assert_equal "PIIX4", value.type
|
89
74
|
end
|
90
75
|
end
|
91
76
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class SystemPropertyTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@raw = <<-raw
|
6
|
+
VirtualBox Command Line Management Interface Version 3.1.2
|
7
|
+
(C) 2005-2009 Sun Microsystems, Inc.
|
8
|
+
All rights reserved.
|
9
|
+
|
10
|
+
Minimum guest RAM size: 4 Megabytes
|
11
|
+
Maximum guest RAM size: 3584 Megabytes
|
12
|
+
Minimum video RAM size: 1 Megabytes
|
13
|
+
Maximum video RAM size: 128 Megabytes
|
14
|
+
Minimum guest CPU count: 1
|
15
|
+
Maximum guest CPU count: 32
|
16
|
+
Maximum VDI size: 2097151 Megabytes
|
17
|
+
Maximum Network Adapter count: 8
|
18
|
+
Maximum Serial Port count: 2
|
19
|
+
Maximum Parallel Port count: 2
|
20
|
+
Maximum Boot Position: 4
|
21
|
+
Maximum IDE Controllers: 1
|
22
|
+
Maximum IDE Port count: 2
|
23
|
+
Maximum Devices per IDE Port: 2
|
24
|
+
Maximum SATA Controllers: 1
|
25
|
+
Maximum SATA Port count: 30
|
26
|
+
Maximum Devices per SATA Port: 1
|
27
|
+
Maximum SCSI Controllers: 1
|
28
|
+
Maximum SCSI Port count: 16
|
29
|
+
Maximum Devices per SCSI Port: 1
|
30
|
+
Maximum Floppy Controllers: 1
|
31
|
+
Maximum Floppy Port count: 1
|
32
|
+
Maximum Devices per Floppy Port: 2
|
33
|
+
Default machine folder: /Users/mitchellh/Library/VirtualBox/Machines
|
34
|
+
Default hard disk folder: /Users/mitchellh/Library/VirtualBox/HardDisks
|
35
|
+
VRDP authentication library: VRDPAuth
|
36
|
+
Webservice auth. library: VRDPAuth
|
37
|
+
Log history count: 3
|
38
|
+
raw
|
39
|
+
end
|
40
|
+
|
41
|
+
context "getting all system properties" do
|
42
|
+
setup do
|
43
|
+
VirtualBox::Command.stubs(:vboxmanage).returns(@raw)
|
44
|
+
end
|
45
|
+
|
46
|
+
should "return a new SystemProperty object" do
|
47
|
+
result = VirtualBox::SystemProperty.all
|
48
|
+
assert result.is_a?(VirtualBox::SystemProperty)
|
49
|
+
end
|
50
|
+
|
51
|
+
should "run the vboxmanage command and parse its output" do
|
52
|
+
raw = mock("raw")
|
53
|
+
VirtualBox::Command.expects(:vboxmanage).with("list", "systemproperties").returns(raw)
|
54
|
+
VirtualBox::SystemProperty.expects(:parse_raw).with(raw).returns("foo")
|
55
|
+
VirtualBox::SystemProperty.all
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "parsing the raw output" do
|
60
|
+
should "return a hash with the proper number of values" do
|
61
|
+
result = VirtualBox::SystemProperty.parse_raw(@raw)
|
62
|
+
assert result.is_a?(Hash)
|
63
|
+
assert_equal 28, result.length
|
64
|
+
end
|
65
|
+
|
66
|
+
should "lowercase and convert each key to a symbol" do
|
67
|
+
result = VirtualBox::SystemProperty.parse_raw(@raw)
|
68
|
+
assert_equal "30", result[:maximum_sata_port_count]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class UsbTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@caller = mock("caller")
|
6
|
+
@caller.stubs(:name).returns("foo")
|
7
|
+
end
|
8
|
+
|
9
|
+
context "populating relationships" do
|
10
|
+
setup do
|
11
|
+
@value = VirtualBox::USB.populate_relationship(@caller, mock_xml_doc)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "create the correct amount of objects" do
|
15
|
+
assert_equal 2, @value.length
|
16
|
+
end
|
17
|
+
|
18
|
+
should "not be dirty initially" do
|
19
|
+
assert !@value[0].changed?
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be an existing record" do
|
23
|
+
assert !@value[0].new_record?
|
24
|
+
end
|
25
|
+
|
26
|
+
should "parse attributes correctly" do
|
27
|
+
assert_equal 'true', @value[0].active
|
28
|
+
assert_equal 'Apple, Inc', @value[0].manufacturer
|
29
|
+
assert_equal 'Apple, Inc Apple Keyboard [0069]', @value[0].name
|
30
|
+
assert_equal @caller, @value[0].parent
|
31
|
+
assert_equal 'Apple Keyboard', @value[0].product
|
32
|
+
assert_equal 'no', @value[0].remote
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/test/virtualbox/vm_test.rb
CHANGED
@@ -2,77 +2,8 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class VMTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@
|
6
|
-
|
7
|
-
ostype="Ubuntu"
|
8
|
-
UUID="8710d3db-d96a-46ed-9004-59fa891fda90"
|
9
|
-
CfgFile="/Users/mitchellh/Library/VirtualBox/Machines/foo/foo.xml"
|
10
|
-
hardwareuuid="8710d3db-d96a-46ed-9004-59fa891fda90"
|
11
|
-
memory=360
|
12
|
-
vram=12
|
13
|
-
cpus=1
|
14
|
-
synthcpu="off"
|
15
|
-
bootmenu="messageandmenu"
|
16
|
-
boot1="floppy"
|
17
|
-
boot2="dvd"
|
18
|
-
boot3="disk"
|
19
|
-
boot4="none"
|
20
|
-
acpi="on"
|
21
|
-
ioapic="off"
|
22
|
-
pae="on"
|
23
|
-
biossystemtimeoffset=0
|
24
|
-
hwvirtex="on"
|
25
|
-
hwvirtexexcl="off"
|
26
|
-
nestedpaging="off"
|
27
|
-
vtxvpid="off"
|
28
|
-
VMState="poweroff"
|
29
|
-
VMStateChangeTime="2010-01-22T22:02:47.672000000"
|
30
|
-
monitorcount=1
|
31
|
-
accelerate3d="off"
|
32
|
-
accelerate2dvideo="off"
|
33
|
-
teleporterenabled="off"
|
34
|
-
teleporterport=0
|
35
|
-
teleporteraddress="<NULL>"
|
36
|
-
teleporterpassword="<NULL>"
|
37
|
-
storagecontrollername0="IDE Controller"
|
38
|
-
storagecontrollertype0="PIIX4"
|
39
|
-
storagecontrollerinstance0="0"
|
40
|
-
storagecontrollermaxportcount0="2"
|
41
|
-
storagecontrollerportcount0="2"
|
42
|
-
storagecontrollername1="Floppy Controller"
|
43
|
-
storagecontrollertype1="I82078"
|
44
|
-
storagecontrollerinstance1="0"
|
45
|
-
storagecontrollermaxportcount1="1"
|
46
|
-
storagecontrollerportcount1="1"
|
47
|
-
"IDE Controller-0-0"="/Users/mitchellh/Library/VirtualBox/HardDisks/HoboBase.vmdk"
|
48
|
-
"IDE Controller-ImageUUID-0-0"="5e090af6-7d71-4f40-8b03-33aa665f9ecf"
|
49
|
-
"IDE Controller-0-1"="none"
|
50
|
-
"IDE Controller-1-0"="emptydrive"
|
51
|
-
"IDE Controller-1-1"="none"
|
52
|
-
"Floppy Controller-0-0"="emptydrive"
|
53
|
-
"Floppy Controller-0-1"="none"
|
54
|
-
bridgeadapter1="en1: AirPort"
|
55
|
-
macaddress1="08002771F257"
|
56
|
-
cableconnected1="on"
|
57
|
-
nic1="bridged"
|
58
|
-
nic2="none"
|
59
|
-
nic3="none"
|
60
|
-
nic4="none"
|
61
|
-
nic5="none"
|
62
|
-
nic6="none"
|
63
|
-
nic7="none"
|
64
|
-
nic8="none"
|
65
|
-
uart1="off"
|
66
|
-
uart2="off"
|
67
|
-
audio="none"
|
68
|
-
clipboard="bidirectional"
|
69
|
-
vrdp="off"
|
70
|
-
usb="off"
|
71
|
-
SharedFolderNameMachineMapping1="mysharedfolder"
|
72
|
-
SharedFolderPathMachineMapping1="/virtualbox"
|
73
|
-
SharedFolderNameMachineMapping2="otherfolder"
|
74
|
-
SharedFolderPathMachineMapping2="/virtualbox/lib"
|
75
|
-
showvminfo
|
5
|
+
@raw_xml = mock_xml
|
6
|
+
@raw_xml_doc = mock_xml_doc
|
76
7
|
|
77
8
|
@name = "foo"
|
78
9
|
|
@@ -81,30 +12,20 @@ showvminfo
|
|
81
12
|
end
|
82
13
|
|
83
14
|
def create_vm
|
84
|
-
VirtualBox::Command.expects(:
|
85
|
-
VirtualBox::
|
86
|
-
VirtualBox::Command.expects(:vboxmanage).with("list", "hdds").returns("")
|
87
|
-
VirtualBox::Command.expects(:vboxmanage).with("list", "dvds").returns("")
|
88
|
-
VirtualBox::Command.expects(:vboxmanage).with("getextradata", @name, "enumerate").returns("")
|
89
|
-
vm = VirtualBox::VM.find(@name)
|
15
|
+
VirtualBox::Command.expects(:parse_xml).returns(@raw_xml_doc)
|
16
|
+
vm = VirtualBox::VM.load_from_xml(@name)
|
90
17
|
assert vm
|
91
18
|
vm
|
92
19
|
end
|
93
20
|
|
94
|
-
context "human readable info" do
|
95
|
-
should "not pass --machinereadable into the showvminfo command" do
|
96
|
-
VirtualBox::Command.expects(:vboxmanage).with("showvminfo", @name).once
|
97
|
-
VirtualBox::VM.human_info(@name)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
21
|
context "reading the VM state" do
|
102
22
|
setup do
|
103
23
|
@vm = create_vm
|
104
24
|
end
|
105
25
|
|
106
|
-
should "
|
107
|
-
|
26
|
+
should "lazy load the state" do
|
27
|
+
@vm.expects(:load_attribute).with(:state).once
|
28
|
+
@vm.state
|
108
29
|
end
|
109
30
|
|
110
31
|
should "reload the state if true is passed as a parameter" do
|
@@ -269,24 +190,39 @@ showvminfo
|
|
269
190
|
VirtualBox::Command.expects(:vboxmanage).with("unregistervm", @name, "--delete").in_sequence(destroy_seq)
|
270
191
|
@vm.destroy
|
271
192
|
end
|
193
|
+
|
194
|
+
should "mark global for reloading" do
|
195
|
+
VirtualBox::Global.expects(:reload!)
|
196
|
+
@vm.destroy
|
197
|
+
end
|
272
198
|
end
|
273
199
|
|
274
200
|
context "finding all VMs" do
|
275
201
|
setup do
|
276
|
-
|
277
|
-
|
278
|
-
"
|
279
|
-
|
202
|
+
VirtualBox::VM.reloaded!
|
203
|
+
|
204
|
+
@global = mock("global")
|
205
|
+
@global.stubs(:vms)
|
280
206
|
end
|
281
207
|
|
282
208
|
should "list VMs then parse them" do
|
283
|
-
|
284
|
-
VirtualBox::Command.expects(:vboxmanage).with("list", "vms").returns(@raw).in_sequence(all_seq)
|
285
|
-
VirtualBox::VM.expects(:parse_vm_list).with(@raw).in_sequence(all_seq)
|
209
|
+
VirtualBox::Global.expects(:global).with(false).returns(@global)
|
286
210
|
VirtualBox::VM.all
|
287
211
|
end
|
288
212
|
|
213
|
+
should "reload the VMs list if given the reload argument" do
|
214
|
+
VirtualBox::Global.expects(:global).with(true).returns(@global)
|
215
|
+
VirtualBox::VM.all(true)
|
216
|
+
end
|
217
|
+
|
289
218
|
context "parser" do
|
219
|
+
setup do
|
220
|
+
@raw = <<-raw
|
221
|
+
"foo" {abcdefg}
|
222
|
+
"bar" {zefaldf}
|
223
|
+
raw
|
224
|
+
end
|
225
|
+
|
290
226
|
should "ignore non-matching lines" do
|
291
227
|
assert VirtualBox::VM.parse_vm_list("HEY YOU").empty?
|
292
228
|
end
|
@@ -344,6 +280,15 @@ raw
|
|
344
280
|
VirtualBox::AttachedDevice.any_instance.stubs(:save)
|
345
281
|
end
|
346
282
|
|
283
|
+
teardown do
|
284
|
+
VirtualBox::Global.reloaded!
|
285
|
+
end
|
286
|
+
|
287
|
+
should "force a reload on the global class" do
|
288
|
+
VirtualBox::Global.expects(:reload!).once
|
289
|
+
assert @vm.save
|
290
|
+
end
|
291
|
+
|
347
292
|
should "return false if saving fails" do
|
348
293
|
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
349
294
|
|
@@ -388,50 +333,46 @@ raw
|
|
388
333
|
end
|
389
334
|
end
|
390
335
|
|
336
|
+
context "loading a VM from XML" do
|
337
|
+
should "parse the XML then initializing the class" do
|
338
|
+
VirtualBox::Command.expects(:parse_xml).with("foo").returns(@raw_xml_doc)
|
339
|
+
VirtualBox::VM.expects(:new).with(@raw_xml_doc).once
|
340
|
+
VirtualBox::VM.load_from_xml("foo")
|
341
|
+
end
|
342
|
+
|
343
|
+
should "initialize the attributes when called with an XML document" do
|
344
|
+
VirtualBox::VM.any_instance.expects(:initialize_attributes).once.with(@raw_xml_doc)
|
345
|
+
VirtualBox::VM.new(@raw_xml_doc)
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
context "initializing attributes" do
|
350
|
+
# TODO: This needs to be tested
|
351
|
+
end
|
352
|
+
|
391
353
|
context "finding a VM by name" do
|
392
354
|
setup do
|
393
|
-
|
394
355
|
@expected = {
|
395
356
|
:name => "foo",
|
396
357
|
:ostype => "Ubuntu",
|
397
358
|
:uuid => "8710d3db-d96a-46ed-9004-59fa891fda90"
|
398
359
|
}
|
399
|
-
|
400
|
-
command_seq = sequence("command_seq)")
|
401
|
-
VirtualBox::Command.expects(:vboxmanage).with("showvminfo", @name, "--machinereadable").returns(@raw).in_sequence(command_seq)
|
402
|
-
VirtualBox::Command.expects(:vboxmanage).returns("").at_least(0).in_sequence(command_seq)
|
403
|
-
@vm = VirtualBox::VM.find(@name)
|
404
|
-
assert @vm
|
405
360
|
end
|
406
361
|
|
407
|
-
should "
|
362
|
+
should "use the global 'all' array to find the VM" do
|
363
|
+
VirtualBox::VM.expects(:all).with(true).returns([create_vm])
|
364
|
+
vm = VirtualBox::VM.find(@name)
|
365
|
+
assert vm
|
366
|
+
|
408
367
|
@expected.each do |k,v|
|
409
|
-
assert_equal v,
|
368
|
+
assert_equal v, vm.read_attribute(k)
|
410
369
|
end
|
411
370
|
end
|
412
371
|
|
413
372
|
should "return nil if the VM doesn't exist" do
|
414
|
-
VirtualBox::
|
373
|
+
VirtualBox::VM.expects(:all).returns([])
|
415
374
|
assert_nil VirtualBox::VM.find("dont exist")
|
416
375
|
end
|
417
|
-
|
418
|
-
should "properly load nic relationship" do
|
419
|
-
assert @vm.nics
|
420
|
-
assert @vm.nics.is_a?(Array)
|
421
|
-
assert_equal 8, @vm.nics.length
|
422
|
-
end
|
423
|
-
|
424
|
-
should "properly load storage controller relationship" do
|
425
|
-
assert @vm.storage_controllers
|
426
|
-
assert @vm.storage_controllers.is_a?(Array)
|
427
|
-
assert_equal 2, @vm.storage_controllers.length
|
428
|
-
end
|
429
|
-
|
430
|
-
should "properly load shared folder relationship" do
|
431
|
-
assert @vm.shared_folders
|
432
|
-
assert @vm.shared_folders.is_a?(Array)
|
433
|
-
assert_equal 2, @vm.shared_folders.length
|
434
|
-
end
|
435
376
|
end
|
436
377
|
|
437
378
|
context "parsing the showvminfo output" do
|