vagrantup 0.4.3.dev → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/config/default.rb +6 -6
  4. data/lib/vagrant.rb +6 -3
  5. data/lib/vagrant/action.rb +77 -0
  6. data/lib/vagrant/action/action_exception.rb +16 -0
  7. data/lib/vagrant/action/box/destroy.rb +19 -0
  8. data/lib/vagrant/action/box/download.rb +78 -0
  9. data/lib/vagrant/action/box/unpackage.rb +58 -0
  10. data/lib/vagrant/action/box/verify.rb +23 -0
  11. data/lib/vagrant/action/builder.rb +151 -0
  12. data/lib/vagrant/action/builtin.rb +114 -0
  13. data/lib/vagrant/action/env/error_halt.rb +16 -0
  14. data/lib/vagrant/action/env/set.rb +18 -0
  15. data/lib/vagrant/action/environment.rb +98 -0
  16. data/lib/vagrant/action/exception_catcher.rb +14 -0
  17. data/lib/vagrant/action/vm/boot.rb +54 -0
  18. data/lib/vagrant/action/vm/check_box.rb +27 -0
  19. data/lib/vagrant/action/vm/check_guest_additions.rb +32 -0
  20. data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
  21. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
  22. data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
  23. data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
  24. data/lib/vagrant/action/vm/customize.rb +21 -0
  25. data/lib/vagrant/action/vm/destroy.rb +20 -0
  26. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +35 -0
  27. data/lib/vagrant/action/vm/disable_networks.rb +26 -0
  28. data/lib/vagrant/action/vm/export.rb +53 -0
  29. data/lib/vagrant/action/vm/forward_ports.rb +121 -0
  30. data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
  31. data/lib/vagrant/action/vm/halt.rb +34 -0
  32. data/lib/vagrant/action/vm/import.rb +33 -0
  33. data/lib/vagrant/action/vm/match_mac_address.rb +19 -0
  34. data/lib/vagrant/{actions → action}/vm/network.rb +47 -55
  35. data/lib/vagrant/action/vm/nfs.rb +161 -0
  36. data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
  37. data/lib/vagrant/action/vm/package.rb +99 -0
  38. data/lib/vagrant/action/vm/persist.rb +22 -0
  39. data/lib/vagrant/action/vm/provision.rb +50 -0
  40. data/lib/vagrant/action/vm/resume.rb +20 -0
  41. data/lib/vagrant/{actions/vm/shared_folders.rb → action/vm/share_folders.rb} +48 -45
  42. data/lib/vagrant/action/vm/suspend.rb +20 -0
  43. data/lib/vagrant/box.rb +3 -7
  44. data/lib/vagrant/commands/base.rb +1 -3
  45. data/lib/vagrant/commands/package.rb +4 -9
  46. data/lib/vagrant/commands/up.rb +0 -2
  47. data/lib/vagrant/config.rb +15 -1
  48. data/lib/vagrant/downloaders/file.rb +1 -1
  49. data/lib/vagrant/downloaders/http.rb +2 -1
  50. data/lib/vagrant/environment.rb +18 -14
  51. data/lib/vagrant/hosts/base.rb +77 -0
  52. data/lib/vagrant/hosts/bsd.rb +53 -0
  53. data/lib/vagrant/hosts/linux.rb +52 -0
  54. data/lib/vagrant/provisioners/base.rb +17 -9
  55. data/lib/vagrant/provisioners/chef.rb +1 -1
  56. data/lib/vagrant/provisioners/chef_server.rb +4 -8
  57. data/lib/vagrant/provisioners/chef_solo.rb +1 -2
  58. data/lib/vagrant/ssh.rb +12 -4
  59. data/lib/vagrant/systems/base.rb +4 -0
  60. data/lib/vagrant/systems/linux.rb +12 -1
  61. data/lib/vagrant/util.rb +16 -0
  62. data/lib/vagrant/util/busy.rb +59 -0
  63. data/lib/vagrant/util/plain_logger.rb +11 -0
  64. data/lib/vagrant/util/platform.rb +18 -0
  65. data/lib/vagrant/util/resource_logger.rb +128 -0
  66. data/lib/vagrant/version.rb +6 -0
  67. data/lib/vagrant/vm.rb +10 -12
  68. data/templates/chef_solo_solo.erb +2 -1
  69. data/templates/nfs/exports.erb +3 -0
  70. data/templates/nfs/exports_linux.erb +3 -0
  71. data/templates/strings.yml +23 -3
  72. metadata +121 -196
  73. data/.gitignore +0 -11
  74. data/Gemfile +0 -18
  75. data/Rakefile +0 -41
  76. data/VERSION +0 -1
  77. data/bin/.gitignore +0 -0
  78. data/lib/vagrant/actions/base.rb +0 -130
  79. data/lib/vagrant/actions/box/add.rb +0 -23
  80. data/lib/vagrant/actions/box/destroy.rb +0 -14
  81. data/lib/vagrant/actions/box/download.rb +0 -67
  82. data/lib/vagrant/actions/box/unpackage.rb +0 -42
  83. data/lib/vagrant/actions/box/verify.rb +0 -32
  84. data/lib/vagrant/actions/collection.rb +0 -36
  85. data/lib/vagrant/actions/runner.rb +0 -131
  86. data/lib/vagrant/actions/vm/boot.rb +0 -43
  87. data/lib/vagrant/actions/vm/customize.rb +0 -19
  88. data/lib/vagrant/actions/vm/destroy.rb +0 -24
  89. data/lib/vagrant/actions/vm/down.rb +0 -22
  90. data/lib/vagrant/actions/vm/export.rb +0 -45
  91. data/lib/vagrant/actions/vm/forward_ports.rb +0 -134
  92. data/lib/vagrant/actions/vm/halt.rb +0 -24
  93. data/lib/vagrant/actions/vm/import.rb +0 -23
  94. data/lib/vagrant/actions/vm/move_hard_drive.rb +0 -51
  95. data/lib/vagrant/actions/vm/package.rb +0 -94
  96. data/lib/vagrant/actions/vm/provision.rb +0 -49
  97. data/lib/vagrant/actions/vm/reload.rb +0 -17
  98. data/lib/vagrant/actions/vm/resume.rb +0 -16
  99. data/lib/vagrant/actions/vm/start.rb +0 -26
  100. data/lib/vagrant/actions/vm/suspend.rb +0 -16
  101. data/lib/vagrant/actions/vm/up.rb +0 -53
  102. data/lib/vagrant/busy.rb +0 -79
  103. data/lib/vagrant/resource_logger.rb +0 -126
  104. data/lib/vagrant/util/error_helper.rb +0 -13
  105. data/lib/vagrant/util/output_helper.rb +0 -9
  106. data/test/test_helper.rb +0 -149
  107. data/test/vagrant/actions/base_test.rb +0 -32
  108. data/test/vagrant/actions/box/add_test.rb +0 -36
  109. data/test/vagrant/actions/box/destroy_test.rb +0 -17
  110. data/test/vagrant/actions/box/download_test.rb +0 -137
  111. data/test/vagrant/actions/box/unpackage_test.rb +0 -99
  112. data/test/vagrant/actions/box/verify_test.rb +0 -44
  113. data/test/vagrant/actions/collection_test.rb +0 -113
  114. data/test/vagrant/actions/runner_test.rb +0 -268
  115. data/test/vagrant/actions/vm/boot_test.rb +0 -49
  116. data/test/vagrant/actions/vm/customize_test.rb +0 -21
  117. data/test/vagrant/actions/vm/destroy_test.rb +0 -37
  118. data/test/vagrant/actions/vm/down_test.rb +0 -39
  119. data/test/vagrant/actions/vm/export_test.rb +0 -88
  120. data/test/vagrant/actions/vm/forward_ports_test.rb +0 -253
  121. data/test/vagrant/actions/vm/halt_test.rb +0 -65
  122. data/test/vagrant/actions/vm/import_test.rb +0 -45
  123. data/test/vagrant/actions/vm/move_hard_drive_test.rb +0 -106
  124. data/test/vagrant/actions/vm/network_test.rb +0 -291
  125. data/test/vagrant/actions/vm/package_test.rb +0 -254
  126. data/test/vagrant/actions/vm/provision_test.rb +0 -99
  127. data/test/vagrant/actions/vm/reload_test.rb +0 -46
  128. data/test/vagrant/actions/vm/resume_test.rb +0 -26
  129. data/test/vagrant/actions/vm/shared_folders_test.rb +0 -211
  130. data/test/vagrant/actions/vm/start_test.rb +0 -73
  131. data/test/vagrant/actions/vm/suspend_test.rb +0 -26
  132. data/test/vagrant/actions/vm/up_test.rb +0 -96
  133. data/test/vagrant/active_list_test.rb +0 -173
  134. data/test/vagrant/box_test.rb +0 -154
  135. data/test/vagrant/busy_test.rb +0 -78
  136. data/test/vagrant/command_test.rb +0 -53
  137. data/test/vagrant/commands/base_test.rb +0 -139
  138. data/test/vagrant/commands/box/add_test.rb +0 -34
  139. data/test/vagrant/commands/box/list_test.rb +0 -32
  140. data/test/vagrant/commands/box/remove_test.rb +0 -41
  141. data/test/vagrant/commands/destroy_test.rb +0 -44
  142. data/test/vagrant/commands/halt_test.rb +0 -50
  143. data/test/vagrant/commands/init_test.rb +0 -55
  144. data/test/vagrant/commands/package_test.rb +0 -104
  145. data/test/vagrant/commands/provision_test.rb +0 -60
  146. data/test/vagrant/commands/reload_test.rb +0 -44
  147. data/test/vagrant/commands/resume_test.rb +0 -44
  148. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  149. data/test/vagrant/commands/ssh_test.rb +0 -129
  150. data/test/vagrant/commands/status_test.rb +0 -40
  151. data/test/vagrant/commands/suspend_test.rb +0 -44
  152. data/test/vagrant/commands/up_test.rb +0 -47
  153. data/test/vagrant/config_test.rb +0 -287
  154. data/test/vagrant/downloaders/base_test.rb +0 -28
  155. data/test/vagrant/downloaders/file_test.rb +0 -33
  156. data/test/vagrant/downloaders/http_test.rb +0 -62
  157. data/test/vagrant/environment_test.rb +0 -770
  158. data/test/vagrant/provisioners/base_test.rb +0 -33
  159. data/test/vagrant/provisioners/chef_server_test.rb +0 -176
  160. data/test/vagrant/provisioners/chef_solo_test.rb +0 -183
  161. data/test/vagrant/provisioners/chef_test.rb +0 -175
  162. data/test/vagrant/resource_logger_test.rb +0 -145
  163. data/test/vagrant/ssh_session_test.rb +0 -46
  164. data/test/vagrant/ssh_test.rb +0 -296
  165. data/test/vagrant/systems/linux_test.rb +0 -179
  166. data/test/vagrant/util/error_helper_test.rb +0 -5
  167. data/test/vagrant/util/output_helper_test.rb +0 -5
  168. data/test/vagrant/util/plain_logger_test.rb +0 -17
  169. data/test/vagrant/util/platform_test.rb +0 -18
  170. data/test/vagrant/util/stacked_proc_runner_test.rb +0 -43
  171. data/test/vagrant/util/template_renderer_test.rb +0 -144
  172. data/test/vagrant/util/translator_test.rb +0 -61
  173. data/test/vagrant/util_test.rb +0 -27
  174. data/test/vagrant/vm_test.rb +0 -235
  175. data/vagrant.gemspec +0 -291
@@ -1,253 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
-
3
- class ForwardPortsActionTest < Test::Unit::TestCase
4
- setup do
5
- @runner, @vm, @action = mock_action(Vagrant::Actions::VM::ForwardPorts)
6
- end
7
-
8
- context "preparing" do
9
- should "call proper sequence" do
10
- prep_seq = sequence("prepare")
11
- @action.expects(:external_collision_check).in_sequence(prep_seq)
12
- @action.prepare
13
- end
14
- end
15
-
16
- context "checking for colliding external ports" do
17
- setup do
18
- @env = mock_environment do |config|
19
- config.vm.forwarded_ports.clear
20
- config.vm.forward_port("ssh", 22, 2222)
21
- end
22
-
23
- @runner.stubs(:env).returns(@env)
24
-
25
- @used_ports = []
26
- @action.stubs(:used_ports).returns(@used_ports)
27
-
28
- # So no exceptions are raised
29
- @action.stubs(:handle_collision)
30
- end
31
-
32
- should "not raise any errors if no forwarded ports collide" do
33
- @used_ports << "80"
34
- assert_nothing_raised { @action.external_collision_check }
35
- end
36
-
37
- should "handle the collision if it happens" do
38
- @used_ports << "2222"
39
- @action.expects(:handle_collision).with("ssh", anything, anything).once
40
- @action.external_collision_check
41
- end
42
- end
43
-
44
- context "handling collisions" do
45
- setup do
46
- @name = :foo
47
- @options = {
48
- :hostport => 0,
49
- :auto => true
50
- }
51
- @used_ports = [1,2,3]
52
-
53
- @runner.env.config.vm.auto_port_range = (1..5)
54
- end
55
-
56
- should "raise an exception if auto forwarding is disabled" do
57
- @options[:auto] = false
58
-
59
- assert_raises(Vagrant::Actions::ActionException) {
60
- @action.handle_collision(@name, @options, @used_ports)
61
- }
62
- end
63
-
64
- should "set the host port to the first available port" do
65
- assert_equal 0, @options[:hostport]
66
- @action.handle_collision(@name, @options, @used_ports)
67
- assert_equal 4, @options[:hostport]
68
- end
69
-
70
- should "add the newly used port to the list of used ports" do
71
- assert !@used_ports.include?(4)
72
- @action.handle_collision(@name, @options, @used_ports)
73
- assert @used_ports.include?(4)
74
- end
75
-
76
- should "not use a host port which is being forwarded later" do
77
- @runner.env.config.vm.forward_port("http", 80, 4)
78
-
79
- assert_equal 0, @options[:hostport]
80
- @action.handle_collision(@name, @options, @used_ports)
81
- assert_equal 5, @options[:hostport]
82
- end
83
-
84
- should "raise an exception if there are no auto ports available" do
85
- @runner.env.config.vm.auto_port_range = (1..3)
86
- assert_raises(Vagrant::Actions::ActionException) {
87
- @action.handle_collision(@name, @options, @used_ports)
88
- }
89
- end
90
- end
91
-
92
- context "execution" do
93
- should "clear all previous ports and forward new ports" do
94
- exec_seq = sequence("exec_seq")
95
- @action.expects(:clear).once.in_sequence(exec_seq)
96
- @action.expects(:forward_ports).once.in_sequence(exec_seq)
97
- @action.execute!
98
- end
99
- end
100
-
101
- context "forwarding ports" do
102
- should "create a port forwarding for the VM" do
103
- forwarded_ports = mock("forwarded_ports")
104
- network_adapter = mock("network_adapter")
105
-
106
- @vm.stubs(:network_adapters).returns([network_adapter])
107
- network_adapter.expects(:attachment_type).returns(:nat)
108
-
109
- @action.expects(:forward_port).once
110
- @vm.expects(:save).once
111
- @runner.expects(:reload!).once
112
- @action.forward_ports
113
- end
114
-
115
- should "No port forwarding for non NAT interfaces" do
116
- forwarded_ports = mock("forwarded_ports")
117
- network_adapter = mock("network_adapter")
118
-
119
- @vm.expects(:network_adapters).returns([network_adapter])
120
- network_adapter.expects(:attachment_type).returns(:host_only)
121
- @vm.expects(:save).once
122
- @runner.expects(:reload!).once
123
- @action.forward_ports
124
- end
125
- end
126
-
127
- context "clearing forwarded ports" do
128
- setup do
129
- @action.stubs(:used_ports).returns([:a])
130
- @action.stubs(:clear_ports)
131
- end
132
-
133
- should "call destroy on all forwarded ports" do
134
- @action.expects(:clear_ports).once
135
- @runner.expects(:reload!)
136
- @action.clear
137
- end
138
-
139
- should "do nothing if there are no forwarded ports" do
140
- @action.stubs(:used_ports).returns([])
141
- @runner.expects(:reload!).never
142
- @action.clear
143
- end
144
- end
145
-
146
- context "getting list of used ports" do
147
- setup do
148
- @vms = []
149
- VirtualBox::VM.stubs(:all).returns(@vms)
150
- VirtualBox.stubs(:version).returns("3.1.0")
151
- @runner.stubs(:uuid).returns(:bar)
152
- end
153
-
154
- def mock_vm(options={})
155
- options = {
156
- :running? => true,
157
- :uuid => :foo
158
- }.merge(options)
159
-
160
- vm = mock("vm")
161
- options.each do |k,v|
162
- vm.stubs(k).returns(v)
163
- end
164
-
165
- vm
166
- end
167
-
168
- def mock_fp(hostport)
169
- fp = mock("fp")
170
- fp.stubs(:hostport).returns(hostport.to_s)
171
- fp
172
- end
173
-
174
- should "ignore VMs which aren't running" do
175
- @vms << mock_vm(:running? => false)
176
- @vms[0].expects(:forwarded_ports).never
177
- @action.used_ports
178
- end
179
-
180
- should "ignore VMs of the same uuid" do
181
- @vms << mock_vm(:uuid => @runner.uuid)
182
- @vms[0].expects(:forwarded_ports).never
183
- @action.used_ports
184
- end
185
-
186
- should "return the forwarded ports for VB 3.2.x" do
187
- VirtualBox.stubs(:version).returns("3.2.4")
188
- fps = [mock_fp(2222), mock_fp(80)]
189
- na = mock("na")
190
- ne = mock("ne")
191
- na.stubs(:nat_driver).returns(ne)
192
- ne.stubs(:forwarded_ports).returns(fps)
193
- @vms << mock_vm(:network_adapters => [na])
194
- assert_equal %W[2222 80], @action.used_ports
195
- end
196
- end
197
-
198
- context "clearing ports" do
199
- def mock_fp
200
- fp = mock("fp")
201
- fp.expects(:destroy).once
202
- fp
203
- end
204
-
205
- setup do
206
- VirtualBox.stubs(:version).returns("3.2.8")
207
- @adapters = []
208
- @vm.stubs(:network_adapters).returns(@adapters)
209
- end
210
-
211
- def mock_adapter
212
- na = mock("adapter")
213
- engine = mock("engine")
214
- engine.stubs(:forwarded_ports).returns([mock_fp])
215
- na.stubs(:nat_driver).returns(engine)
216
- na
217
- end
218
-
219
- should "destroy each forwarded port" do
220
- @adapters << mock_adapter
221
- @adapters << mock_adapter
222
- @action.clear_ports
223
- end
224
- end
225
-
226
- context "forwarding ports implementation" do
227
- setup do
228
- VirtualBox.stubs(:version).returns("3.2.8")
229
- end
230
-
231
- should "forward ports" do
232
- name, opts = @runner.env.config.vm.forwarded_ports.first
233
-
234
- adapters = []
235
- adapter = mock("adapter")
236
- engine = mock("engine")
237
- fps = mock("forwarded ports")
238
- adapter.stubs(:nat_driver).returns(engine)
239
- engine.stubs(:forwarded_ports).returns(fps)
240
- fps.expects(:<<).with do |port|
241
- assert_equal name, port.name
242
- assert_equal opts[:hostport], port.hostport
243
- assert_equal opts[:guestport], port.guestport
244
- true
245
- end
246
-
247
- adapters[opts[:adapter]] = adapter
248
- @vm.stubs(:network_adapters).returns(adapters)
249
-
250
- @action.forward_port(name, opts)
251
- end
252
- end
253
- end
@@ -1,65 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
-
3
- class HaltActionTest < Test::Unit::TestCase
4
- setup do
5
- @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Halt)
6
- @runner.stubs(:system).returns(linux_system(@vm))
7
- end
8
-
9
- context "force?" do
10
- should "not force by default" do
11
- @action.options[:force] = nil
12
- assert !@action.force?
13
- end
14
-
15
- should "force if specified" do
16
- @action.options[:force] = true
17
- assert @action.force?
18
- end
19
- end
20
-
21
- context "executing" do
22
- setup do
23
- @vm.stubs(:running?).returns(true)
24
-
25
- @runner.system.stubs(:halt)
26
- @vm.stubs(:stop)
27
- @vm.stubs(:state).returns(:powered_off)
28
- end
29
-
30
- should "invoke the 'halt' around callback" do
31
- @runner.expects(:invoke_around_callback).with(:halt).once
32
- @action.execute!
33
- end
34
-
35
- should "halt with the system and NOT force VM to stop if powered off" do
36
- @vm.expects(:state).with(true).returns(:powered_off)
37
-
38
- @runner.system.expects(:halt).once
39
- @vm.expects(:stop).never
40
- @action.execute!
41
- end
42
-
43
- should "halt with the system and force VM to stop if NOT powered off" do
44
- @vm.expects(:state).with(true).returns(:running)
45
-
46
- @runner.system.expects(:halt).once
47
- @vm.expects(:stop).once
48
- @action.execute!
49
- end
50
-
51
- should "not call halt on the system if forcing" do
52
- @action.stubs(:force).returns(true)
53
- @runner.system.expects(:halt).never
54
- @action.execute!
55
- end
56
-
57
- should "raise an ActionException if VM is not running" do
58
- @vm.stubs(:running?).returns(false)
59
- @vm.expects(:stop).never
60
- assert_raises(Vagrant::Actions::ActionException) {
61
- @action.execute!
62
- }
63
- end
64
- end
65
- end
@@ -1,45 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
-
3
- class ImportActionTest < Test::Unit::TestCase
4
- setup do
5
- @runner, @vm, @import = mock_action(Vagrant::Actions::VM::Import)
6
-
7
- @ovf_file = "foo"
8
- @box = mock("box")
9
- @box.stubs(:ovf_file).returns(@ovf_file)
10
- @runner.env.stubs(:box).returns(@box)
11
-
12
- VirtualBox::VM.stubs(:import)
13
-
14
- @import.stubs(:complete_progress)
15
- end
16
-
17
- should "run in a busy block" do
18
- Vagrant::Busy.expects(:busy).once
19
- @import.execute!
20
- end
21
-
22
- should "invoke an around callback around the import" do
23
- @runner.expects(:invoke_around_callback).with(:import).once
24
- @import.execute!
25
- end
26
-
27
- should "call import on VirtualBox::VM with the proper base" do
28
- VirtualBox::VM.expects(:import).once.with(@ovf_file).returns("foo")
29
- assert_nothing_raised { @import.execute! }
30
- end
31
-
32
- should "raise an exception if import is nil" do
33
- @runner.expects(:vm).returns(nil)
34
- assert_raises(Vagrant::Actions::ActionException) {
35
- @import.execute!
36
- }
37
- end
38
-
39
- should "set the resulting VM as the VM of the Vagrant VM object" do
40
- new_vm = mock("new_vm")
41
- @runner.expects(:vm=).with(new_vm).once
42
- VirtualBox::VM.expects(:import).returns(new_vm).returns("foo")
43
- @import.execute!
44
- end
45
- end
@@ -1,106 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
-
3
- class MoveHardDriveActionTest < Test::Unit::TestCase
4
- setup do
5
- @mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::MoveHardDrive)
6
- @hd_location = "/foo"
7
-
8
- @mock_vm.env.config.vm.stubs(:hd_location).returns(@hd_location)
9
- end
10
-
11
-
12
- should "be able to identifiy a hard drive within the storage controllers" do
13
- hd = mock('hd')
14
- hd_image = mock('hd_image')
15
- hd_image.expects(:is_a?).returns(true)
16
- hd.expects(:image).returns(hd_image)
17
-
18
- dvd = mock('dvd')
19
- controller = mock('controller')
20
- controller.expects(:devices).returns([hd, dvd])
21
-
22
- @vm.expects(:storage_controllers).once.returns([controller])
23
- assert_equal @action.find_hard_drive, hd
24
- end
25
-
26
- context "execution" do
27
- should "error and exit if the vm is not powered off" do
28
- @mock_vm.expects(:powered_off?).returns(false)
29
- @action.expects(:error_and_exit).with(:vm_power_off_to_move_hd).once
30
- @action.execute!
31
- end
32
-
33
- should "move the hard drive if vm is powered off" do
34
- @mock_vm.expects(:powered_off?).returns(true)
35
- @action.expects(:error_and_exit).never
36
- @action.expects(:destroy_drive_after).once
37
- @action.execute!
38
- end
39
- end
40
-
41
- context "new image path" do
42
- setup do
43
- @hd = mock("hd")
44
- @image = mock("image")
45
- @filename = "foo"
46
- @hd.stubs(:image).returns(@image)
47
- @image.stubs(:filename).returns(@filename)
48
- @action.stubs(:hard_drive).returns(@hd)
49
- end
50
-
51
- should "be the configured hd location and the existing hard drive filename" do
52
- joined = File.join(@mock_vm.env.config.vm.hd_location, @filename)
53
- assert_equal joined, @action.new_image_path
54
- end
55
- end
56
-
57
- context "cloning and attaching new image" do
58
- setup do
59
- @hd = mock("hd")
60
- @image = mock("image")
61
- @hd.stubs(:image).returns(@image)
62
- @action.stubs(:hard_drive).returns(@hd)
63
- @new_image_path = "foo"
64
- @action.stubs(:new_image_path).returns(@new_image_path)
65
- end
66
-
67
- should "clone to the new path" do
68
- new_image = mock("new_image")
69
- @image.expects(:clone).with(@new_image_path, Vagrant.config.vm.disk_image_format, true).returns(new_image).once
70
- @hd.expects(:image=).with(new_image).once
71
- @vm.expects(:save).once
72
- @action.clone_and_attach
73
- end
74
- end
75
-
76
- context "destroying the old image" do
77
- setup do
78
- @hd = mock("hd")
79
- @action.stubs(:hard_drive).returns(@hd)
80
- end
81
-
82
- should "yield the block, and destroy the old image after" do
83
- image = mock("image")
84
- image.stubs(:filename).returns("foo")
85
- destroy_seq = sequence("destroy_seq")
86
- @hd.expects(:image).returns(image).in_sequence(destroy_seq)
87
- @hd.expects(:foo).once.in_sequence(destroy_seq)
88
- image.expects(:destroy).with(true).once.in_sequence(destroy_seq)
89
-
90
- @action.destroy_drive_after { @hd.foo }
91
- end
92
-
93
- # Ensures that the image is not destroyed in an "ensure" block
94
- should "not destroy the image if an exception is raised" do
95
- image = mock("image")
96
- image.expects(:destroy).never
97
- @hd.expects(:image).returns(image)
98
-
99
- assert_raises(Exception) do
100
- @action.destroy_drive_after do
101
- raise Exception.new("FOO")
102
- end
103
- end
104
- end
105
- end
106
- end