vagrant 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/README.md +1 -0
  2. data/config/default.rb +6 -6
  3. data/lib/vagrant.rb +6 -3
  4. data/lib/vagrant/action.rb +77 -0
  5. data/lib/vagrant/action/action_exception.rb +16 -0
  6. data/lib/vagrant/action/box/destroy.rb +19 -0
  7. data/lib/vagrant/action/box/download.rb +78 -0
  8. data/lib/vagrant/action/box/unpackage.rb +58 -0
  9. data/lib/vagrant/action/box/verify.rb +23 -0
  10. data/lib/vagrant/action/builder.rb +151 -0
  11. data/lib/vagrant/action/builtin.rb +114 -0
  12. data/lib/vagrant/action/env/error_halt.rb +16 -0
  13. data/lib/vagrant/action/env/set.rb +18 -0
  14. data/lib/vagrant/action/environment.rb +98 -0
  15. data/lib/vagrant/action/exception_catcher.rb +14 -0
  16. data/lib/vagrant/action/vm/boot.rb +54 -0
  17. data/lib/vagrant/action/vm/check_box.rb +27 -0
  18. data/lib/vagrant/action/vm/check_guest_additions.rb +32 -0
  19. data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
  20. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
  21. data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
  22. data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
  23. data/lib/vagrant/action/vm/customize.rb +21 -0
  24. data/lib/vagrant/action/vm/destroy.rb +20 -0
  25. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +35 -0
  26. data/lib/vagrant/action/vm/disable_networks.rb +26 -0
  27. data/lib/vagrant/action/vm/export.rb +53 -0
  28. data/lib/vagrant/action/vm/forward_ports.rb +121 -0
  29. data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
  30. data/lib/vagrant/action/vm/halt.rb +34 -0
  31. data/lib/vagrant/action/vm/import.rb +33 -0
  32. data/lib/vagrant/action/vm/match_mac_address.rb +19 -0
  33. data/lib/vagrant/{actions → action}/vm/network.rb +47 -55
  34. data/lib/vagrant/action/vm/nfs.rb +161 -0
  35. data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
  36. data/lib/vagrant/action/vm/package.rb +99 -0
  37. data/lib/vagrant/action/vm/persist.rb +22 -0
  38. data/lib/vagrant/action/vm/provision.rb +50 -0
  39. data/lib/vagrant/action/vm/resume.rb +20 -0
  40. data/lib/vagrant/{actions/vm/shared_folders.rb → action/vm/share_folders.rb} +48 -45
  41. data/lib/vagrant/action/vm/suspend.rb +20 -0
  42. data/lib/vagrant/box.rb +3 -7
  43. data/lib/vagrant/commands/base.rb +1 -3
  44. data/lib/vagrant/commands/package.rb +4 -9
  45. data/lib/vagrant/commands/up.rb +0 -2
  46. data/lib/vagrant/config.rb +15 -1
  47. data/lib/vagrant/downloaders/file.rb +1 -1
  48. data/lib/vagrant/downloaders/http.rb +2 -1
  49. data/lib/vagrant/environment.rb +18 -14
  50. data/lib/vagrant/hosts/base.rb +77 -0
  51. data/lib/vagrant/hosts/bsd.rb +53 -0
  52. data/lib/vagrant/hosts/linux.rb +52 -0
  53. data/lib/vagrant/provisioners/base.rb +17 -9
  54. data/lib/vagrant/provisioners/chef.rb +1 -1
  55. data/lib/vagrant/provisioners/chef_server.rb +4 -8
  56. data/lib/vagrant/provisioners/chef_solo.rb +1 -2
  57. data/lib/vagrant/ssh.rb +12 -4
  58. data/lib/vagrant/systems/base.rb +4 -0
  59. data/lib/vagrant/systems/linux.rb +12 -1
  60. data/lib/vagrant/util.rb +16 -0
  61. data/lib/vagrant/util/busy.rb +59 -0
  62. data/lib/vagrant/util/plain_logger.rb +11 -0
  63. data/lib/vagrant/util/platform.rb +18 -0
  64. data/lib/vagrant/util/resource_logger.rb +128 -0
  65. data/lib/vagrant/version.rb +6 -0
  66. data/lib/vagrant/vm.rb +10 -12
  67. data/templates/chef_solo_solo.erb +2 -1
  68. data/templates/nfs/exports.erb +3 -0
  69. data/templates/nfs/exports_linux.erb +3 -0
  70. data/templates/strings.yml +23 -3
  71. metadata +128 -198
  72. data/.gitignore +0 -11
  73. data/Gemfile +0 -18
  74. data/Rakefile +0 -41
  75. data/VERSION +0 -1
  76. data/bin/.gitignore +0 -0
  77. data/lib/vagrant/actions/base.rb +0 -130
  78. data/lib/vagrant/actions/box/add.rb +0 -23
  79. data/lib/vagrant/actions/box/destroy.rb +0 -14
  80. data/lib/vagrant/actions/box/download.rb +0 -67
  81. data/lib/vagrant/actions/box/unpackage.rb +0 -42
  82. data/lib/vagrant/actions/box/verify.rb +0 -32
  83. data/lib/vagrant/actions/collection.rb +0 -36
  84. data/lib/vagrant/actions/runner.rb +0 -131
  85. data/lib/vagrant/actions/vm/boot.rb +0 -43
  86. data/lib/vagrant/actions/vm/customize.rb +0 -19
  87. data/lib/vagrant/actions/vm/destroy.rb +0 -24
  88. data/lib/vagrant/actions/vm/down.rb +0 -22
  89. data/lib/vagrant/actions/vm/export.rb +0 -45
  90. data/lib/vagrant/actions/vm/forward_ports.rb +0 -134
  91. data/lib/vagrant/actions/vm/halt.rb +0 -24
  92. data/lib/vagrant/actions/vm/import.rb +0 -23
  93. data/lib/vagrant/actions/vm/move_hard_drive.rb +0 -51
  94. data/lib/vagrant/actions/vm/package.rb +0 -94
  95. data/lib/vagrant/actions/vm/provision.rb +0 -49
  96. data/lib/vagrant/actions/vm/reload.rb +0 -17
  97. data/lib/vagrant/actions/vm/resume.rb +0 -16
  98. data/lib/vagrant/actions/vm/start.rb +0 -26
  99. data/lib/vagrant/actions/vm/suspend.rb +0 -16
  100. data/lib/vagrant/actions/vm/up.rb +0 -53
  101. data/lib/vagrant/busy.rb +0 -79
  102. data/lib/vagrant/resource_logger.rb +0 -126
  103. data/lib/vagrant/util/error_helper.rb +0 -13
  104. data/lib/vagrant/util/output_helper.rb +0 -9
  105. data/test/test_helper.rb +0 -149
  106. data/test/vagrant/actions/base_test.rb +0 -32
  107. data/test/vagrant/actions/box/add_test.rb +0 -36
  108. data/test/vagrant/actions/box/destroy_test.rb +0 -17
  109. data/test/vagrant/actions/box/download_test.rb +0 -137
  110. data/test/vagrant/actions/box/unpackage_test.rb +0 -99
  111. data/test/vagrant/actions/box/verify_test.rb +0 -44
  112. data/test/vagrant/actions/collection_test.rb +0 -113
  113. data/test/vagrant/actions/runner_test.rb +0 -268
  114. data/test/vagrant/actions/vm/boot_test.rb +0 -49
  115. data/test/vagrant/actions/vm/customize_test.rb +0 -21
  116. data/test/vagrant/actions/vm/destroy_test.rb +0 -37
  117. data/test/vagrant/actions/vm/down_test.rb +0 -39
  118. data/test/vagrant/actions/vm/export_test.rb +0 -88
  119. data/test/vagrant/actions/vm/forward_ports_test.rb +0 -253
  120. data/test/vagrant/actions/vm/halt_test.rb +0 -65
  121. data/test/vagrant/actions/vm/import_test.rb +0 -45
  122. data/test/vagrant/actions/vm/move_hard_drive_test.rb +0 -106
  123. data/test/vagrant/actions/vm/network_test.rb +0 -291
  124. data/test/vagrant/actions/vm/package_test.rb +0 -254
  125. data/test/vagrant/actions/vm/provision_test.rb +0 -99
  126. data/test/vagrant/actions/vm/reload_test.rb +0 -46
  127. data/test/vagrant/actions/vm/resume_test.rb +0 -26
  128. data/test/vagrant/actions/vm/shared_folders_test.rb +0 -211
  129. data/test/vagrant/actions/vm/start_test.rb +0 -73
  130. data/test/vagrant/actions/vm/suspend_test.rb +0 -26
  131. data/test/vagrant/actions/vm/up_test.rb +0 -96
  132. data/test/vagrant/active_list_test.rb +0 -173
  133. data/test/vagrant/box_test.rb +0 -154
  134. data/test/vagrant/busy_test.rb +0 -78
  135. data/test/vagrant/command_test.rb +0 -53
  136. data/test/vagrant/commands/base_test.rb +0 -139
  137. data/test/vagrant/commands/box/add_test.rb +0 -34
  138. data/test/vagrant/commands/box/list_test.rb +0 -32
  139. data/test/vagrant/commands/box/remove_test.rb +0 -41
  140. data/test/vagrant/commands/destroy_test.rb +0 -44
  141. data/test/vagrant/commands/halt_test.rb +0 -50
  142. data/test/vagrant/commands/init_test.rb +0 -55
  143. data/test/vagrant/commands/package_test.rb +0 -104
  144. data/test/vagrant/commands/provision_test.rb +0 -60
  145. data/test/vagrant/commands/reload_test.rb +0 -44
  146. data/test/vagrant/commands/resume_test.rb +0 -44
  147. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  148. data/test/vagrant/commands/ssh_test.rb +0 -129
  149. data/test/vagrant/commands/status_test.rb +0 -40
  150. data/test/vagrant/commands/suspend_test.rb +0 -44
  151. data/test/vagrant/commands/up_test.rb +0 -47
  152. data/test/vagrant/config_test.rb +0 -287
  153. data/test/vagrant/downloaders/base_test.rb +0 -28
  154. data/test/vagrant/downloaders/file_test.rb +0 -33
  155. data/test/vagrant/downloaders/http_test.rb +0 -62
  156. data/test/vagrant/environment_test.rb +0 -770
  157. data/test/vagrant/provisioners/base_test.rb +0 -33
  158. data/test/vagrant/provisioners/chef_server_test.rb +0 -176
  159. data/test/vagrant/provisioners/chef_solo_test.rb +0 -183
  160. data/test/vagrant/provisioners/chef_test.rb +0 -175
  161. data/test/vagrant/resource_logger_test.rb +0 -145
  162. data/test/vagrant/ssh_session_test.rb +0 -46
  163. data/test/vagrant/ssh_test.rb +0 -296
  164. data/test/vagrant/systems/linux_test.rb +0 -179
  165. data/test/vagrant/util/error_helper_test.rb +0 -5
  166. data/test/vagrant/util/output_helper_test.rb +0 -5
  167. data/test/vagrant/util/plain_logger_test.rb +0 -17
  168. data/test/vagrant/util/platform_test.rb +0 -18
  169. data/test/vagrant/util/stacked_proc_runner_test.rb +0 -43
  170. data/test/vagrant/util/template_renderer_test.rb +0 -144
  171. data/test/vagrant/util/translator_test.rb +0 -61
  172. data/test/vagrant/util_test.rb +0 -27
  173. data/test/vagrant/vm_test.rb +0 -235
  174. data/vagrant.gemspec +0 -291
@@ -1,291 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
-
3
- class NetworkTest < Test::Unit::TestCase
4
- setup do
5
- @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Network)
6
- @runner.stubs(:system).returns(linux_system(@vm))
7
-
8
- @interfaces = []
9
- VirtualBox::Global.global.host.stubs(:network_interfaces).returns(@interfaces)
10
- end
11
-
12
- def mock_interface(options=nil)
13
- options = {
14
- :interface_type => :host_only,
15
- :name => "foo"
16
- }.merge(options || {})
17
-
18
- interface = mock("interface")
19
- options.each do |k,v|
20
- interface.stubs(k).returns(v)
21
- end
22
-
23
- @interfaces << interface
24
- interface
25
- end
26
-
27
- context "preparing" do
28
- should "verify no bridge collisions for each network enabled" do
29
- @runner.env.config.vm.network("foo")
30
- @action.expects(:verify_no_bridge_collision).once.with() do |options|
31
- assert_equal "foo", options[:ip]
32
- true
33
- end
34
-
35
- @action.prepare
36
- end
37
- end
38
-
39
- context "before destroy" do
40
- setup do
41
- @network_adapters = []
42
- @vm.stubs(:network_adapters).returns(@network_adapters)
43
- end
44
-
45
- def stub_interface(length=5)
46
- interface = mock("interface")
47
- adapter = mock("adapter")
48
- adapter.stubs(:host_interface_object).returns(interface)
49
- interface.stubs(:attached_vms).returns(Array.new(length))
50
-
51
- @network_adapters << adapter
52
- interface
53
- end
54
-
55
- should "destroy only the unused network interfaces" do
56
- stub_interface(5)
57
- stub_interface(7)
58
- results = [stub_interface(1), stub_interface(1)]
59
-
60
- results.each do |result|
61
- result.expects(:destroy).once
62
- end
63
-
64
- @action.before_destroy
65
- end
66
- end
67
-
68
- context "before boot" do
69
- setup do
70
- @action.stubs(:enable_network?).returns(false)
71
- end
72
-
73
- should "do nothing if network should not be enabled" do
74
- @action.expects(:assign_network).never
75
- @action.before_boot
76
- end
77
-
78
- should "assign the network if host only networking is enabled" do
79
- @action.stubs(:enable_network?).returns(true)
80
- @action.expects(:assign_network).once
81
- @action.before_boot
82
- end
83
- end
84
-
85
- context "after boot" do
86
- setup do
87
- @runner.env.config.vm.network("foo")
88
- @action.stubs(:enable_network?).returns(true)
89
- end
90
-
91
- should "prepare the host only network, then enable them" do
92
- run_seq = sequence("run")
93
- @runner.system.expects(:prepare_host_only_network).once.in_sequence(run_seq)
94
- @runner.system.expects(:enable_host_only_network).once.in_sequence(run_seq)
95
- @action.after_boot
96
- end
97
-
98
- should "do nothing if network is not enabled" do
99
- @action.stubs(:enable_network?).returns(false)
100
- @runner.system.expects(:prepare_host_only_network).never
101
- @action.after_boot
102
- end
103
- end
104
-
105
- context "checking if network is enabled" do
106
- should "return true if the network options are set" do
107
- @runner.env.config.vm.network("foo")
108
- assert @action.enable_network?
109
- end
110
-
111
- should "return false if the network was not set" do
112
- assert !@action.enable_network?
113
- end
114
- end
115
-
116
- context "assigning the network" do
117
- setup do
118
- @network_name = "foo"
119
- @action.stubs(:network_name).returns(@network_name)
120
-
121
- @network_adapters = []
122
- @vm.stubs(:network_adapters).returns(@network_adapters)
123
-
124
- @options = {
125
- :ip => "foo",
126
- :adapter => 7
127
- }
128
-
129
- @runner.env.config.vm.network(@options[:ip], @options)
130
- end
131
-
132
- should "setup the specified network adapter" do
133
- adapter = mock("adapter")
134
- @network_adapters[@options[:adapter]] = adapter
135
-
136
- adapter.expects(:enabled=).with(true).once
137
- adapter.expects(:attachment_type=).with(:host_only).once
138
- adapter.expects(:host_interface=).with(@network_name).once
139
- adapter.expects(:save).once
140
-
141
- @action.assign_network
142
- end
143
- end
144
-
145
- context "verify no bridge collision" do
146
- setup do
147
- @action.stubs(:matching_network?).returns(false)
148
- @options = { :ip => :foo, :netmask => :bar, :name => nil }
149
- end
150
-
151
- should "do nothing if everything is okay" do
152
- mock_interface
153
-
154
- assert_nothing_raised { @action.verify_no_bridge_collision(@options) }
155
- end
156
-
157
- should "raise an exception if a collision is found" do
158
- mock_interface(:interface_type => :bridged)
159
- @action.stubs(:matching_network?).returns(true)
160
-
161
- assert_raises(Vagrant::Actions::ActionException) {
162
- @action.verify_no_bridge_collision(@options)
163
- }
164
- end
165
- end
166
-
167
- context "network name" do
168
- setup do
169
- @action.stubs(:matching_network?).returns(false)
170
-
171
- @options = { :ip => :foo, :netmask => :bar, :name => nil }
172
- end
173
-
174
- should "return the network which matches" do
175
- result = mock("result")
176
- interface = mock_interface(:name => result)
177
-
178
- @action.expects(:matching_network?).with(interface, @options).returns(true)
179
- assert_equal result, @action.network_name(@options)
180
- end
181
-
182
- should "ignore non-host only interfaces" do
183
- @options[:name] = "foo"
184
- mock_interface(:name => @options[:name],
185
- :interface_type => :bridged)
186
-
187
- assert_raises(Vagrant::Actions::ActionException) {
188
- @action.network_name(@options)
189
- }
190
- end
191
-
192
- should "return the network which matches the name if given" do
193
- @options[:name] = "foo"
194
-
195
- interface = mock_interface(:name => @options[:name])
196
- assert_equal @options[:name], @action.network_name(@options)
197
- end
198
-
199
- should "error and exit if the given network name is not found" do
200
- @options[:name] = "foo"
201
-
202
- @interfaces.expects(:create).never
203
-
204
- assert_raises(Vagrant::Actions::ActionException) {
205
- @action.network_name(@options)
206
- }
207
- end
208
-
209
- should "create a network for the IP and netmask" do
210
- result = mock("result")
211
- network_ip = :foo
212
-
213
- interface = mock_interface(:name => result)
214
- interface.expects(:enable_static).with(network_ip, @options[:netmask])
215
- @interfaces.expects(:create).returns(interface)
216
- @action.expects(:network_ip).with(@options[:ip], @options[:netmask]).once.returns(network_ip)
217
-
218
- assert_equal result, @action.network_name(@options)
219
- end
220
- end
221
-
222
- context "checking for a matching network" do
223
- setup do
224
- @interface = mock("interface")
225
- @interface.stubs(:network_mask).returns("foo")
226
- @interface.stubs(:ip_address).returns("192.168.0.1")
227
-
228
- @options = {
229
- :netmask => "foo",
230
- :ip => "baz"
231
- }
232
- end
233
-
234
- should "return false if the netmasks don't match" do
235
- @options[:netmask] = "bar"
236
- assert @interface.network_mask != @options[:netmask] # sanity
237
- assert !@action.matching_network?(@interface, @options)
238
- end
239
-
240
- should "return true if the netmasks yield the same IP" do
241
- tests = [["255.255.255.0", "192.168.0.1", "192.168.0.45"],
242
- ["255.255.0.0", "192.168.45.1", "192.168.28.7"]]
243
-
244
- tests.each do |netmask, interface_ip, guest_ip|
245
- @options[:netmask] = netmask
246
- @options[:ip] = guest_ip
247
- @interface.stubs(:network_mask).returns(netmask)
248
- @interface.stubs(:ip_address).returns(interface_ip)
249
-
250
- assert @action.matching_network?(@interface, @options)
251
- end
252
- end
253
- end
254
-
255
- context "applying the netmask" do
256
- should "return the proper result" do
257
- tests = {
258
- ["192.168.0.1","255.255.255.0"] => [192,168,0,0],
259
- ["192.168.45.10","255.255.255.0"] => [192,168,45,0]
260
- }
261
-
262
- tests.each do |k,v|
263
- assert_equal v, @action.apply_netmask(*k)
264
- end
265
- end
266
- end
267
-
268
- context "splitting an IP" do
269
- should "return the proper result" do
270
- tests = {
271
- "192.168.0.1" => [192,168,0,1]
272
- }
273
-
274
- tests.each do |k,v|
275
- assert_equal v, @action.split_ip(k)
276
- end
277
- end
278
- end
279
-
280
- context "network IP" do
281
- should "return the proper result" do
282
- tests = {
283
- ["192.168.0.45", "255.255.255.0"] => "192.168.0.1"
284
- }
285
-
286
- tests.each do |args, result|
287
- assert_equal result, @action.network_ip(*args)
288
- end
289
- end
290
- end
291
- end
@@ -1,254 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
-
3
- class PackageActionTest < Test::Unit::TestCase
4
- setup do
5
- @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package)
6
- end
7
-
8
- context "initialization" do
9
- def get_action(output, include_files)
10
- runner, vm, action = mock_action(Vagrant::Actions::VM::Package, {
11
- :output => output,
12
- :include => include_files
13
- })
14
- return action
15
- end
16
-
17
- should "make out_path 'package' by default if nil is given" do
18
- action = get_action(nil, [])
19
- assert_equal "package", action.out_path
20
- end
21
-
22
- should "make include files an empty array by default" do
23
- action = get_action("foo", nil)
24
- assert action.include_files.is_a?(Array)
25
- assert action.include_files.empty?
26
- end
27
- end
28
-
29
- context "executing" do
30
- setup do
31
- @action.stubs(:compress)
32
- end
33
-
34
- should "compress" do
35
- package_seq = sequence("package_seq")
36
- @action.expects(:compress).in_sequence(package_seq)
37
- @action.execute!
38
- end
39
- end
40
-
41
- context "out path" do
42
- should "be the specified output file if given" do
43
- result = mock("result")
44
- @action.options[:output] = result
45
- assert_equal result, @action.out_path
46
- end
47
-
48
- should "default to 'package'" do
49
- @action.options[:output] = nil
50
- assert_equal "package", @action.out_path
51
- end
52
- end
53
-
54
- context "include files" do
55
- should "specified array if given" do
56
- @action.options[:include] = [1,2,3]
57
- assert_equal @action.options[:include], @action.include_files
58
- end
59
-
60
- should "be an empty array by default" do
61
- @action.options[:include] = nil
62
- assert_equal [], @action.include_files
63
- end
64
- end
65
-
66
- context "tar path" do
67
- should "be the temporary directory with the name and extension attached" do
68
- pwd = "foo"
69
- FileUtils.stubs(:pwd).returns(pwd)
70
- assert_equal File.join(pwd, "#{@action.out_path}#{@runner.env.config.package.extension}"), @action.tar_path
71
- end
72
- end
73
-
74
- context "temp path" do
75
- setup do
76
- @export = mock("export")
77
- @action.expects(:export_action).returns(@export)
78
- end
79
-
80
- should "use the export action's temp dir" do
81
- path = mock("path")
82
- @export.expects(:temp_dir).returns(path)
83
- @action.temp_path
84
- end
85
- end
86
-
87
- context "copying include files" do
88
- setup do
89
- @include_files = []
90
- @action.stubs(:include_files).returns(@include_files)
91
-
92
- @temp_path = "foo"
93
- @action.stubs(:temp_path).returns(@temp_path)
94
- end
95
-
96
- should "do nothing if no include files are specified" do
97
- assert @action.include_files.empty?
98
- FileUtils.expects(:mkdir_p).never
99
- FileUtils.expects(:cp).never
100
- @action.copy_include_files
101
- end
102
-
103
- should "create the include directory and copy files to it" do
104
- include_dir = File.join(@action.temp_path, "include")
105
- copy_seq = sequence("copy_seq")
106
- FileUtils.expects(:mkdir_p).with(include_dir).once.in_sequence(copy_seq)
107
-
108
- 5.times do |i|
109
- file = mock("f#{i}")
110
- @include_files << file
111
- FileUtils.expects(:cp).with(file, include_dir).in_sequence(copy_seq)
112
- end
113
-
114
- @action.copy_include_files
115
- end
116
- end
117
-
118
- context "creating vagrantfile" do
119
- setup do
120
- @temp_path = "foo"
121
- @action.stubs(:temp_path).returns(@temp_path)
122
-
123
- @network_adapter = mock("nic")
124
- @network_adapter.stubs(:mac_address).returns("mac_address")
125
- @vm.stubs(:network_adapters).returns([@network_adapter])
126
- end
127
-
128
- should "write the rendered vagrantfile to temp_path Vagrantfile" do
129
- f = mock("file")
130
- rendered = mock("rendered")
131
- File.expects(:open).with(File.join(@action.temp_path, "Vagrantfile"), "w").yields(f)
132
- Vagrant::Util::TemplateRenderer.expects(:render).returns(rendered).with("package_Vagrantfile", {
133
- :base_mac => @runner.vm.network_adapters.first.mac_address
134
- })
135
- f.expects(:write).with(rendered)
136
-
137
- @action.create_vagrantfile
138
- end
139
- end
140
-
141
- context "compression" do
142
- setup do
143
- @tar_path = "foo"
144
- @action.stubs(:tar_path).returns(@tar_path)
145
-
146
- @temp_path = "foo"
147
- @action.stubs(:temp_path).returns(@temp_path)
148
-
149
- @include_files = []
150
- @action.stubs(:include_files).returns(@include_files)
151
-
152
- @pwd = "bar"
153
- FileUtils.stubs(:pwd).returns(@pwd)
154
- FileUtils.stubs(:cd)
155
-
156
- @file = mock("file")
157
- File.stubs(:open).yields(@file)
158
-
159
- @output = mock("output")
160
- @tar = Archive::Tar::Minitar
161
- Archive::Tar::Minitar::Output.stubs(:open).yields(@output)
162
- @tar.stubs(:pack_file)
163
-
164
- @action.stubs(:copy_include_files)
165
- @action.stubs(:create_vagrantfile)
166
- end
167
-
168
- should "open the tar file with the tar path properly" do
169
- File.expects(:open).with(@tar_path, Vagrant::Util::Platform.tar_file_options).once
170
- @action.compress
171
- end
172
-
173
- should "open tar file" do
174
- Archive::Tar::Minitar::Output.expects(:open).with(@file).once
175
- @action.compress
176
- end
177
-
178
- #----------------------------------------------------------------
179
- # Methods below this comment test the block yielded by Minitar open
180
- #----------------------------------------------------------------
181
- should "cd to the directory and append the directory" do
182
- @files = []
183
- compress_seq = sequence("compress_seq")
184
-
185
- FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq)
186
- @action.expects(:copy_include_files).once.in_sequence(compress_seq)
187
- @action.expects(:create_vagrantfile).once.in_sequence(compress_seq)
188
- FileUtils.expects(:cd).with(@temp_path).in_sequence(compress_seq)
189
- Dir.expects(:glob).returns(@files).in_sequence(compress_seq)
190
-
191
- 5.times do |i|
192
- file = mock("file#{i}")
193
- @tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq)
194
- @files << file
195
- end
196
-
197
- FileUtils.expects(:cd).with(@pwd).in_sequence(compress_seq)
198
- @action.compress
199
- end
200
-
201
- should "pop back to the current directory even if an exception is raised" do
202
- cd_seq = sequence("cd_seq")
203
- FileUtils.expects(:cd).with(@temp_path).raises(Exception).in_sequence(cd_seq)
204
- FileUtils.expects(:cd).with(@pwd).in_sequence(cd_seq)
205
-
206
- assert_raises(Exception) {
207
- @action.compress
208
- }
209
- end
210
- end
211
-
212
- context "preparing the action" do
213
- context "checking include files" do
214
- setup do
215
- @include_files = ['fooiest', 'booiest']
216
- @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, {
217
- :include => @include_files
218
- })
219
- @runner.stubs(:find_action).returns("foo")
220
- end
221
-
222
- should "check that all the include files exist" do
223
- @include_files.each do |file|
224
- File.expects(:exists?).with(file).returns(true)
225
- end
226
- @action.prepare
227
- end
228
-
229
- should "raise an exception if the output file already exists" do
230
- File.expects(:exist?).with(@action.tar_path).returns(false)
231
- assert_raises(Vagrant::Actions::ActionException) { @action.prepare }
232
- end
233
-
234
- should "raise an exception when an include file does not exist" do
235
- File.expects(:exists?).once.returns(false)
236
- assert_raises(Vagrant::Actions::ActionException) { @action.prepare }
237
- end
238
- end
239
-
240
- context "loading export reference" do
241
- should "find and store a reference to the export action" do
242
- @export = mock("export")
243
- @runner.expects(:find_action).with(Vagrant::Actions::VM::Export).once.returns(@export)
244
- @action.prepare
245
- assert @export.equal?(@action.export_action)
246
- end
247
-
248
- should "raise an exception if the export action couldn't be found" do
249
- @runner.expects(:find_action).with(Vagrant::Actions::VM::Export).once.returns(nil)
250
- assert_raises(Vagrant::Actions::ActionException) { @action.prepare }
251
- end
252
- end
253
- end
254
- end