virtualbox 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -81,9 +81,10 @@ showvminfo
81
81
  end
82
82
 
83
83
  def create_vm
84
- command_seq = sequence("command_seq")
85
- VirtualBox::Command.expects(:vboxmanage).with("showvminfo #{@name} --machinereadable").returns(@raw).in_sequence(command_seq)
86
- VirtualBox::Command.expects(:vboxmanage).with(anything).returns("").at_least(0).in_sequence(command_seq)
84
+ VirtualBox::Command.expects(:vboxmanage).with("showvminfo #{@name} --machinereadable").returns(@raw)
85
+ VirtualBox::Command.expects(:vboxmanage).with("showvminfo #{@name}").returns("")
86
+ VirtualBox::Command.expects(:vboxmanage).with("list hdds").returns("")
87
+ VirtualBox::Command.expects(:vboxmanage).with("list dvds").returns("")
87
88
  vm = VirtualBox::VM.find(@name)
88
89
  assert vm
89
90
  vm
@@ -112,19 +113,103 @@ showvminfo
112
113
  end
113
114
  end
114
115
 
115
- context "starting and stopping" do
116
+ context "exporting a VM" do
116
117
  setup do
117
118
  @vm = create_vm
118
119
  end
119
120
 
121
+ should "export the VM with no options if none are passed" do
122
+ VirtualBox::Command.expects(:vboxmanage).with("export #{@name} -o foo")
123
+ @vm.export("foo")
124
+ end
125
+
126
+ should "export the VM with specified options" do
127
+ VirtualBox::Command.expects(:vboxmanage).with("export #{@name} -o foo --vsys 0 --foo bar")
128
+ @vm.export("foo", :foo => :bar)
129
+ end
130
+
131
+ should "shell escape all the options" do
132
+ VirtualBox::Command.expects(:vboxmanage).with("export #{@name} -o foo --vsys 0 --foo a\\ space")
133
+ @vm.export("foo", :foo => "a space")
134
+ end
135
+
136
+ should "return true if the export succeeded" do
137
+ VirtualBox::Command.expects(:vboxmanage).once
138
+ assert @vm.export("foo")
139
+ end
140
+
141
+ should "return false if the export failed" do
142
+ VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
143
+ assert !@vm.export("foo")
144
+ end
145
+
146
+ should "raise an exception on failure if raise_error is true" do
147
+ VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
148
+ assert_raises(VirtualBox::Exceptions::CommandFailedException) {
149
+ @vm.export("foo", {}, true)
150
+ }
151
+ end
152
+ end
153
+
154
+ context "controlling a VM (start, stop, pause, etc.)" do
155
+ setup do
156
+ @vm = create_vm
157
+ end
158
+
159
+ context "control method" do
160
+ should "run the given command when 'control' is called" do
161
+ VirtualBox::Command.expects(:vboxmanage).with("controlvm #{@name} foo")
162
+ assert @vm.control(:foo)
163
+ end
164
+
165
+ should "return false if the command failed" do
166
+ VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
167
+ assert !@vm.control(:foo)
168
+ end
169
+
170
+ should "raise an exception if flag is set" do
171
+ VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
172
+ assert_raises(VirtualBox::Exceptions::CommandFailedException) {
173
+ @vm.control(:foo, true)
174
+ }
175
+ end
176
+ end
177
+
120
178
  should "start a VM with the given type" do
121
179
  VirtualBox::Command.expects(:vboxmanage).with("startvm #{@name} --type FOO")
122
- @vm.start(:FOO)
180
+ assert @vm.start(:FOO)
181
+ end
182
+
183
+ should "return false if start failed" do
184
+ VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
185
+ assert !@vm.start
186
+ end
187
+
188
+ should "raise an exception if start fails and flag is set" do
189
+ VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
190
+ assert_raises(VirtualBox::Exceptions::CommandFailedException) {
191
+ @vm.start(:foo, true)
192
+ }
123
193
  end
124
194
 
125
195
  should "stop a VM with a 'poweroff'" do
126
- VirtualBox::Command.expects(:vboxmanage).with("controlvm #{@name} poweroff")
127
- @vm.stop
196
+ @vm.expects(:control).with(:poweroff, false).returns(true)
197
+ assert @vm.stop
198
+ end
199
+
200
+ should "pause a VM" do
201
+ @vm.expects(:control).with(:pause, false).returns(true)
202
+ assert @vm.pause
203
+ end
204
+
205
+ should "resume a VM" do
206
+ @vm.expects(:control).with(:resume, false).returns(true)
207
+ assert @vm.resume
208
+ end
209
+
210
+ should "save the state of a VM" do
211
+ @vm.expects(:control).with(:savestate, false).returns(true)
212
+ assert @vm.save_state
128
213
  end
129
214
  end
130
215
 
@@ -215,20 +300,37 @@ raw
215
300
  context "saving a changed VM" do
216
301
  setup do
217
302
  @vm = create_vm
303
+ VirtualBox::AttachedDevice.any_instance.stubs(:save)
304
+ end
305
+
306
+ should "return false if saving fails" do
307
+ VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
308
+
309
+ @vm.ostype = "Zubuntu"
310
+ assert !@vm.save
311
+ end
312
+
313
+ should "raise an error if saving fails and flag to true" do
314
+ VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
315
+
316
+ @vm.ostype = "Zubuntu"
317
+ assert_raises(VirtualBox::Exceptions::CommandFailedException) {
318
+ @vm.save(true)
319
+ }
218
320
  end
219
321
 
220
322
  should "save only the attributes which saved" do
221
323
  VirtualBox::Command.expects(:vboxmanage).with("modifyvm #{@name} --ostype Zubuntu")
222
324
 
223
325
  @vm.ostype = "Zubuntu"
224
- @vm.save
326
+ assert @vm.save
225
327
  end
226
328
 
227
329
  should "shell escape saved values" do
228
330
  VirtualBox::Command.expects(:vboxmanage).with("modifyvm #{@name} --ostype My\\ Value")
229
331
 
230
332
  @vm.ostype = "My Value"
231
- @vm.save
333
+ assert @vm.save
232
334
  end
233
335
 
234
336
  should "shell escape the string value of a value" do
@@ -246,7 +348,13 @@ raw
246
348
 
247
349
  @vm.name = new_name
248
350
  @vm.ostype = "Zubuntu"
249
- @vm.save
351
+ assert @vm.save
352
+ end
353
+
354
+ should "save the relationships as well" do
355
+ VirtualBox::Nic.expects(:save_relationship).once
356
+ VirtualBox::StorageController.expects(:save_relationship).once
357
+ assert @vm.save
250
358
  end
251
359
  end
252
360
 
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.1.1"
8
+ s.version = "0.2.0"
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-01-24}
12
+ s.date = %q{2010-01-26}
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 = [
@@ -17,11 +17,13 @@ Gem::Specification.new do |s|
17
17
  ]
18
18
  s.files = [
19
19
  ".gitignore",
20
+ ".yardopts",
20
21
  "Gemfile",
21
22
  "Rakefile",
22
23
  "Readme.md",
23
24
  "TODO",
24
25
  "VERSION",
26
+ "docs/GettingStarted.md",
25
27
  "lib/virtualbox.rb",
26
28
  "lib/virtualbox/abstract_model.rb",
27
29
  "lib/virtualbox/abstract_model/attributable.rb",
@@ -30,11 +32,12 @@ Gem::Specification.new do |s|
30
32
  "lib/virtualbox/attached_device.rb",
31
33
  "lib/virtualbox/command.rb",
32
34
  "lib/virtualbox/dvd.rb",
33
- "lib/virtualbox/errors.rb",
35
+ "lib/virtualbox/exceptions.rb",
34
36
  "lib/virtualbox/ext/subclass_listing.rb",
35
37
  "lib/virtualbox/hard_drive.rb",
36
38
  "lib/virtualbox/image.rb",
37
39
  "lib/virtualbox/nic.rb",
40
+ "lib/virtualbox/proxies/collection.rb",
38
41
  "lib/virtualbox/storage_controller.rb",
39
42
  "lib/virtualbox/vm.rb",
40
43
  "test/test_helper.rb",
@@ -49,6 +52,7 @@ Gem::Specification.new do |s|
49
52
  "test/virtualbox/hard_drive_test.rb",
50
53
  "test/virtualbox/image_test.rb",
51
54
  "test/virtualbox/nic_test.rb",
55
+ "test/virtualbox/proxies/collection_test.rb",
52
56
  "test/virtualbox/storage_controller_test.rb",
53
57
  "test/virtualbox/vm_test.rb",
54
58
  "virtualbox.gemspec"
@@ -71,6 +75,7 @@ Gem::Specification.new do |s|
71
75
  "test/virtualbox/hard_drive_test.rb",
72
76
  "test/virtualbox/image_test.rb",
73
77
  "test/virtualbox/nic_test.rb",
78
+ "test/virtualbox/proxies/collection_test.rb",
74
79
  "test/virtualbox/storage_controller_test.rb",
75
80
  "test/virtualbox/vm_test.rb"
76
81
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virtualbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell Hashimoto
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-24 00:00:00 -08:00
12
+ date: 2010-01-26 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,11 +23,13 @@ extra_rdoc_files:
23
23
  - TODO
24
24
  files:
25
25
  - .gitignore
26
+ - .yardopts
26
27
  - Gemfile
27
28
  - Rakefile
28
29
  - Readme.md
29
30
  - TODO
30
31
  - VERSION
32
+ - docs/GettingStarted.md
31
33
  - lib/virtualbox.rb
32
34
  - lib/virtualbox/abstract_model.rb
33
35
  - lib/virtualbox/abstract_model/attributable.rb
@@ -36,11 +38,12 @@ files:
36
38
  - lib/virtualbox/attached_device.rb
37
39
  - lib/virtualbox/command.rb
38
40
  - lib/virtualbox/dvd.rb
39
- - lib/virtualbox/errors.rb
41
+ - lib/virtualbox/exceptions.rb
40
42
  - lib/virtualbox/ext/subclass_listing.rb
41
43
  - lib/virtualbox/hard_drive.rb
42
44
  - lib/virtualbox/image.rb
43
45
  - lib/virtualbox/nic.rb
46
+ - lib/virtualbox/proxies/collection.rb
44
47
  - lib/virtualbox/storage_controller.rb
45
48
  - lib/virtualbox/vm.rb
46
49
  - test/test_helper.rb
@@ -55,6 +58,7 @@ files:
55
58
  - test/virtualbox/hard_drive_test.rb
56
59
  - test/virtualbox/image_test.rb
57
60
  - test/virtualbox/nic_test.rb
61
+ - test/virtualbox/proxies/collection_test.rb
58
62
  - test/virtualbox/storage_controller_test.rb
59
63
  - test/virtualbox/vm_test.rb
60
64
  - virtualbox.gemspec
@@ -99,5 +103,6 @@ test_files:
99
103
  - test/virtualbox/hard_drive_test.rb
100
104
  - test/virtualbox/image_test.rb
101
105
  - test/virtualbox/nic_test.rb
106
+ - test/virtualbox/proxies/collection_test.rb
102
107
  - test/virtualbox/storage_controller_test.rb
103
108
  - test/virtualbox/vm_test.rb
@@ -1,7 +0,0 @@
1
- module VirtualBox
2
- # Gem specific exceptions will reside under this namespace for easy
3
- # documentation and searching.
4
- module Errors
5
- class Exception < ::Exception; end
6
- end
7
- end