virtualbox 0.7.1 → 0.7.2
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/VERSION +1 -1
- data/lib/virtualbox/abstract_model.rb +10 -1
- data/lib/virtualbox/abstract_model/attributable.rb +21 -2
- data/lib/virtualbox/abstract_model/interface_attributes.rb +3 -1
- data/lib/virtualbox/abstract_model/relatable.rb +11 -1
- data/lib/virtualbox/abstract_model/version_matcher.rb +33 -0
- data/lib/virtualbox/com/ffi/interfaces.rb +9 -1
- data/lib/virtualbox/exceptions.rb +2 -1
- data/lib/virtualbox/forwarded_port.rb +1 -1
- data/lib/virtualbox/nat_engine.rb +71 -0
- data/lib/virtualbox/nat_forwarded_port.rb +171 -0
- data/lib/virtualbox/network_adapter.rb +10 -1
- data/lib/virtualbox/shared_folder.rb +1 -1
- data/lib/virtualbox/vm.rb +7 -2
- data/test/test_helper.rb +1 -1
- data/test/virtualbox/abstract_model/attributable_test.rb +24 -3
- data/test/virtualbox/abstract_model/interface_attributes_test.rb +26 -1
- data/test/virtualbox/abstract_model/relatable_test.rb +64 -5
- data/test/virtualbox/abstract_model/version_matcher_test.rb +37 -0
- data/test/virtualbox/abstract_model_test.rb +29 -11
- data/test/virtualbox/forwarded_port_test.rb +20 -3
- data/test/virtualbox/nat_engine_test.rb +106 -0
- data/test/virtualbox/nat_forwarded_port_test.rb +216 -0
- data/test/virtualbox/network_adapter_test.rb +2 -0
- data/test/virtualbox/shared_folder_test.rb +1 -0
- data/test/virtualbox/vm_test.rb +16 -2
- data/virtualbox.gemspec +12 -3
- metadata +12 -3
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class NATEngineTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = VirtualBox::NATEngine
|
6
|
+
@interface = mock("interface")
|
7
|
+
@parent = mock("parent")
|
8
|
+
end
|
9
|
+
|
10
|
+
context "initializing" do
|
11
|
+
should "load attributes from the machine" do
|
12
|
+
@klass.any_instance.expects(:initialize_attributes).with(@parent, @interface).once
|
13
|
+
@klass.new(@parent, @interface)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "initializing attributes" do
|
18
|
+
setup do
|
19
|
+
@klass.any_instance.stubs(:load_interface_attributes)
|
20
|
+
@klass.any_instance.stubs(:populate_relationships)
|
21
|
+
|
22
|
+
@instance = @klass.new(@parent, @interface)
|
23
|
+
end
|
24
|
+
|
25
|
+
should "load interface attribtues" do
|
26
|
+
@klass.any_instance.expects(:load_interface_attributes).with(@interface).once
|
27
|
+
@klass.new(@parent, @interface)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "setup the parent" do
|
31
|
+
assert_equal @parent, @instance.parent
|
32
|
+
end
|
33
|
+
|
34
|
+
should "setup the interface" do
|
35
|
+
assert_equal @interface, @instance.interface
|
36
|
+
end
|
37
|
+
|
38
|
+
should "not be dirty" do
|
39
|
+
assert !@instance.changed?
|
40
|
+
end
|
41
|
+
|
42
|
+
should "be existing record" do
|
43
|
+
assert !@instance.new_record?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "class methods" do
|
48
|
+
context "populating relationship" do
|
49
|
+
should "return nil if the interface is nil" do
|
50
|
+
assert_nil @klass.populate_relationship(@parent, nil)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "return an initialized NATEngine" do
|
54
|
+
@klass.any_instance.stubs(:load_interface_attributes)
|
55
|
+
@klass.any_instance.stubs(:populate_relationships)
|
56
|
+
result = @klass.populate_relationship(@parent, @interface)
|
57
|
+
assert result.is_a?(@klass)
|
58
|
+
assert_equal @parent, result.parent
|
59
|
+
assert_equal @interface, result.interface
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "saving relationship" do
|
64
|
+
should "call save on each item" do
|
65
|
+
item = mock("item")
|
66
|
+
item.expects(:save)
|
67
|
+
@klass.save_relationship(nil, item)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "instance methods" do
|
73
|
+
setup do
|
74
|
+
@klass.any_instance.stubs(:load_interface_attributes)
|
75
|
+
@klass.any_instance.stubs(:populate_relationships)
|
76
|
+
@instance = @klass.new(@parent, @interface)
|
77
|
+
end
|
78
|
+
|
79
|
+
context "saving" do
|
80
|
+
setup do
|
81
|
+
@engine = mock("engine")
|
82
|
+
@instance.stubs(:modify_engine).yields(@engine)
|
83
|
+
end
|
84
|
+
|
85
|
+
should "save the interface attributes and relationships" do
|
86
|
+
@instance.expects(:save_changed_interface_attributes).with(@engine).once
|
87
|
+
@instance.expects(:save_relationships).once
|
88
|
+
@instance.save
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "modify engine" do
|
93
|
+
setup do
|
94
|
+
@adapter = mock("adapter")
|
95
|
+
@adapter.stubs(:nat_driver).returns(mock("nat_driver"))
|
96
|
+
@parent.stubs(:modify_adapter).yields(@adapter)
|
97
|
+
end
|
98
|
+
|
99
|
+
should "yield the NAT engine" do
|
100
|
+
@instance.modify_engine do |engine|
|
101
|
+
assert_equal @adapter.nat_driver, engine
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class NATForwardedPortTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = VirtualBox::NATForwardedPort
|
6
|
+
|
7
|
+
@interface = mock("interface")
|
8
|
+
@caller = mock("caller")
|
9
|
+
@caller.stubs(:interface).returns(@interface)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "validations" do
|
13
|
+
setup do
|
14
|
+
@collection = VirtualBox::Proxies::Collection.new(@caller)
|
15
|
+
|
16
|
+
@port = @klass.new
|
17
|
+
@port.name = "foo"
|
18
|
+
@port.guestport = "22"
|
19
|
+
@port.hostport = "2222"
|
20
|
+
@port.added_to_relationship(@collection)
|
21
|
+
end
|
22
|
+
|
23
|
+
should "be valid with all fields" do
|
24
|
+
assert @port.valid?
|
25
|
+
end
|
26
|
+
|
27
|
+
should "be invalid with no name" do
|
28
|
+
@port.name = nil
|
29
|
+
assert !@port.valid?
|
30
|
+
end
|
31
|
+
|
32
|
+
should "be invalid with no guest port" do
|
33
|
+
@port.guestport = nil
|
34
|
+
assert !@port.valid?
|
35
|
+
end
|
36
|
+
|
37
|
+
should "be invalid with no host port" do
|
38
|
+
@port.hostport = nil
|
39
|
+
assert !@port.valid?
|
40
|
+
end
|
41
|
+
|
42
|
+
should "be invalid if not in a relationship" do
|
43
|
+
@port.write_attribute(:parent, nil)
|
44
|
+
assert !@port.valid?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with an instance" do
|
49
|
+
setup do
|
50
|
+
@port = @klass.new({
|
51
|
+
:name => "foo",
|
52
|
+
:guestport => "22",
|
53
|
+
:hostport => "2222"
|
54
|
+
})
|
55
|
+
|
56
|
+
@collection = VirtualBox::Proxies::Collection.new(@caller)
|
57
|
+
@collection << @port
|
58
|
+
|
59
|
+
@port.clear_dirty!
|
60
|
+
end
|
61
|
+
|
62
|
+
context "initializing a new record" do
|
63
|
+
setup do
|
64
|
+
@port = @klass.new
|
65
|
+
end
|
66
|
+
|
67
|
+
should "be a new record" do
|
68
|
+
assert @port.new_record?
|
69
|
+
end
|
70
|
+
|
71
|
+
should "not be dirty" do
|
72
|
+
assert !@port.changed?
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "saving" do
|
77
|
+
setup do
|
78
|
+
@interface.stubs(:add_redirect)
|
79
|
+
@port.stubs(:destroy)
|
80
|
+
end
|
81
|
+
|
82
|
+
context "an existing record" do
|
83
|
+
setup do
|
84
|
+
@port.existing_record!
|
85
|
+
@caller.stubs(:modify_engine)
|
86
|
+
end
|
87
|
+
|
88
|
+
should "not do anything and return true if its unchanged" do
|
89
|
+
@caller.expects(:modify_engine).never
|
90
|
+
assert @port.save
|
91
|
+
end
|
92
|
+
|
93
|
+
should "clear the dirty state after saving" do
|
94
|
+
@port.name = "diff"
|
95
|
+
@port.save
|
96
|
+
assert !@port.changed?
|
97
|
+
end
|
98
|
+
|
99
|
+
should "call destroy if not a new record" do
|
100
|
+
@port.name = "diff"
|
101
|
+
@port.expects(:destroy).once
|
102
|
+
@port.save
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "a new record" do
|
107
|
+
setup do
|
108
|
+
@port.stubs(:valid?).returns(true)
|
109
|
+
@port.new_record!
|
110
|
+
assert @port.new_record?
|
111
|
+
|
112
|
+
@caller.stubs(:modify_engine)
|
113
|
+
end
|
114
|
+
|
115
|
+
should "no longer be a new record after saving" do
|
116
|
+
@port.save
|
117
|
+
assert !@port.new_record?
|
118
|
+
end
|
119
|
+
|
120
|
+
should "not call destroy" do
|
121
|
+
@port.expects(:destroy).never
|
122
|
+
@port.save
|
123
|
+
end
|
124
|
+
|
125
|
+
should "raise a ValidationFailedException if invalid and raise_errors is true" do
|
126
|
+
@port.expects(:valid?).returns(false)
|
127
|
+
assert_raises(VirtualBox::Exceptions::ValidationFailedException) {
|
128
|
+
@port.save
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
should "add the redirect to the nat engine" do
|
133
|
+
nat = mock("nat")
|
134
|
+
@caller.stubs(:modify_engine).yields(nat)
|
135
|
+
nat.expects(:add_redirect).with(@port.name,
|
136
|
+
@port.protocol,
|
137
|
+
"", @port.hostport,
|
138
|
+
"", @port.guestport)
|
139
|
+
@port.save
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "destroying" do
|
145
|
+
setup do
|
146
|
+
@interface.stubs(:remove_redirect)
|
147
|
+
@nat = mock("nat")
|
148
|
+
@nat.stubs(:remove_redirect)
|
149
|
+
@caller.stubs(:modify_engine).yields(@nat)
|
150
|
+
end
|
151
|
+
|
152
|
+
should "remove itself from it's collection" do
|
153
|
+
assert @collection.include?(@port)
|
154
|
+
@port.destroy
|
155
|
+
assert !@collection.include?(@port)
|
156
|
+
end
|
157
|
+
|
158
|
+
should "remove the redirect from the nat engine interface" do
|
159
|
+
@nat.expects(:remove_redirect).with(@port.name).once
|
160
|
+
@port.destroy
|
161
|
+
end
|
162
|
+
|
163
|
+
should "do nothing if the record is new" do
|
164
|
+
@port.new_record!
|
165
|
+
@nat.expects(:remove_redirect).never
|
166
|
+
@port.destroy
|
167
|
+
end
|
168
|
+
|
169
|
+
should "be a new record after destroying" do
|
170
|
+
@port.destroy
|
171
|
+
assert @port.new_record?
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "relationships" do
|
177
|
+
context "saving" do
|
178
|
+
should "call #save on every object" do
|
179
|
+
objects = []
|
180
|
+
5.times do |i|
|
181
|
+
object = mock("object#{i}")
|
182
|
+
object.expects(:save).once
|
183
|
+
objects.push(object)
|
184
|
+
end
|
185
|
+
|
186
|
+
@klass.save_relationship(@caller, objects)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "populating" do
|
191
|
+
setup do
|
192
|
+
@interface.stubs(:redirects).returns([
|
193
|
+
"foo,1,,2222,,22"
|
194
|
+
])
|
195
|
+
@objects = @klass.populate_relationship(@caller, @interface)
|
196
|
+
end
|
197
|
+
|
198
|
+
should "return an array of ForwardedPorts" do
|
199
|
+
assert @objects.is_a?(VirtualBox::Proxies::Collection)
|
200
|
+
assert @objects.all? { |o| o.is_a?(@klass) }
|
201
|
+
end
|
202
|
+
|
203
|
+
should "have the proper data" do
|
204
|
+
object = @objects.first
|
205
|
+
assert_equal "22", object.guestport
|
206
|
+
assert_equal "2222", object.hostport
|
207
|
+
assert_equal :tcp, object.protocol
|
208
|
+
assert_equal @objects, object.parent_collection
|
209
|
+
end
|
210
|
+
|
211
|
+
should "be existing records" do
|
212
|
+
assert !@objects.first.new_record?
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -136,6 +136,7 @@ class NetworkAdapterTest < Test::Unit::TestCase
|
|
136
136
|
should "save the attachment type and interface attributes on the open adapter" do
|
137
137
|
@instance.expects(:save_attachment_type).with(@adapter).once
|
138
138
|
@instance.expects(:save_changed_interface_attributes).with(@adapter).once
|
139
|
+
@instance.expects(:save_relationships).once
|
139
140
|
@instance.save
|
140
141
|
end
|
141
142
|
end
|
@@ -171,6 +172,7 @@ class NetworkAdapterTest < Test::Unit::TestCase
|
|
171
172
|
@machine = mock("machine")
|
172
173
|
@session = mock("session")
|
173
174
|
@session.stubs(:machine).returns(@machine)
|
175
|
+
@instance.expects(:parent_machine).returns(@parent)
|
174
176
|
|
175
177
|
@adapter = mock("adapter")
|
176
178
|
end
|
@@ -89,6 +89,7 @@ class SharedFolderTest < Test::Unit::TestCase
|
|
89
89
|
setup do
|
90
90
|
@klass.any_instance.stubs(:load_interface_attributes)
|
91
91
|
@instance = @klass.new(@interface)
|
92
|
+
@instance.stubs(:parent_machine).returns(@parent)
|
92
93
|
@collection = VirtualBox::Proxies::Collection.new(@parent)
|
93
94
|
@collection << @instance
|
94
95
|
|
data/test/virtualbox/vm_test.rb
CHANGED
@@ -318,8 +318,7 @@ class VMTest < Test::Unit::TestCase
|
|
318
318
|
:stop => :power_down,
|
319
319
|
:pause => :pause,
|
320
320
|
:resume => :resume,
|
321
|
-
:save_state => :save_state
|
322
|
-
:discard_state => [:forget_saved_state, true]
|
321
|
+
:save_state => :save_state
|
323
322
|
}
|
324
323
|
|
325
324
|
methods.each do |method, control|
|
@@ -328,6 +327,21 @@ class VMTest < Test::Unit::TestCase
|
|
328
327
|
@instance.send(method)
|
329
328
|
end
|
330
329
|
end
|
330
|
+
|
331
|
+
context "discard state" do
|
332
|
+
setup do
|
333
|
+
@session = mock("session")
|
334
|
+
@console = mock("console")
|
335
|
+
@session.stubs(:console).returns(@console)
|
336
|
+
@instance.stubs(:with_open_session)
|
337
|
+
end
|
338
|
+
|
339
|
+
should "discard the session in an open state" do
|
340
|
+
@instance.expects(:with_open_session).yields(@session)
|
341
|
+
@console.expects(:forget_saved_state).with(true).once
|
342
|
+
@instance.discard_state
|
343
|
+
end
|
344
|
+
end
|
331
345
|
end
|
332
346
|
|
333
347
|
context "saving" do
|
data/virtualbox.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{virtualbox}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mitchell Hashimoto"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-17}
|
13
13
|
s.description = %q{Create and modify virtual machines in VirtualBox using pure ruby.}
|
14
14
|
s.email = %q{mitchell.hashimoto@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/virtualbox/abstract_model/interface_attributes.rb",
|
33
33
|
"lib/virtualbox/abstract_model/relatable.rb",
|
34
34
|
"lib/virtualbox/abstract_model/validatable.rb",
|
35
|
+
"lib/virtualbox/abstract_model/version_matcher.rb",
|
35
36
|
"lib/virtualbox/appliance.rb",
|
36
37
|
"lib/virtualbox/audio_adapter.rb",
|
37
38
|
"lib/virtualbox/bios.rb",
|
@@ -196,6 +197,8 @@ Gem::Specification.new do |s|
|
|
196
197
|
"lib/virtualbox/media.rb",
|
197
198
|
"lib/virtualbox/medium.rb",
|
198
199
|
"lib/virtualbox/medium_attachment.rb",
|
200
|
+
"lib/virtualbox/nat_engine.rb",
|
201
|
+
"lib/virtualbox/nat_forwarded_port.rb",
|
199
202
|
"lib/virtualbox/network_adapter.rb",
|
200
203
|
"lib/virtualbox/proxies/collection.rb",
|
201
204
|
"lib/virtualbox/shared_folder.rb",
|
@@ -214,6 +217,7 @@ Gem::Specification.new do |s|
|
|
214
217
|
"test/virtualbox/abstract_model/interface_attributes_test.rb",
|
215
218
|
"test/virtualbox/abstract_model/relatable_test.rb",
|
216
219
|
"test/virtualbox/abstract_model/validatable_test.rb",
|
220
|
+
"test/virtualbox/abstract_model/version_matcher_test.rb",
|
217
221
|
"test/virtualbox/abstract_model_test.rb",
|
218
222
|
"test/virtualbox/appliance_test.rb",
|
219
223
|
"test/virtualbox/audio_adapter_test.rb",
|
@@ -245,6 +249,8 @@ Gem::Specification.new do |s|
|
|
245
249
|
"test/virtualbox/lib_test.rb",
|
246
250
|
"test/virtualbox/medium_attachment_test.rb",
|
247
251
|
"test/virtualbox/medium_test.rb",
|
252
|
+
"test/virtualbox/nat_engine_test.rb",
|
253
|
+
"test/virtualbox/nat_forwarded_port_test.rb",
|
248
254
|
"test/virtualbox/network_adapter_test.rb",
|
249
255
|
"test/virtualbox/proxies/collection_test.rb",
|
250
256
|
"test/virtualbox/shared_folder_test.rb",
|
@@ -274,10 +280,12 @@ Gem::Specification.new do |s|
|
|
274
280
|
"test/virtualbox/vm_test.rb",
|
275
281
|
"test/virtualbox/virtual_system_description_test.rb",
|
276
282
|
"test/virtualbox/vrdp_server_test.rb",
|
283
|
+
"test/virtualbox/nat_forwarded_port_test.rb",
|
277
284
|
"test/virtualbox/appliance_test.rb",
|
278
285
|
"test/virtualbox/medium_attachment_test.rb",
|
279
286
|
"test/virtualbox/audio_adapter_test.rb",
|
280
287
|
"test/virtualbox/cpu_test.rb",
|
288
|
+
"test/virtualbox/abstract_model/version_matcher_test.rb",
|
281
289
|
"test/virtualbox/abstract_model/validatable_test.rb",
|
282
290
|
"test/virtualbox/abstract_model/attributable_test.rb",
|
283
291
|
"test/virtualbox/abstract_model/relatable_test.rb",
|
@@ -315,7 +323,8 @@ Gem::Specification.new do |s|
|
|
315
323
|
"test/virtualbox/ext/byte_normalizer_test.rb",
|
316
324
|
"test/virtualbox/ext/subclass_listing_test.rb",
|
317
325
|
"test/virtualbox/ext/platform_test.rb",
|
318
|
-
"test/virtualbox/version_test.rb"
|
326
|
+
"test/virtualbox/version_test.rb",
|
327
|
+
"test/virtualbox/nat_engine_test.rb"
|
319
328
|
]
|
320
329
|
|
321
330
|
if s.respond_to? :specification_version then
|