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,33 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class FileDownloaderTest < Test::Unit::TestCase
4
- setup do
5
- @downloader, @tempfile = mock_downloader(Vagrant::Downloaders::File)
6
- @uri = "foo.box"
7
- end
8
-
9
- context "preparing" do
10
- should "raise an exception if the file does not exist" do
11
- File.expects(:file?).with(@uri).returns(false)
12
- assert_raises(Vagrant::Actions::ActionException) {
13
- @downloader.prepare(@uri)
14
- }
15
- end
16
- end
17
-
18
- context "downloading" do
19
- should "cp the file" do
20
- path = '/path'
21
- @tempfile.expects(:path).returns(path)
22
- FileUtils.expects(:cp).with(@uri, path)
23
- @downloader.download!(@uri, @tempfile)
24
- end
25
- end
26
-
27
- context "matching a uri" do
28
- should "return true if the File exists on the file system" do
29
- File.expects(:exists?).with('foo').returns(true)
30
- assert Vagrant::Downloaders::File.match?('foo')
31
- end
32
- end
33
- end
@@ -1,62 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
-
3
- class HttpDownloaderTest < Test::Unit::TestCase
4
- setup do
5
- @downloader, @tempfile = mock_downloader(Vagrant::Downloaders::HTTP)
6
- @downloader.stubs(:report_progress)
7
- @downloader.stubs(:complete_progress)
8
- @uri = "http://google.com/"
9
- end
10
-
11
- context "downloading" do
12
- setup do
13
- @parsed_uri = URI.parse(@uri)
14
- @http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port)
15
- Net::HTTP.stubs(:new).returns(@http)
16
- @http.stubs(:start)
17
- end
18
-
19
- should "create a proper net/http object" do
20
- Net::HTTP.expects(:new).with(@parsed_uri.host, @parsed_uri.port).once.returns(@http)
21
- @http.expects(:start)
22
- @downloader.download!(@uri, @tempfile)
23
- end
24
-
25
- should "enable SSL if scheme is https" do
26
- @uri = "https://google.com/"
27
- @http.expects(:use_ssl=).with(true).once
28
- @downloader.download!(@uri, @tempfile)
29
- end
30
-
31
- should "read the body of the response and place each segment into the file" do
32
- h = mock("http")
33
- response = mock("response")
34
- response.stubs(:content_length)
35
- segment = mock("segment")
36
- segment.stubs(:length).returns(7)
37
-
38
- @http.stubs(:start).yields(h)
39
- h.expects(:request_get).with(@parsed_uri.request_uri).once.yields(response)
40
- response.expects(:read_body).once.yields(segment)
41
- @tempfile.expects(:write).with(segment).once
42
-
43
- @downloader.download!(@uri, @tempfile)
44
- end
45
- end
46
-
47
- context "matching the uri" do
48
- should "use extract to verify that the string is in fact a uri" do
49
- URI.expects(:extract).returns(['foo'])
50
- assert Vagrant::Downloaders::HTTP.match?('foo')
51
- end
52
-
53
- should "return false if there are no extract results" do
54
- URI.expects(:extract).returns([])
55
- assert !Vagrant::Downloaders::HTTP.match?('foo')
56
- end
57
- end
58
-
59
- context "reporting progress" do
60
- # TODO: Testing for this, probably
61
- end
62
- end
@@ -1,770 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
-
3
- class EnvironmentTest < Test::Unit::TestCase
4
- context "class method check virtualbox version" do
5
- setup do
6
- VirtualBox.stubs(:version).returns("3.1.4")
7
- end
8
-
9
- should "not error and exit if everything is good" do
10
- VirtualBox.expects(:version).returns("3.2.4")
11
- Vagrant::Environment.expects(:error_and_exit).never
12
- Vagrant::Environment.check_virtualbox!
13
- end
14
-
15
- should "error and exit if VirtualBox is not installed or detected" do
16
- Vagrant::Environment.expects(:error_and_exit).with(:virtualbox_not_detected).once
17
- VirtualBox.expects(:version).returns(nil)
18
- Vagrant::Environment.check_virtualbox!
19
- end
20
-
21
- should "error and exit if VirtualBox is lower than version 3.2" do
22
- version = "3.1.12r1041"
23
- Vagrant::Environment.expects(:error_and_exit).with(:virtualbox_invalid_version, :version => version.to_s).once
24
- VirtualBox.expects(:version).returns(version)
25
- Vagrant::Environment.check_virtualbox!
26
- end
27
-
28
- should "error and exit for OSE VirtualBox" do
29
- version = "3.2.6_OSE"
30
- Vagrant::Environment.expects(:error_and_exit).with(:virtualbox_invalid_ose, :version => version.to_s).once
31
- VirtualBox.expects(:version).returns(version)
32
- Vagrant::Environment.check_virtualbox!
33
- end
34
- end
35
-
36
- context "class method load!" do
37
- setup do
38
- @cwd = mock('cwd')
39
-
40
- @env = mock('env')
41
- @env.stubs(:load!).returns(@env)
42
- end
43
-
44
- should "create the environment with given cwd, load it, and return it" do
45
- Vagrant::Environment.expects(:new).with(:cwd => @cwd).once.returns(@env)
46
- @env.expects(:load!).returns(@env)
47
- assert_equal @env, Vagrant::Environment.load!(@cwd)
48
- end
49
-
50
- should "work without a given cwd" do
51
- Vagrant::Environment.expects(:new).with(:cwd => nil).returns(@env)
52
-
53
- assert_nothing_raised {
54
- env = Vagrant::Environment.load!
55
- assert_equal env, @env
56
- }
57
- end
58
- end
59
-
60
- context "initialization" do
61
- should "set the cwd if given" do
62
- cwd = "foobarbaz"
63
- env = Vagrant::Environment.new(:cwd => cwd)
64
- assert_equal cwd, env.cwd
65
- end
66
-
67
- should "default to pwd if cwd is nil" do
68
- env = Vagrant::Environment.new
69
- assert_equal Dir.pwd, env.cwd
70
- end
71
- end
72
-
73
- context "paths" do
74
- setup do
75
- @env = mock_environment
76
- end
77
-
78
- context "cwd" do
79
- should "default to Dir.pwd" do
80
- assert_equal Dir.pwd, @env.cwd
81
- end
82
-
83
- should "return cwd if set" do
84
- @env.cwd = "foo"
85
- assert_equal "foo", @env.cwd
86
- end
87
- end
88
-
89
- context "dotfile path" do
90
- setup do
91
- @env.stubs(:root_path).returns("foo")
92
- end
93
-
94
- should "build up the dotfile out of the root path and the dotfile name" do
95
- assert_equal File.join(@env.root_path, @env.config.vagrant.dotfile_name), @env.dotfile_path
96
- end
97
- end
98
-
99
- context "home path" do
100
- should "return nil if config is not yet loaded" do
101
- @env.stubs(:config).returns(nil)
102
- assert_nil @env.home_path
103
- end
104
-
105
- should "return the home path if it loaded" do
106
- assert_equal @env.config.vagrant.home, @env.home_path
107
- end
108
- end
109
-
110
- context "temp path" do
111
- should "return the home path joined with 'tmp'" do
112
- home_path = "foo"
113
- @env.stubs(:home_path).returns(home_path)
114
- assert_equal File.join("foo", "tmp"), @env.tmp_path
115
- end
116
- end
117
-
118
- context "boxes path" do
119
- should "return the home path joined with 'tmp'" do
120
- home_path = "foo"
121
- @env.stubs(:home_path).returns(home_path)
122
- assert_equal File.join("foo", "boxes"), @env.boxes_path
123
- end
124
- end
125
- end
126
-
127
- context "primary VM helper" do
128
- setup do
129
- @env = mock_environment
130
- @env.stubs(:multivm?).returns(true)
131
- end
132
-
133
- should "return the first VM if not multivm" do
134
- result = mock("result")
135
-
136
- @env.stubs(:multivm?).returns(false)
137
- @env.stubs(:vms).returns({:default => result})
138
-
139
- assert_equal result, @env.primary_vm
140
- end
141
-
142
- should "call and return the primary VM from the parent if has one" do
143
- result = mock("result")
144
- parent = mock("parent")
145
- parent.expects(:primary_vm).returns(result)
146
-
147
- @env.stubs(:parent).returns(parent)
148
- assert_equal result, @env.primary_vm
149
- end
150
-
151
- should "return nil if no VM is marked as primary" do
152
- @env.config.vm.define(:foo)
153
- @env.config.vm.define(:bar)
154
- @env.config.vm.define(:baz)
155
-
156
- assert @env.primary_vm.nil?
157
- end
158
-
159
- should "return the primary VM" do
160
- @env.config.vm.define(:foo)
161
- @env.config.vm.define(:bar, :primary => true)
162
- @env.config.vm.define(:baz)
163
-
164
- result = mock("result")
165
- vms = {
166
- :foo => :foo,
167
- :bar => result,
168
- :baz => :baz
169
- }
170
- @env.stubs(:vms).returns(vms)
171
-
172
- assert_equal result, @env.primary_vm
173
- end
174
- end
175
-
176
- context "multivm? helper" do
177
- setup do
178
- @env = mock_environment
179
- end
180
-
181
- context "with a parent" do
182
- setup do
183
- @parent = mock('parent')
184
- @env.stubs(:parent).returns(@parent)
185
- end
186
-
187
- should "return the value of multivm? from the parent" do
188
- result = mock("result")
189
- @parent.stubs(:multivm?).returns(result)
190
- assert_equal result, @env.multivm?
191
- end
192
- end
193
-
194
- context "without a parent" do
195
- setup do
196
- @env.stubs(:parent).returns(nil)
197
- end
198
-
199
- should "return true if VM length greater than 1" do
200
- @env.stubs(:vms).returns([1,2,3])
201
- assert @env.multivm?
202
- end
203
-
204
- should "return false if VM length is 1" do
205
- @env.stubs(:vms).returns([1])
206
- assert !@env.multivm?
207
- end
208
- end
209
- end
210
-
211
- context "loading" do
212
- setup do
213
- @env = mock_environment
214
- end
215
-
216
- context "overall load method" do
217
- should "load! should call proper sequence and return itself" do
218
- call_seq = sequence("call_sequence")
219
- @env.expects(:load_logger!).once.in_sequence(call_seq)
220
- @env.expects(:load_root_path!).once.in_sequence(call_seq)
221
- @env.expects(:load_config!).once.in_sequence(call_seq)
222
- @env.expects(:load_home_directory!).once.in_sequence(call_seq)
223
- @env.expects(:load_box!).once.in_sequence(call_seq)
224
- @env.expects(:load_config!).once.in_sequence(call_seq)
225
- Vagrant::Environment.expects(:check_virtualbox!).once.in_sequence(call_seq)
226
- @env.expects(:load_vm!).once.in_sequence(call_seq)
227
- @env.expects(:load_active_list!).once.in_sequence(call_seq)
228
- @env.expects(:load_commands!).once.in_sequence(call_seq)
229
- assert_equal @env, @env.load!
230
- end
231
- end
232
-
233
- context "loading the root path" do
234
- setup do
235
- @env.cwd = "/foo"
236
- end
237
-
238
- should "default the path to the cwd instance var if nil" do
239
- @path = mock("path")
240
- @path.stubs(:root?).returns(true)
241
- File.expects(:expand_path).with(@env.cwd).returns(@env.cwd)
242
- Pathname.expects(:new).with(@env.cwd).returns(@path)
243
- @env.load_root_path!(nil)
244
- end
245
-
246
- should "not default the path to pwd if its not nil" do
247
- @path = mock("path")
248
- @path.stubs(:to_s).returns("/")
249
- File.expects(:expand_path).with(@path).returns("/")
250
- Pathname.expects(:new).with("/").returns(@path)
251
- @path.stubs(:root?).returns(true)
252
- @env.load_root_path!(@path)
253
- end
254
-
255
- should "should walk the parent directories looking for rootfile" do
256
- paths = [
257
- Pathname.new("/foo/bar/baz"),
258
- Pathname.new("/foo/bar"),
259
- Pathname.new("/foo")
260
- ]
261
-
262
- search_seq = sequence("search_seq")
263
- paths.each do |path|
264
- # NOTE File.expect(:expand_path) causes tests to hang in windows below is the interim solution
265
- File.expects(:exist?).with("#{File.expand_path(path)}/#{Vagrant::Environment::ROOTFILE_NAME}").returns(false).in_sequence(search_seq)
266
- end
267
-
268
- assert !@env.load_root_path!(paths.first)
269
- end
270
-
271
- should "return false if not found" do
272
- path = Pathname.new("/")
273
- assert !@env.load_root_path!(path)
274
- end
275
-
276
- should "return false if not found on windows-style root" do
277
- # TODO: Is there _any_ way to test this on unix machines? The
278
- # expand path doesn't work [properly for the test] on unix machines.
279
- if RUBY_PLATFORM.downcase.include?("mswin")
280
- # Note the escaped back slash
281
- path = Pathname.new("C:\\")
282
- assert !@env.load_root_path!(path)
283
- end
284
- end
285
-
286
- should "should set the path for the rootfile" do
287
- # NOTE File.expect(:expand_path) causes tests to hang in windows below is the interim solution
288
- path = File.expand_path("/foo")
289
- File.expects(:exist?).with("#{path}/#{Vagrant::Environment::ROOTFILE_NAME}").returns(true)
290
-
291
- assert @env.load_root_path!(Pathname.new(path))
292
- assert_equal path, @env.root_path
293
- end
294
- end
295
-
296
- context "loading config" do
297
- setup do
298
- @root_path = "/foo"
299
- @home_path = "/bar"
300
- @env.stubs(:root_path).returns(@root_path)
301
- @env.stubs(:home_path).returns(@home_path)
302
- @env.stubs(:load_logger!)
303
-
304
- @parent_env = mock_environment
305
-
306
- File.stubs(:exist?).returns(false)
307
- end
308
-
309
- should "reset the configuration object" do
310
- Vagrant::Config.expects(:reset!).with(@env).once
311
- @env.load_config!
312
- end
313
-
314
- should "load from the project root" do
315
- File.expects(:exist?).with(File.join(PROJECT_ROOT, "config", "default.rb")).once
316
- @env.load_config!
317
- end
318
-
319
- should "load from the root path" do
320
- File.expects(:exist?).with(File.join(@root_path, Vagrant::Environment::ROOTFILE_NAME)).once
321
- @env.load_config!
322
- end
323
-
324
- should "not load from the root path if nil" do
325
- @env.stubs(:root_path).returns(nil)
326
- File.expects(:exist?).with(File.join(@root_path, Vagrant::Environment::ROOTFILE_NAME)).never
327
- @env.load_config!
328
- end
329
-
330
- should "load from the home directory" do
331
- File.expects(:exist?).with(File.join(@env.home_path, Vagrant::Environment::ROOTFILE_NAME)).once
332
- @env.load_config!
333
- end
334
-
335
- should "not load from the home directory if the config is nil" do
336
- @env.stubs(:home_path).returns(nil)
337
- File.expects(:exist?).twice.returns(false)
338
- @env.load_config!
339
- end
340
-
341
- should "not load from the box directory if it is nil" do
342
- @env.expects(:box).once.returns(nil)
343
- File.expects(:exist?).twice.returns(false)
344
- @env.load_config!
345
- end
346
-
347
- should "load from the box directory if it is not nil" do
348
- dir = "foo"
349
- box = mock("box")
350
- box.stubs(:directory).returns(dir)
351
- @env.expects(:box).twice.returns(box)
352
- File.expects(:exist?).with(File.join(dir, Vagrant::Environment::ROOTFILE_NAME)).once
353
- @env.load_config!
354
- end
355
-
356
- should "load a sub-VM configuration if specified" do
357
- vm_name = :foo
358
- sub_box = :YO
359
- @parent_env.config.vm.box = :NO
360
- @parent_env.config.vm.define(vm_name) do |config|
361
- config.vm.box = sub_box
362
- end
363
-
364
- # Sanity
365
- assert_equal :NO, @parent_env.config.vm.box
366
-
367
- @env.stubs(:vm_name).returns(vm_name)
368
- @env.stubs(:parent).returns(@parent_env)
369
-
370
- @env.load_config!
371
-
372
- assert_equal sub_box, @env.config.vm.box
373
- end
374
-
375
- should "load the files only if exist? returns true" do
376
- File.expects(:exist?).once.returns(true)
377
- @env.expects(:load).once
378
- @env.load_config!
379
- end
380
-
381
- should "not load the files if exist? returns false" do
382
- @env.expects(:load).never
383
- @env.load_config!
384
- end
385
-
386
- should "execute after loading and set result to environment config" do
387
- result = mock("result")
388
- File.expects(:exist?).once.returns(true)
389
- @env.expects(:load).once
390
- Vagrant::Config.expects(:execute!).once.returns(result)
391
- @env.load_config!
392
- assert_equal result, @env.config
393
- end
394
-
395
- should "reload the logger after executing" do
396
- load_seq = sequence("load_seq")
397
- Vagrant::Config.expects(:execute!).once.returns(nil).in_sequence(load_seq)
398
- @env.expects(:load_logger!).once.in_sequence(load_seq)
399
- @env.load_config!
400
- end
401
- end
402
-
403
- context "loading logger" do
404
- setup do
405
- @env = mock_environment
406
- @env.stubs(:vm_name).returns(nil)
407
- end
408
-
409
- should "use 'vagrant' by default" do
410
- assert @env.vm_name.nil? # sanity
411
- @env.load_logger!
412
- assert_equal "vagrant", @env.logger.resource
413
- end
414
-
415
- should "use the vm name if available" do
416
- name = "foo"
417
- @env.stubs(:vm_name).returns(name)
418
- @env.load_logger!
419
- assert_equal name, @env.logger.resource
420
- end
421
- end
422
-
423
- context "loading home directory" do
424
- setup do
425
- @env = mock_environment
426
- @home_dir = File.expand_path(@env.config.vagrant.home)
427
-
428
- File.stubs(:directory?).returns(true)
429
- FileUtils.stubs(:mkdir_p)
430
- end
431
-
432
- should "create each directory if it doesn't exist" do
433
- create_seq = sequence("create_seq")
434
- File.stubs(:directory?).returns(false)
435
- Vagrant::Environment::HOME_SUBDIRS.each do |subdir|
436
- FileUtils.expects(:mkdir_p).with(File.join(@home_dir, subdir)).in_sequence(create_seq)
437
- end
438
-
439
- @env.load_home_directory!
440
- end
441
-
442
- should "not create directories if they exist" do
443
- File.stubs(:directory?).returns(true)
444
- FileUtils.expects(:mkdir_p).never
445
- @env.load_home_directory!
446
- end
447
- end
448
-
449
- context "loading box" do
450
- setup do
451
- @box = mock("box")
452
- @box.stubs(:env=)
453
-
454
- @env = mock_environment
455
- @env.stubs(:root_path).returns("foo")
456
- end
457
-
458
- should "do nothing if the root path is nil" do
459
- Vagrant::Box.expects(:find).never
460
- @env.stubs(:root_path).returns(nil)
461
- @env.load_box!
462
- end
463
-
464
- should "not load the box if its not set" do
465
- @env = mock_environment do |config|
466
- config.vm.box = nil
467
- end
468
-
469
- Vagrant::Box.expects(:find).never
470
- @env.load_box!
471
- end
472
-
473
- should "set the box to what is found by the Box class" do
474
- Vagrant::Box.expects(:find).with(@env, @env.config.vm.box).once.returns(@box)
475
- @env.load_box!
476
- assert @box.equal?(@env.box)
477
- end
478
- end
479
-
480
- context "loading the UUID out from the persisted dotfile" do
481
- setup do
482
- @env = mock_environment
483
- @env.stubs(:root_path).returns("foo")
484
-
485
- File.stubs(:file?).returns(true)
486
- end
487
-
488
- should "blank the VMs" do
489
- load_seq = sequence("load_seq")
490
- @env.stubs(:root_path).returns("foo")
491
- @env.expects(:load_blank_vms!).in_sequence(load_seq)
492
- File.expects(:open).in_sequence(load_seq)
493
- @env.load_vm!
494
- end
495
-
496
- should "load the UUID if the JSON parsing fails" do
497
- vm = mock("vm")
498
-
499
- filemock = mock("filemock")
500
- filemock.expects(:read).returns("foo")
501
- Vagrant::VM.expects(:find).with("foo", @env, Vagrant::Environment::DEFAULT_VM).returns(vm)
502
- File.expects(:open).with(@env.dotfile_path).once.yields(filemock)
503
- File.expects(:file?).with(@env.dotfile_path).once.returns(true)
504
- @env.load_vm!
505
-
506
- assert_equal vm, @env.vms.values.first
507
- end
508
-
509
- should "load all the VMs from the dotfile" do
510
- vms = { :foo => "bar", :bar => "baz" }
511
- results = {}
512
-
513
- filemock = mock("filemock")
514
- filemock.expects(:read).returns(vms.to_json)
515
- File.expects(:open).with(@env.dotfile_path).once.yields(filemock)
516
- File.expects(:file?).with(@env.dotfile_path).once.returns(true)
517
-
518
- vms.each do |key, value|
519
- vm = mock("vm#{key}")
520
- Vagrant::VM.expects(:find).with(value, @env, key.to_sym).returns(vm)
521
- results[key] = vm
522
- end
523
-
524
- @env.load_vm!
525
-
526
- results.each do |key, value|
527
- assert_equal value, @env.vms[key]
528
- end
529
- end
530
-
531
- should "do nothing if the vm_name is set" do
532
- @env.stubs(:vm_name).returns(:foo)
533
- File.expects(:open).never
534
- @env.load_vm!
535
- end
536
-
537
- should "do nothing if the dotfile is nil" do
538
- @env.stubs(:dotfile_path).returns(nil)
539
- File.expects(:open).never
540
-
541
- assert_nothing_raised {
542
- @env.load_vm!
543
- }
544
- end
545
-
546
- should "do nothing if dotfile is not a file" do
547
- File.expects(:file?).returns(false)
548
- File.expects(:open).never
549
- @env.load_vm!
550
- end
551
-
552
- should "uuid should be nil if dotfile didn't exist" do
553
- File.expects(:open).raises(Errno::ENOENT)
554
- @env.load_vm!
555
- assert_nil @env.vm
556
- end
557
- end
558
-
559
- context "loading blank VMs" do
560
- setup do
561
- @env = mock_environment
562
- end
563
-
564
- should "blank the VMs" do
565
- @env = mock_environment do |config|
566
- config.vm.define :foo do |config|
567
- end
568
-
569
- config.vm.define :bar do |config|
570
- end
571
- end
572
-
573
- @env.load_blank_vms!
574
-
575
- assert_equal 2, @env.vms.length
576
- assert(@env.vms.all? { |name, vm| !vm.created? })
577
-
578
- sorted_vms = @env.vms.keys.sort { |a,b| a.to_s <=> b.to_s }
579
- assert_equal [:bar, :foo], sorted_vms
580
- end
581
-
582
- should "load the default VM blank if no multi-VMs are specified" do
583
- assert @env.config.vm.defined_vms.empty? # sanity
584
-
585
- @env.load_blank_vms!
586
-
587
- assert_equal 1, @env.vms.length
588
- assert !@env.vms.values.first.created?
589
- end
590
- end
591
-
592
- context "loading the active list" do
593
- setup do
594
- @env = mock_environment
595
- end
596
-
597
- should "initialize the ActiveList object with the given environment" do
598
- active_list = mock("active_list")
599
- Vagrant::ActiveList.expects(:new).with(@env).returns(active_list)
600
- @env.load_active_list!
601
- assert_equal active_list, @env.active_list
602
- end
603
- end
604
-
605
- context "loading the commands" do
606
- setup do
607
- @env = mock_environment
608
- end
609
-
610
- should "initialize the Commands object with the given environment" do
611
- commands = mock("commands")
612
- Vagrant::Command.expects(:new).with(@env).returns(commands)
613
- @env.load_commands!
614
- assert_equal commands, @env.commands
615
- end
616
- end
617
- end
618
-
619
- context "requiring properties" do
620
- setup do
621
- @env = mock_environment
622
- end
623
-
624
- context "requiring boxes" do
625
- setup do
626
- reconfig_environment
627
- end
628
-
629
- def reconfig_environment
630
- @env = mock_environment do |config|
631
- yield config if block_given?
632
- end
633
-
634
- @env.stubs(:require_root_path)
635
- @env.stubs(:error_and_exit)
636
- end
637
-
638
- should "require root path" do
639
- @env.expects(:require_root_path).once
640
- @env.require_box
641
- end
642
-
643
- should "error and exit if no box is specified" do
644
- reconfig_environment do |config|
645
- config.vm.box = nil
646
- end
647
-
648
- @env.expects(:box).returns(nil)
649
- @env.expects(:error_and_exit).once.with(:box_not_specified)
650
- @env.require_box
651
- end
652
-
653
- should "error and exit if box is specified but doesn't exist" do
654
- reconfig_environment do |config|
655
- config.vm.box = "foo"
656
- end
657
-
658
- @env.expects(:box).returns(nil)
659
- @env.expects(:error_and_exit).once.with(:box_specified_doesnt_exist, :box_name => "foo")
660
- @env.require_box
661
- end
662
- end
663
-
664
- context "requiring root_path" do
665
- should "error and exit if no root_path is set" do
666
- @env.expects(:root_path).returns(nil)
667
- @env.expects(:error_and_exit).with(:rootfile_not_found).once
668
- @env.require_root_path
669
- end
670
-
671
- should "not error and exit if root_path is set" do
672
- @env.expects(:root_path).returns("foo")
673
- @env.expects(:error_and_exit).never
674
- @env.require_root_path
675
- end
676
- end
677
-
678
- context "requiring a persisted VM" do
679
- setup do
680
- @env.stubs(:vm).returns("foo")
681
- @env.stubs(:require_root_path)
682
- end
683
-
684
- should "require a root path" do
685
- @env.expects(:require_root_path).once
686
- @env.expects(:error_and_exit).never
687
- @env.require_persisted_vm
688
- end
689
-
690
- should "error and exit if the VM is not set" do
691
- @env.expects(:vm).returns(nil)
692
- @env.expects(:error_and_exit).once
693
- @env.require_persisted_vm
694
- end
695
- end
696
- end
697
-
698
- context "managing VM" do
699
- setup do
700
- @env = mock_environment
701
-
702
- @dotfile_path = "foo"
703
- @env.stubs(:dotfile_path).returns(@dotfile_path)
704
- end
705
-
706
- def mock_vm
707
- @vm = mock("vm")
708
- @vm.stubs(:uuid).returns("foo")
709
- @env.stubs(:vm).returns(@vm)
710
- end
711
- end
712
-
713
- context "updating the dotfile" do
714
- setup do
715
- @env = mock_environment
716
- @env.stubs(:parent).returns(nil)
717
- @env.stubs(:dotfile_path).returns("foo")
718
- File.stubs(:open)
719
- end
720
-
721
- def create_vm(created)
722
- vm = mock("vm")
723
- vm.stubs(:created?).returns(created)
724
- vm.stubs(:uuid).returns("foo")
725
- vm
726
- end
727
-
728
- should "call parent if exists" do
729
- parent = mock("parent")
730
- @env.stubs(:parent).returns(parent)
731
- parent.expects(:update_dotfile).once
732
-
733
- @env.update_dotfile
734
- end
735
-
736
- should "remove the dotfile if the data is empty" do
737
- vms = {
738
- :foo => create_vm(false)
739
- }
740
-
741
- @env.stubs(:vms).returns(vms)
742
- File.expects(:delete).with(@env.dotfile_path).once
743
- @env.update_dotfile
744
- end
745
-
746
- should "write the proper data to dotfile" do
747
- vms = {
748
- :foo => create_vm(false),
749
- :bar => create_vm(true),
750
- :baz => create_vm(true)
751
- }
752
-
753
- f = mock("f")
754
- @env.stubs(:vms).returns(vms)
755
- File.expects(:open).with(@env.dotfile_path, 'w+').yields(f)
756
- f.expects(:write).with() do |json|
757
- assert_nothing_raised {
758
- data = JSON.parse(json)
759
- assert_equal 2, data.length
760
- assert_equal vms[:bar].uuid, data["bar"]
761
- assert_equal vms[:baz].uuid, data["baz"]
762
- }
763
-
764
- true
765
- end
766
-
767
- @env.update_dotfile
768
- end
769
- end
770
- end