vagrantup 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/bin/vagrant +1 -1
  6. data/bin/vagrant-box +1 -2
  7. data/bin/vagrant-down +1 -2
  8. data/bin/vagrant-halt +1 -2
  9. data/bin/vagrant-init +1 -2
  10. data/bin/vagrant-package +1 -2
  11. data/bin/vagrant-reload +1 -2
  12. data/bin/vagrant-resume +1 -2
  13. data/bin/vagrant-ssh +1 -2
  14. data/bin/vagrant-status +29 -0
  15. data/bin/vagrant-suspend +1 -2
  16. data/bin/vagrant-up +1 -2
  17. data/config/default.rb +5 -9
  18. data/keys/README.md +10 -0
  19. data/keys/vagrant +27 -0
  20. data/keys/vagrant.pub +1 -0
  21. data/lib/vagrant.rb +10 -5
  22. data/lib/vagrant/actions/base.rb +14 -0
  23. data/lib/vagrant/actions/box/download.rb +3 -0
  24. data/lib/vagrant/actions/collection.rb +36 -0
  25. data/lib/vagrant/actions/runner.rb +4 -10
  26. data/lib/vagrant/actions/vm/boot.rb +4 -5
  27. data/lib/vagrant/actions/vm/customize.rb +17 -0
  28. data/lib/vagrant/actions/vm/destroy.rb +11 -2
  29. data/lib/vagrant/actions/vm/forward_ports.rb +24 -0
  30. data/lib/vagrant/actions/vm/import.rb +1 -0
  31. data/lib/vagrant/actions/vm/provision.rb +30 -52
  32. data/lib/vagrant/actions/vm/reload.rb +2 -2
  33. data/lib/vagrant/actions/vm/shared_folders.rb +37 -25
  34. data/lib/vagrant/actions/vm/up.rb +8 -4
  35. data/lib/vagrant/active_list.rb +66 -0
  36. data/lib/vagrant/commands.rb +44 -0
  37. data/lib/vagrant/config.rb +64 -47
  38. data/lib/vagrant/downloaders/base.rb +3 -0
  39. data/lib/vagrant/downloaders/file.rb +11 -11
  40. data/lib/vagrant/env.rb +48 -12
  41. data/lib/vagrant/provisioners/base.rb +22 -0
  42. data/lib/vagrant/provisioners/chef.rb +102 -0
  43. data/lib/vagrant/provisioners/chef_server.rb +96 -0
  44. data/lib/vagrant/provisioners/chef_solo.rb +67 -0
  45. data/lib/vagrant/ssh.rb +25 -6
  46. data/lib/vagrant/stacked_proc_runner.rb +33 -0
  47. data/lib/vagrant/vm.rb +8 -0
  48. data/test/test_helper.rb +22 -6
  49. data/test/vagrant/actions/box/download_test.rb +11 -0
  50. data/test/vagrant/actions/collection_test.rb +110 -0
  51. data/test/vagrant/actions/runner_test.rb +11 -7
  52. data/test/vagrant/actions/vm/boot_test.rb +7 -7
  53. data/test/vagrant/actions/vm/customize_test.rb +16 -0
  54. data/test/vagrant/actions/vm/destroy_test.rb +19 -6
  55. data/test/vagrant/actions/vm/forward_ports_test.rb +52 -0
  56. data/test/vagrant/actions/vm/import_test.rb +10 -3
  57. data/test/vagrant/actions/vm/provision_test.rb +75 -70
  58. data/test/vagrant/actions/vm/reload_test.rb +3 -2
  59. data/test/vagrant/actions/vm/shared_folders_test.rb +62 -9
  60. data/test/vagrant/actions/vm/up_test.rb +4 -4
  61. data/test/vagrant/active_list_test.rb +169 -0
  62. data/test/vagrant/config_test.rb +145 -29
  63. data/test/vagrant/downloaders/base_test.rb +7 -0
  64. data/test/vagrant/downloaders/file_test.rb +12 -18
  65. data/test/vagrant/env_test.rb +96 -23
  66. data/test/vagrant/provisioners/base_test.rb +27 -0
  67. data/test/vagrant/provisioners/chef_server_test.rb +175 -0
  68. data/test/vagrant/provisioners/chef_solo_test.rb +142 -0
  69. data/test/vagrant/provisioners/chef_test.rb +116 -0
  70. data/test/vagrant/ssh_test.rb +29 -8
  71. data/test/vagrant/stacked_proc_runner_test.rb +43 -0
  72. data/test/vagrant/vm_test.rb +23 -0
  73. data/vagrant.gemspec +34 -7
  74. metadata +33 -5
  75. data/script/vagrant-ssh-expect.sh +0 -22
@@ -1,6 +1,23 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class ConfigTest < Test::Unit::TestCase
4
+ context "the ssh config" do
5
+ should "expand any path when requesting the value" do
6
+ Vagrant::Env.stubs(:root_path).returns('foo')
7
+ File.stubs(:expand_path).with(Vagrant.config.ssh[:private_key_path], 'foo').returns('success')
8
+ assert Vagrant.config.ssh.private_key_path, 'success'
9
+ end
10
+ end
11
+
12
+ context "adding configures" do
13
+ should "forward the method to the Top class" do
14
+ key = mock("key")
15
+ klass = mock("klass")
16
+ Vagrant::Config::Top.expects(:configures).with(key, klass)
17
+ Vagrant::Config.configures(key, klass)
18
+ end
19
+ end
20
+
4
21
  context "resetting" do
5
22
  setup do
6
23
  Vagrant::Config.run { |config| }
@@ -18,10 +35,10 @@ class ConfigTest < Test::Unit::TestCase
18
35
  assert !config.equal?(Vagrant::Config.config)
19
36
  end
20
37
 
21
- should "empty the runners" do
22
- assert !Vagrant::Config.config_runners.empty?
38
+ should "empty the proc stack" do
39
+ assert !Vagrant::Config.proc_stack.empty?
23
40
  Vagrant::Config.reset!
24
- assert Vagrant::Config.config_runners.empty?
41
+ assert Vagrant::Config.proc_stack.empty?
25
42
  end
26
43
  end
27
44
 
@@ -37,30 +54,18 @@ class ConfigTest < Test::Unit::TestCase
37
54
  end
38
55
 
39
56
  context "initializing" do
40
- teardown do
41
- Vagrant::Config.instance_variable_set(:@config_runners, nil)
42
- Vagrant::Config.instance_variable_set(:@config, nil)
43
- end
44
-
45
- should "not run the blocks right away" do
46
- obj = mock("obj")
47
- obj.expects(:foo).never
48
- Vagrant::Config.run { |config| obj.foo }
49
- Vagrant::Config.run { |config| obj.foo }
50
- Vagrant::Config.run { |config| obj.foo }
57
+ setup do
58
+ Vagrant::Config.reset!
51
59
  end
52
60
 
53
- should "run the blocks when execute! is ran" do
54
- obj = mock("obj")
55
- obj.expects(:foo).times(2)
56
- Vagrant::Config.run { |config| obj.foo }
57
- Vagrant::Config.run { |config| obj.foo }
58
- Vagrant::Config.execute!
61
+ should "add the given block to the proc stack" do
62
+ proc = Proc.new {}
63
+ Vagrant::Config.run(&proc)
64
+ assert_equal [proc], Vagrant::Config.proc_stack
59
65
  end
60
66
 
61
- should "run the blocks with the same config object" do
62
- Vagrant::Config.run { |config| assert config }
63
- Vagrant::Config.run { |config| assert config }
67
+ should "run the proc stack with the config when execute is called" do
68
+ Vagrant::Config.expects(:run_procs!).with(Vagrant::Config.config).once
64
69
  Vagrant::Config.execute!
65
70
  end
66
71
 
@@ -109,15 +114,126 @@ class ConfigTest < Test::Unit::TestCase
109
114
  end
110
115
  end
111
116
 
112
- context "chef config" do
117
+ context "top config class" do
113
118
  setup do
114
- @config = Vagrant::Config::ChefConfig.new
115
- @config.json = "HEY"
119
+ @configures_list = []
120
+ Vagrant::Config::Top.stubs(:configures_list).returns(@configures_list)
116
121
  end
117
122
 
118
- should "not include the 'json' key in the config dump" do
119
- result = JSON.parse(@config.to_json)
120
- assert !result.has_key?("json")
123
+ context "adding configure keys" do
124
+ setup do
125
+ @key = "top_config_foo"
126
+ @klass = mock("klass")
127
+ end
128
+
129
+ should "add key and klass to configures list" do
130
+ @configures_list.expects(:<<).with([@key, @klass])
131
+ Vagrant::Config::Top.configures(@key, @klass)
132
+ end
133
+ end
134
+
135
+ context "configuration keys on instance" do
136
+ setup do
137
+ @configures_list.clear
138
+ end
139
+
140
+ should "initialize each configurer and set it to its key" do
141
+ 5.times do |i|
142
+ key = "key#{i}"
143
+ klass = mock("klass#{i}")
144
+ instance = mock("instance#{i}")
145
+ klass.expects(:new).returns(instance)
146
+ @configures_list << [key, klass]
147
+ end
148
+
149
+ Vagrant::Config::Top.new
150
+ end
151
+
152
+ should "allow reading via methods" do
153
+ key = "my_foo_bar_key"
154
+ klass = mock("klass")
155
+ instance = mock("instance")
156
+ klass.expects(:new).returns(instance)
157
+ Vagrant::Config::Top.configures(key, klass)
158
+
159
+ config = Vagrant::Config::Top.new
160
+ assert_equal instance, config.send(key)
161
+ end
162
+ end
163
+
164
+ context "loaded status" do
165
+ setup do
166
+ @top= Vagrant::Config::Top.new
167
+ end
168
+
169
+ should "not be loaded by default" do
170
+ assert !@top.loaded?
171
+ end
172
+
173
+ should "be loaded after calling loaded!" do
174
+ @top.loaded!
175
+ assert @top.loaded?
176
+ end
177
+ end
178
+ end
179
+
180
+ context "vagrant configuration" do
181
+ setup do
182
+ @config = Vagrant::Config::VagrantConfig.new
183
+ end
184
+
185
+ should "return nil if home is nil" do
186
+ File.expects(:expand_path).never
187
+ assert @config.home.nil?
188
+ end
189
+
190
+ should "expand the path if home is not nil" do
191
+ @config.home = "foo"
192
+ File.expects(:expand_path).with("foo").once.returns("result")
193
+ assert_equal "result", @config.home
194
+ end
195
+ end
196
+
197
+ context "VM configuration" do
198
+ setup do
199
+ @config = Vagrant::Config::VMConfig.new
200
+ @username = "bob"
201
+
202
+ mock_config do |config|
203
+ config.ssh.username = @username
204
+ end
205
+ end
206
+
207
+ should "include the stacked proc runner module" do
208
+ assert @config.class.included_modules.include?(Vagrant::StackedProcRunner)
209
+ end
210
+
211
+ should "add the customize proc to the proc stack" do
212
+ proc = Proc.new {}
213
+ @config.customize(&proc)
214
+ assert_equal [proc], @config.proc_stack
215
+ end
216
+
217
+ context "uid/gid" do
218
+ should "return the shared folder UID if set" do
219
+ @config.shared_folder_uid = "foo"
220
+ assert_equal "foo", @config.shared_folder_uid
221
+ end
222
+
223
+ should "return the SSH username if UID not set" do
224
+ @config.shared_folder_uid = nil
225
+ assert_equal @username, @config.shared_folder_uid
226
+ end
227
+
228
+ should "return the shared folder GID if set" do
229
+ @config.shared_folder_gid = "foo"
230
+ assert_equal "foo", @config.shared_folder_gid
231
+ end
232
+
233
+ should "return the SSH username if GID not set" do
234
+ @config.shared_folder_gid = nil
235
+ assert_equal @username, @config.shared_folder_gid
236
+ end
121
237
  end
122
238
  end
123
239
  end
@@ -11,6 +11,13 @@ class BaseDownloaderTest < Test::Unit::TestCase
11
11
  end
12
12
 
13
13
  should "implement prepare which does nothing" do
14
+ assert_nothing_raised do
15
+ assert @base.respond_to?(:prepare)
16
+ @base.prepare("source")
17
+ end
18
+ end
19
+
20
+ should "implement download! which does nothing" do
14
21
  assert_nothing_raised do
15
22
  assert @base.respond_to?(:download!)
16
23
  @base.download!("source", "destination")
@@ -6,26 +6,20 @@ class FileDownloaderTest < Test::Unit::TestCase
6
6
  @uri = "foo.box"
7
7
  end
8
8
 
9
- context "downloading" do
10
- setup do
11
- @file = mock("file")
12
- @file.stubs(:read)
13
- @file.stubs(:eof?).returns(false)
14
- @downloader.stubs(:open).yields(@file)
15
- end
16
-
17
- should "open with the given uri" do
18
- @downloader.expects(:open).with(@uri).once
19
- @downloader.download!(@uri, @tempfile)
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
+ }
20
15
  end
16
+ end
21
17
 
22
- should "buffer the read from the file and write to the tempfile" do
23
- data = mock("data")
24
- write_seq = sequence("write_seq")
25
- @file.stubs(:eof?).returns(false).in_sequence(write_seq)
26
- @file.expects(:read).returns(data).in_sequence(write_seq)
27
- @tempfile.expects(:write).with(data).in_sequence(write_seq)
28
- @file.stubs(:eof?).returns(true).in_sequence(write_seq)
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)
29
23
  @downloader.download!(@uri, @tempfile)
30
24
  end
31
25
  end
@@ -15,6 +15,24 @@ class EnvTest < Test::Unit::TestCase
15
15
  Vagrant::Box.stubs(:find).returns("foo")
16
16
  end
17
17
 
18
+ context "checking virtualbox version" do
19
+ setup do
20
+ VirtualBox::Command.stubs(:version)
21
+ end
22
+
23
+ should "error and exit if VirtualBox is not installed or detected" do
24
+ Vagrant::Env.expects(:error_and_exit).once
25
+ VirtualBox::Command.expects(:version).returns(nil)
26
+ Vagrant::Env.check_virtualbox!
27
+ end
28
+
29
+ should "error and exit if VirtualBox is lower than version 3.1" do
30
+ Vagrant::Env.expects(:error_and_exit).once
31
+ VirtualBox::Command.expects(:version).returns("3.0.12r1041")
32
+ Vagrant::Env.check_virtualbox!
33
+ end
34
+ end
35
+
18
36
  context "requiring a VM" do
19
37
  setup do
20
38
  Vagrant::Env.stubs(:require_root_path)
@@ -89,6 +107,20 @@ class EnvTest < Test::Unit::TestCase
89
107
  Vagrant::Env.load_config!
90
108
  end
91
109
 
110
+ should "load from the home directory" do
111
+ File.expects(:exist?).with(File.join(Vagrant::Env.home_path, Vagrant::Env::ROOTFILE_NAME)).once
112
+ Vagrant::Env.load_config!
113
+ end
114
+
115
+ should "not load from the home directory if the home config is nil" do
116
+ mock_config do |config|
117
+ config.vagrant.home = nil
118
+ end
119
+
120
+ File.expects(:exist?).with(File.join(Vagrant::Env.home_path, Vagrant::Env::ROOTFILE_NAME)).never
121
+ Vagrant::Env.load_config!
122
+ end
123
+
92
124
  should "not load from the root path if nil" do
93
125
  Vagrant::Env.stubs(:root_path).returns(nil)
94
126
  File.expects(:exist?).with(File.join(@root_path, Vagrant::Env::ROOTFILE_NAME)).never
@@ -129,29 +161,69 @@ class EnvTest < Test::Unit::TestCase
129
161
  end
130
162
 
131
163
  context "initial load" do
132
- test "load! should load the config and set the persisted_uid" do
133
- Vagrant::Env.expects(:load_config!).once
134
- Vagrant::Env.expects(:load_vm!).once
135
- Vagrant::Env.expects(:load_root_path!).once
136
- Vagrant::Env.expects(:load_home_directory!).once
137
- Vagrant::Env.expects(:load_box!).once
164
+ should "load! should load the config and set the persisted_uid" do
165
+ call_seq = sequence("call_sequence")
166
+ Vagrant::Env.expects(:load_root_path!).once.in_sequence(call_seq)
167
+ Vagrant::Env.expects(:load_config!).once.in_sequence(call_seq)
168
+ Vagrant::Env.expects(:load_home_directory!).once.in_sequence(call_seq)
169
+ Vagrant::Env.expects(:load_box!).once.in_sequence(call_seq)
170
+ Vagrant::Env.expects(:load_config!).once.in_sequence(call_seq)
171
+ Vagrant::Env.expects(:check_virtualbox!).once.in_sequence(call_seq)
172
+ Vagrant::Env.expects(:load_vm!).once.in_sequence(call_seq)
138
173
  Vagrant::Env.load!
139
174
  end
140
175
  end
141
176
 
142
177
  context "persisting the VM into a file" do
143
178
  setup do
144
- mock_config
145
- end
179
+ @vm = mock("vm")
180
+ @vm.stubs(:uuid).returns("foo")
146
181
 
147
- test "should save it to the dotfile path" do
148
- vm = mock("vm")
149
- vm.stubs(:uuid).returns("foo")
182
+ File.stubs(:open)
183
+ Vagrant::ActiveList.stubs(:add)
184
+ end
150
185
 
186
+ should "should save it to the dotfile path" do
151
187
  filemock = mock("filemock")
152
- filemock.expects(:write).with(vm.uuid)
188
+ filemock.expects(:write).with(@vm.uuid)
153
189
  File.expects(:open).with(Vagrant::Env.dotfile_path, 'w+').once.yields(filemock)
154
- Vagrant::Env.persist_vm(vm)
190
+ Vagrant::Env.persist_vm(@vm)
191
+ end
192
+
193
+ should "add the VM to the activelist" do
194
+ Vagrant::ActiveList.expects(:add).with(@vm)
195
+ Vagrant::Env.persist_vm(@vm)
196
+ end
197
+ end
198
+
199
+ context "depersisting the VM" do
200
+ setup do
201
+ File.stubs(:exist?).returns(false)
202
+ File.stubs(:delete)
203
+
204
+ Vagrant::ActiveList.stubs(:remove)
205
+
206
+ @dotfile_path = "foo"
207
+ Vagrant::Env.stubs(:dotfile_path).returns(@dotfile_path)
208
+
209
+ @vm = mock("vm")
210
+ end
211
+
212
+ should "remove the dotfile if it exists" do
213
+ File.expects(:exist?).with(Vagrant::Env.dotfile_path).returns(true)
214
+ File.expects(:delete).with(Vagrant::Env.dotfile_path).once
215
+ Vagrant::Env.depersist_vm(@vm)
216
+ end
217
+
218
+ should "not remove the dotfile if it doesn't exist" do
219
+ File.expects(:exist?).returns(false)
220
+ File.expects(:delete).never
221
+ Vagrant::Env.depersist_vm(@vm)
222
+ end
223
+
224
+ should "remove from the active list" do
225
+ Vagrant::ActiveList.expects(:remove).with(@vm)
226
+ Vagrant::Env.depersist_vm(@vm)
155
227
  end
156
228
  end
157
229
 
@@ -191,7 +263,7 @@ class EnvTest < Test::Unit::TestCase
191
263
  context "loading the root path" do
192
264
  should "default the path to the pwd if nil" do
193
265
  @path = mock("path")
194
- @path.stubs(:to_s).returns("/")
266
+ @path.stubs(:root?).returns(true)
195
267
  Pathname.expects(:new).with(Dir.pwd).returns(@path)
196
268
  Vagrant::Env.load_root_path!(nil)
197
269
  end
@@ -199,7 +271,9 @@ class EnvTest < Test::Unit::TestCase
199
271
  should "not default the path to pwd if its not nil" do
200
272
  @path = mock("path")
201
273
  @path.stubs(:to_s).returns("/")
202
- Pathname.expects(:new).never
274
+ File.expects(:expand_path).with(@path).returns("/")
275
+ Pathname.expects(:new).with("/").returns(@path)
276
+ @path.stubs(:root?).returns(true)
203
277
  Vagrant::Env.load_root_path!(@path)
204
278
  end
205
279
 
@@ -224,8 +298,13 @@ class EnvTest < Test::Unit::TestCase
224
298
  end
225
299
 
226
300
  should "return false if not found on windows-style root" do
227
- path = Pathname.new("C:.")
228
- assert !Vagrant::Env.load_root_path!(path)
301
+ # TODO: Is there _any_ way to test this on unix machines? The
302
+ # expand path doesn't work [properly for the test] on unix machines.
303
+ if RUBY_PLATFORM.downcase.include?("mswin")
304
+ # Note the escaped back slash
305
+ path = Pathname.new("C:\\")
306
+ assert !Vagrant::Env.load_root_path!(path)
307
+ end
229
308
  end
230
309
 
231
310
  should "should set the path for the rootfile" do
@@ -283,12 +362,6 @@ class EnvTest < Test::Unit::TestCase
283
362
  Vagrant::Env.load_box!
284
363
  assert @box.equal?(Vagrant::Env.box)
285
364
  end
286
-
287
- should "load the config if a box is loaded" do
288
- Vagrant::Env.expects(:load_config!).once
289
- Vagrant::Box.expects(:find).returns(@box)
290
- Vagrant::Env.load_box!
291
- end
292
365
  end
293
366
 
294
367
  context "requiring boxes" do
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class BaseProvisionerTest < Test::Unit::TestCase
4
+ should "include the util class so subclasses have access to it" do
5
+ assert Vagrant::Provisioners::Base.include?(Vagrant::Util)
6
+ end
7
+
8
+ context "base instance" do
9
+ setup do
10
+ @base = Vagrant::Provisioners::Base.new
11
+ end
12
+
13
+ should "implement provision! which does nothing" do
14
+ assert_nothing_raised do
15
+ assert @base.respond_to?(:provision!)
16
+ @base.provision!
17
+ end
18
+ end
19
+
20
+ should "implement prepare which does nothing" do
21
+ assert_nothing_raised do
22
+ assert @base.respond_to?(:prepare)
23
+ @base.prepare
24
+ end
25
+ end
26
+ end
27
+ end