vagrantup 0.6.9 → 0.7.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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/CHANGELOG.md +37 -0
  4. data/Gemfile +0 -8
  5. data/README.md +5 -0
  6. data/config/default.rb +1 -3
  7. data/contrib/README.md +12 -0
  8. data/contrib/emacs/vagrant.el +8 -0
  9. data/contrib/vim/vagrantfile.vim +9 -0
  10. data/lib/vagrant/action/box/download.rb +0 -1
  11. data/lib/vagrant/action/box.rb +11 -0
  12. data/lib/vagrant/action/builtin.rb +1 -2
  13. data/lib/vagrant/action/env.rb +7 -0
  14. data/lib/vagrant/action/general.rb +8 -0
  15. data/lib/vagrant/action/vm/boot.rb +3 -2
  16. data/lib/vagrant/action/vm/check_box.rb +1 -0
  17. data/lib/vagrant/action/vm/clean_machine_folder.rb +1 -1
  18. data/lib/vagrant/action/vm/destroy.rb +1 -1
  19. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +7 -12
  20. data/lib/vagrant/action/vm/network.rb +1 -1
  21. data/lib/vagrant/action/vm/nfs.rb +3 -1
  22. data/lib/vagrant/action/vm/provision.rb +14 -25
  23. data/lib/vagrant/action/vm/share_folders.rb +11 -4
  24. data/lib/vagrant/action/vm.rb +30 -0
  25. data/lib/vagrant/action.rb +12 -0
  26. data/lib/vagrant/command.rb +25 -0
  27. data/lib/vagrant/config/base.rb +17 -3
  28. data/lib/vagrant/config/ssh.rb +2 -2
  29. data/lib/vagrant/config/top.rb +61 -0
  30. data/lib/vagrant/config/vagrant.rb +1 -6
  31. data/lib/vagrant/config/vm/provisioner.rb +56 -0
  32. data/lib/vagrant/config/vm/sub_vm.rb +17 -0
  33. data/lib/vagrant/config/vm.rb +34 -20
  34. data/lib/vagrant/config.rb +78 -128
  35. data/lib/vagrant/downloaders/file.rb +1 -0
  36. data/lib/vagrant/downloaders/http.rb +9 -0
  37. data/lib/vagrant/downloaders.rb +7 -0
  38. data/lib/vagrant/environment.rb +26 -14
  39. data/lib/vagrant/errors.rb +5 -15
  40. data/lib/vagrant/hosts.rb +7 -0
  41. data/lib/vagrant/provisioners/base.rb +19 -1
  42. data/lib/vagrant/provisioners/chef.rb +31 -52
  43. data/lib/vagrant/provisioners/chef_server.rb +34 -10
  44. data/lib/vagrant/provisioners/chef_solo.rb +31 -9
  45. data/lib/vagrant/provisioners/puppet.rb +111 -60
  46. data/lib/vagrant/provisioners/puppet_server.rb +57 -0
  47. data/lib/vagrant/provisioners.rb +8 -0
  48. data/lib/vagrant/ssh/session.rb +81 -0
  49. data/lib/vagrant/ssh.rb +6 -76
  50. data/lib/vagrant/systems/base.rb +16 -1
  51. data/lib/vagrant/systems/debian.rb +26 -0
  52. data/lib/vagrant/systems/gentoo.rb +27 -0
  53. data/lib/vagrant/systems/linux/config.rb +21 -0
  54. data/lib/vagrant/systems/linux/error.rb +9 -0
  55. data/lib/vagrant/systems/linux.rb +14 -56
  56. data/lib/vagrant/systems/redhat.rb +31 -0
  57. data/lib/vagrant/systems.rb +9 -0
  58. data/lib/vagrant/test_helpers.rb +1 -1
  59. data/lib/vagrant/version.rb +1 -1
  60. data/lib/vagrant/vm.rb +25 -5
  61. data/lib/vagrant.rb +14 -18
  62. data/templates/chef_solo_solo.erb +11 -3
  63. data/templates/commands/init/Vagrantfile.erb +13 -11
  64. data/templates/locales/en.yml +76 -26
  65. data/templates/{network_entry.erb → network_entry_debian.erb} +0 -0
  66. data/templates/network_entry_gentoo.erb +7 -0
  67. data/templates/network_entry_redhat.erb +8 -0
  68. data/templates/ssh_config.erb +1 -1
  69. data/test/vagrant/action/vm/check_box_test.rb +1 -0
  70. data/test/vagrant/action/vm/clean_machine_folder_test.rb +6 -4
  71. data/test/vagrant/action/vm/destroy_test.rb +1 -1
  72. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +10 -7
  73. data/test/vagrant/action/vm/nfs_test.rb +7 -1
  74. data/test/vagrant/action/vm/provision_test.rb +24 -79
  75. data/test/vagrant/action/vm/share_folders_test.rb +6 -1
  76. data/test/vagrant/command/helpers_test.rb +2 -2
  77. data/test/vagrant/config/base_test.rb +0 -6
  78. data/test/vagrant/config/vagrant_test.rb +0 -8
  79. data/test/vagrant/config/vm/provisioner_test.rb +92 -0
  80. data/test/vagrant/config/vm_test.rb +8 -0
  81. data/test/vagrant/config_test.rb +49 -89
  82. data/test/vagrant/downloaders/file_test.rb +18 -4
  83. data/test/vagrant/environment_test.rb +36 -12
  84. data/test/vagrant/provisioners/base_test.rb +28 -1
  85. data/test/vagrant/provisioners/chef_server_test.rb +50 -41
  86. data/test/vagrant/provisioners/chef_solo_test.rb +39 -16
  87. data/test/vagrant/provisioners/chef_test.rb +11 -81
  88. data/test/vagrant/provisioners/puppet_server_test.rb +69 -0
  89. data/test/vagrant/provisioners/puppet_test.rb +116 -69
  90. data/test/vagrant/{ssh_session_test.rb → ssh/session_test.rb} +0 -0
  91. data/test/vagrant/ssh_test.rb +20 -7
  92. data/test/vagrant/systems/base_test.rb +18 -0
  93. data/test/vagrant/systems/linux_test.rb +2 -2
  94. data/test/vagrant/vm_test.rb +33 -5
  95. data/vagrant.gemspec +6 -5
  96. metadata +38 -14
  97. data/lib/vagrant/action/vm/disable_networks.rb +0 -34
  98. data/lib/vagrant/util/glob_loader.rb +0 -24
  99. data/test/vagrant/action/vm/disable_networks_test.rb +0 -48
@@ -5,117 +5,79 @@ class ConfigTest < Test::Unit::TestCase
5
5
  @klass = Vagrant::Config
6
6
  end
7
7
 
8
- context "with an instance" do
9
- setup do
10
- @env = vagrant_env
11
- @instance = @klass.new(@env)
12
- end
8
+ context "with the class" do
9
+ should "allow access to the last proc" do
10
+ foo = mock("object")
11
+ foo.expects(:call).once
13
12
 
14
- should "initially have an empty queue" do
15
- assert @instance.queue.empty?
16
- end
13
+ @klass.run { |config| foo.call }
14
+ value = @klass.last_proc.first
15
+ assert value.is_a?(Proc)
16
+ value.call(nil)
17
17
 
18
- should "reset the config class on load, then execute" do
19
- seq = sequence("sequence")
20
- @klass.expects(:reset!).with(@env).in_sequence(seq)
21
- @klass.expects(:execute!).in_sequence(seq)
22
- @instance.load!
18
+ assert @klass.last_proc.nil?
23
19
  end
20
+ end
24
21
 
25
- should "run the queue in the order given" do
26
- @instance.queue << Proc.new { |config| config.vm.box = "foo" }
27
- @instance.queue << Proc.new { |config| config.vm.box = "bar" }
28
- result = @instance.load!
29
-
30
- assert_equal "bar", result.vm.box
22
+ context "with an instance" do
23
+ setup do
24
+ @instance = @klass.new
31
25
  end
32
26
 
33
- should "allow nested arrays" do
34
- queue = []
35
- queue << Proc.new { |config| config.vm.box = "foo" }
36
- queue << Proc.new { |config| config.vm.box = "bar" }
37
- @instance.queue << queue
38
- result = @instance.load!
27
+ should "load the config files in the given order" do
28
+ names = %w{alpha beta gamma}
39
29
 
40
- assert_equal "bar", result.vm.box
41
- end
30
+ @instance.load_order = [:alpha, :beta]
42
31
 
43
- should "load a file if it exists" do
44
- filename = "foo"
45
- File.expects(:exist?).with(filename).returns(true)
46
- @instance.expects(:load).with(filename).once
32
+ names.each do |name|
33
+ vagrantfile(vagrant_box(name), "config.vm.box = '#{name}'")
34
+ @instance.set(name.to_sym, vagrant_box(name).join("Vagrantfile"))
35
+ end
47
36
 
48
- @instance.queue << filename
49
- @instance.load!
37
+ config = @instance.load(nil)
38
+ assert_equal "beta", config.vm.box
50
39
  end
51
40
 
52
- should "not load a file if it doesn't exist" do
53
- filename = "foo"
54
- File.expects(:exist?).with(filename).returns(false)
55
- @instance.expects(:load).with(filename).never
41
+ should "load the config as procs" do
42
+ @instance.set(:proc, Proc.new { |config| config.vm.box = "proc" })
43
+ @instance.load_order = [:proc]
44
+ config = @instance.load(nil)
56
45
 
57
- @instance.queue << filename
58
- @instance.load!
46
+ assert_equal "proc", config.vm.box
59
47
  end
60
48
 
61
- should "raise an exception if there is a syntax error in a file" do
62
- @instance.queue << "foo"
63
- File.expects(:exist?).with("foo").returns(true)
64
- @instance.expects(:load).with("foo").raises(SyntaxError.new)
49
+ should "load an array of procs" do
50
+ @instance.set(:proc, [Proc.new { |config| config.vm.box = "proc" },
51
+ Proc.new { |config| config.vm.box = "proc2" }])
52
+ @instance.load_order = [:proc]
53
+ config = @instance.load(nil)
65
54
 
66
- assert_raises(Vagrant::Errors::VagrantfileSyntaxError) {
67
- @instance.load!
68
- }
55
+ assert_equal "proc2", config.vm.box
69
56
  end
70
- end
71
57
 
72
- context "resetting" do
73
- setup do
74
- @klass.reset!(vagrant_env)
75
- @klass::Top.any_instance.stubs(:validate!)
76
- @klass.run { |config| }
77
- @klass.execute!
58
+ should "not care if a file doesn't exist" do
59
+ @instance.load_order = [:foo]
60
+ assert_nothing_raised { @instance.set(:foo, "i/dont/exist") }
61
+ assert_nothing_raised { @instance.load(nil) }
78
62
  end
79
63
 
80
- should "return the same config object typically" do
81
- config = @klass.config
82
- assert config.equal?(@klass.config)
83
- end
64
+ should "not reload a file" do
65
+ foo_path = vagrant_box("foo").join("Vagrantfile")
84
66
 
85
- should "create a new object if cleared" do
86
- config = @klass.config
87
- @klass.reset!
88
- assert !config.equal?(@klass.config)
89
- end
67
+ vagrantfile(vagrant_box("foo"))
68
+ @instance.set(:foo, foo_path)
90
69
 
91
- should "empty the proc stack" do
92
- assert !@klass.proc_stack.empty?
93
- @klass.reset!
94
- assert @klass.proc_stack.empty?
70
+ # Nothing should be raised in this case because the file isn't reloaded
71
+ vagrantfile(vagrant_box("foo"), "^%&8318")
72
+ assert_nothing_raised { @instance.set(:foo, foo_path) }
95
73
  end
96
74
 
97
- should "reload the config object based on the given environment" do
98
- env = mock("env")
99
- @klass.expects(:config).with(env).once
100
- @klass.reset!(env)
101
- end
102
- end
103
-
104
- context "initializing" do
105
- setup do
106
- @klass.reset!(vagrant_env)
107
- end
108
-
109
- should "add the given block to the proc stack" do
110
- proc = Proc.new {}
111
- @klass.run(&proc)
112
- assert_equal [proc], @klass.proc_stack
113
- end
75
+ should "raise an exception if there is a syntax error in a file" do
76
+ vagrantfile(vagrant_box("foo"), "^%&8318")
114
77
 
115
- should "return the configuration on execute!" do
116
- @klass.run {}
117
- result = @klass.execute!
118
- assert result.is_a?(@klass::Top)
78
+ assert_raises(Vagrant::Errors::VagrantfileSyntaxError) {
79
+ @instance.set(:foo, vagrant_box("foo").join("Vagrantfile"))
80
+ }
119
81
  end
120
82
  end
121
83
 
@@ -149,7 +111,6 @@ class ConfigTest < Test::Unit::TestCase
149
111
  key = "key#{i}"
150
112
  klass = mock("klass#{i}")
151
113
  instance = mock("instance#{i}")
152
- instance.expects(:env=).with(env)
153
114
  instance.expects(:top=).with() do |top|
154
115
  assert top.is_a?(@klass::Top)
155
116
  true
@@ -165,7 +126,6 @@ class ConfigTest < Test::Unit::TestCase
165
126
  key = "my_foo_bar_key"
166
127
  klass = mock("klass")
167
128
  instance = mock("instance")
168
- instance.stubs(:env=)
169
129
  instance.stubs(:top=)
170
130
  klass.expects(:new).returns(instance)
171
131
  @klass::Top.configures(key, klass)
@@ -17,11 +17,25 @@ class FileDownloaderTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  context "downloading" do
20
+ setup do
21
+ clean_paths
22
+ end
23
+
20
24
  should "cp the file" do
21
- path = '/path'
22
- @tempfile.expects(:path).returns(path)
23
- FileUtils.expects(:cp).with(@uri, path)
24
- @downloader.download!(@uri, @tempfile)
25
+ uri = tmp_path.join("foo_source")
26
+ dest = tmp_path.join("foo_dest")
27
+
28
+ # Create the source file, then "download" it
29
+ File.open(uri, "w+") { |f| f.write("FOO") }
30
+ File.open(dest, "w+") do |dest_file|
31
+ @downloader.download!(uri, dest_file)
32
+ end
33
+
34
+ # Finally, verify the destination file was properly created
35
+ assert File.file?(dest)
36
+ File.open(dest) do |f|
37
+ assert_equal "FOO", f.read
38
+ end
25
39
  end
26
40
  end
27
41
 
@@ -4,15 +4,17 @@ require "pathname"
4
4
  class EnvironmentTest < Test::Unit::TestCase
5
5
  setup do
6
6
  @klass = Vagrant::Environment
7
+
8
+ clean_paths
7
9
  end
8
10
 
9
11
  context "class method check virtualbox version" do
10
12
  setup do
11
- VirtualBox.stubs(:version).returns("3.1.4")
13
+ VirtualBox.stubs(:version).returns("4.0.0")
12
14
  end
13
15
 
14
16
  should "not error and exit if everything is good" do
15
- VirtualBox.expects(:version).returns("3.2.4")
17
+ VirtualBox.expects(:version).returns("4.0.0")
16
18
  assert_nothing_raised { @klass.check_virtualbox! }
17
19
  end
18
20
 
@@ -21,17 +23,11 @@ class EnvironmentTest < Test::Unit::TestCase
21
23
  assert_raises(Vagrant::Errors::VirtualBoxNotDetected) { @klass.check_virtualbox! }
22
24
  end
23
25
 
24
- should "error and exit if VirtualBox is lower than version 3.2" do
25
- version = "3.1.12r1041"
26
+ should "error and exit if VirtualBox is lower than version 4.0" do
27
+ version = "3.2.12r1041"
26
28
  VirtualBox.expects(:version).returns(version)
27
29
  assert_raises(Vagrant::Errors::VirtualBoxInvalidVersion) { @klass.check_virtualbox! }
28
30
  end
29
-
30
- should "error and exit for OSE VirtualBox" do
31
- version = "3.2.6_OSE"
32
- VirtualBox.expects(:version).returns(version)
33
- assert_raises(Vagrant::Errors::VirtualBoxInvalidOSE) { @klass.check_virtualbox! }
34
- end
35
31
  end
36
32
 
37
33
  context "initialization" do
@@ -59,8 +55,21 @@ class EnvironmentTest < Test::Unit::TestCase
59
55
  end
60
56
 
61
57
  context "home path" do
58
+ setup do
59
+ @env = @klass.new
60
+ end
61
+
62
62
  should "return the home path if it loaded" do
63
- expected = Pathname.new(File.expand_path(@env.config.vagrant.home, @env.root_path))
63
+ ENV["VAGRANT_HOME"] = nil
64
+
65
+ expected = Pathname.new(File.expand_path(@klass::DEFAULT_HOME))
66
+ assert_equal expected, @env.home_path
67
+ end
68
+
69
+ should "return the home path set by the environmental variable" do
70
+ ENV["VAGRANT_HOME"] = "foo"
71
+
72
+ expected = Pathname.new(File.expand_path(ENV["VAGRANT_HOME"]))
64
73
  assert_equal expected, @env.home_path
65
74
  end
66
75
  end
@@ -391,7 +400,7 @@ class EnvironmentTest < Test::Unit::TestCase
391
400
  create_box_vagrantfile
392
401
  vagrantfile(@env.root_path, "config.vm.box = 'box'")
393
402
 
394
- assert_equal "box.box", @env.config.package.name
403
+ assert_equal "box.box", @env.primary_vm.env.config.package.name
395
404
  end
396
405
 
397
406
  should "load from home path if exists" do
@@ -425,6 +434,21 @@ class EnvironmentTest < Test::Unit::TestCase
425
434
  @env.load_config!
426
435
  assert @env.instance_variable_get(:@logger).nil?
427
436
  end
437
+
438
+ should "be able to reload config" do
439
+ vagrantfile(@env.root_path, "config.vm.box = 'box'")
440
+
441
+ # First load the config normally
442
+ @env.load_config!
443
+ assert_equal "box", @env.config.vm.box
444
+ assert_not_equal "set", @env.config.vm.base_mac
445
+
446
+ # Modify the Vagrantfile and reload it, then verify new results
447
+ # are available
448
+ vagrantfile(@env.root_path, "config.vm.base_mac = 'set'")
449
+ @env.reload_config!
450
+ assert_equal "set", @env.config.vm.base_mac
451
+ end
428
452
  end
429
453
 
430
454
  context "loading home directory" do
@@ -1,14 +1,37 @@
1
1
  require "test_helper"
2
2
 
3
3
  class BaseProvisionerTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Provisioners::Base
6
+ end
7
+
4
8
  should "include the util class so subclasses have access to it" do
5
9
  assert Vagrant::Provisioners::Base.include?(Vagrant::Util)
6
10
  end
7
11
 
12
+ context "registering provisioners" do
13
+ teardown do
14
+ @klass.registered.delete(:zomg)
15
+ end
16
+
17
+ should "not have unregistered provisioners" do
18
+ assert_nil @klass.registered[:foo]
19
+ end
20
+
21
+ should "be able to register a provisioner" do
22
+ foo = Class.new(@klass) do
23
+ register :zomg
24
+ end
25
+
26
+ assert_equal foo, @klass.registered[:zomg]
27
+ end
28
+ end
29
+
8
30
  context "base instance" do
9
31
  setup do
10
32
  @env = Vagrant::Action::Environment.new(vagrant_env)
11
- @base = Vagrant::Provisioners::Base.new(@env)
33
+ @config = mock("config")
34
+ @base = Vagrant::Provisioners::Base.new(@env, @config)
12
35
  end
13
36
 
14
37
  should "set the environment" do
@@ -19,6 +42,10 @@ class BaseProvisionerTest < Test::Unit::TestCase
19
42
  assert_equal @env.env.vm, @base.vm
20
43
  end
21
44
 
45
+ should "provide access to the config" do
46
+ assert_equal @config, @base.config
47
+ end
48
+
22
49
  should "implement provision! which does nothing" do
23
50
  assert_nothing_raised do
24
51
  assert @base.respond_to?(:provision!)
@@ -2,13 +2,44 @@ require "test_helper"
2
2
 
3
3
  class ChefServerProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
+ @klass = Vagrant::Provisioners::ChefServer
6
+
5
7
  @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
6
8
 
7
- @action = Vagrant::Provisioners::ChefServer.new(@action_env)
9
+ @config = @klass::Config.new
10
+ @action = @klass.new(@action_env, @config)
8
11
  @env = @action.env
9
12
  @vm = @action.vm
10
13
  end
11
14
 
15
+ context "config validation" do
16
+ setup do
17
+ @errors = Vagrant::Config::ErrorRecorder.new
18
+
19
+ @config.run_list = ["foo"]
20
+ @config.chef_server_url = "foo"
21
+ @config.validation_key_path = "foo"
22
+ end
23
+
24
+ should "be invalid if run list is empty" do
25
+ @config.run_list = []
26
+ @config.validate(@errors)
27
+ assert !@errors.errors.empty?
28
+ end
29
+
30
+ should "be invalid if run list is empty" do
31
+ @config.chef_server_url = nil
32
+ @config.validate(@errors)
33
+ assert !@errors.errors.empty?
34
+ end
35
+
36
+ should "be invalid if run list is empty" do
37
+ @config.validation_key_path = nil
38
+ @config.validate(@errors)
39
+ assert !@errors.errors.empty?
40
+ end
41
+ end
42
+
12
43
  context "provisioning" do
13
44
  should "run the proper sequence of methods in order" do
14
45
  prov_seq = sequence("prov_seq")
@@ -29,21 +60,14 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
29
60
  end
30
61
 
31
62
  should "not raise an exception if validation_key_path is set" do
32
- @env = vagrant_env(vagrantfile(<<-vf))
33
- config.chef.validation_key_path = "7"
34
- config.chef.chef_server_url = "7"
35
- vf
63
+ @config.validation_key_path = "7"
64
+ @config.chef_server_url = "7"
36
65
 
37
- @action.stubs(:env).returns(@env)
38
66
  assert_nothing_raised { @action.prepare }
39
67
  end
40
68
 
41
69
  should "raise an exception if validation_key_path is nil" do
42
- @env = vagrant_env(vagrantfile(<<-vf))
43
- config.chef.validation_key_path = nil
44
- vf
45
-
46
- @action.stubs(:env).returns(@env)
70
+ @config.validation_key_path = nil
47
71
 
48
72
  assert_raises(Vagrant::Provisioners::Chef::ChefError) {
49
73
  @action.prepare
@@ -51,23 +75,15 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
51
75
  end
52
76
 
53
77
  should "not raise an exception if validation_key_path does exist" do
54
- @env = vagrant_env(vagrantfile(<<-vf))
55
- config.chef.validation_key_path = "#{vagrantfile(tmp_path)}"
56
- config.chef.chef_server_url = "7"
57
- vf
78
+ @config.validation_key_path = vagrantfile(tmp_path)
79
+ @config.chef_server_url = "7"
58
80
 
59
- @action.stubs(:env).returns(@env)
60
81
  assert_nothing_raised { @action.prepare }
61
82
  end
62
83
 
63
84
  should "raise an exception if validation_key_path doesn't exist" do
64
- @env = vagrant_env(vagrantfile(<<-vf))
65
- config.chef.validation_key_path = "7"
66
- config.chef.chef_server_url = "7"
67
- vf
68
-
69
- @action.stubs(:env).returns(@env)
70
- @action.stubs(:validation_key_path).returns("9")
85
+ @config.validation_key_path = "7"
86
+ @config.chef_server_url = "7"
71
87
 
72
88
  File.expects(:file?).with(@action.validation_key_path).returns(false)
73
89
  assert_raises(Vagrant::Provisioners::Chef::ChefError) {
@@ -76,21 +92,14 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
76
92
  end
77
93
 
78
94
  should "not raise an exception if chef_server_url is set" do
79
- @env = vagrant_env(vagrantfile(<<-vf))
80
- config.chef.validation_key_path = "#{vagrantfile(tmp_path)}"
81
- config.chef.chef_server_url = "7"
82
- vf
95
+ @config.validation_key_path = vagrantfile(tmp_path)
96
+ @config.chef_server_url = "7"
83
97
 
84
- @action.stubs(:env).returns(@env)
85
98
  assert_nothing_raised { @action.prepare }
86
99
  end
87
100
 
88
101
  should "raise an exception if chef_server_url is nil" do
89
- @env = vagrant_env(vagrantfile(<<-vf))
90
- config.chef.chef_server_url = nil
91
- vf
92
-
93
- @action.stubs(:env).returns(@env)
102
+ @config.chef_server_url = nil
94
103
 
95
104
  assert_raises(Vagrant::Provisioners::Chef::ChefError) {
96
105
  @action.prepare
@@ -101,7 +110,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
101
110
  context "creating the client key folder" do
102
111
  setup do
103
112
  @raw_path = "/foo/bar/baz.pem"
104
- @env.config.chef.client_key_path = @raw_path
113
+ @config.client_key_path = @raw_path
105
114
 
106
115
  @path = Pathname.new(@raw_path)
107
116
  end
@@ -126,7 +135,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
126
135
  context "the validation key path" do
127
136
  should "expand the configured key path" do
128
137
  result = mock("result")
129
- File.expects(:expand_path).with(@env.config.chef.validation_key_path, @env.root_path).once.returns(result)
138
+ File.expects(:expand_path).with(@config.validation_key_path, @env.root_path).once.returns(result)
130
139
  assert_equal result, @action.validation_key_path
131
140
  end
132
141
  end
@@ -134,7 +143,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
134
143
  context "the guest validation key path" do
135
144
  should "be the provisioning path joined with validation.pem" do
136
145
  result = mock("result")
137
- File.expects(:join).with(@env.config.chef.provisioning_path, "validation.pem").once.returns(result)
146
+ File.expects(:join).with(@config.provisioning_path, "validation.pem").once.returns(result)
138
147
  assert_equal result, @action.guest_validation_key_path
139
148
  end
140
149
  end
@@ -146,11 +155,11 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
146
155
 
147
156
  should "call setup_config with proper variables" do
148
157
  @action.expects(:setup_config).with("chef_server_client", "client.rb", {
149
- :node_name => @env.config.chef.node_name,
150
- :chef_server_url => @env.config.chef.chef_server_url,
151
- :validation_client_name => @env.config.chef.validation_client_name,
158
+ :node_name => @config.node_name,
159
+ :chef_server_url => @config.chef_server_url,
160
+ :validation_client_name => @config.validation_client_name,
152
161
  :validation_key => @action.guest_validation_key_path,
153
- :client_key => @env.config.chef.client_key_path
162
+ :client_key => @config.client_key_path
154
163
  })
155
164
 
156
165
  @action.setup_server_config
@@ -164,7 +173,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
164
173
  end
165
174
 
166
175
  should "cd into the provisioning directory and run chef client" do
167
- @ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json").once
176
+ @ssh.expects(:exec!).with("sudo -i 'cd #{@config.provisioning_path} && chef-client -c client.rb -j dna.json'").once
168
177
  @action.run_chef_client
169
178
  end
170
179
 
@@ -2,13 +2,36 @@ require "test_helper"
2
2
 
3
3
  class ChefSoloProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
+ @klass = Vagrant::Provisioners::ChefSolo
6
+
5
7
  @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
6
8
 
7
- @action = Vagrant::Provisioners::ChefSolo.new(@action_env)
9
+ @config = @klass::Config.new
10
+ @action = @klass.new(@action_env, @config)
8
11
  @env = @action.env
9
12
  @vm = @action.vm
10
13
  end
11
14
 
15
+ context "config validation" do
16
+ setup do
17
+ @errors = Vagrant::Config::ErrorRecorder.new
18
+ @config.run_list = ["foo"]
19
+ @config.cookbooks_path = "cookbooks"
20
+ end
21
+
22
+ should "be invalid if run list is empty" do
23
+ @config.run_list = []
24
+ @config.validate(@errors)
25
+ assert !@errors.errors.empty?
26
+ end
27
+
28
+ should "be invalid if cookbooks path is empty" do
29
+ @config.cookbooks_path = nil
30
+ @config.validate(@errors)
31
+ assert !@errors.errors.empty?
32
+ end
33
+ end
34
+
12
35
  context "preparing" do
13
36
  should "share cookbook folders" do
14
37
  @action.expects(:share_cookbook_folders).once
@@ -87,8 +110,8 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
87
110
  context "host cookbooks paths" do
88
111
  should "get folders path for configured cookbooks path" do
89
112
  result = mock("result")
90
- @env.config.chef.stubs(:cookbooks_path).returns("foo")
91
- @action.expects(:host_folder_paths).with(@env.config.chef.cookbooks_path).returns(result)
113
+ @config.stubs(:cookbooks_path).returns("foo")
114
+ @action.expects(:host_folder_paths).with(@config.cookbooks_path).returns(result)
92
115
  assert_equal result, @action.host_cookbook_paths
93
116
  end
94
117
  end
@@ -96,15 +119,15 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
96
119
  context "host roles paths" do
97
120
  should "get folders path for configured roles path" do
98
121
  result = mock("result")
99
- @env.config.chef.stubs(:roles_path).returns("foo")
100
- @action.expects(:host_folder_paths).with(@env.config.chef.roles_path).returns(result)
122
+ @config.stubs(:roles_path).returns("foo")
123
+ @action.expects(:host_folder_paths).with(@config.roles_path).returns(result)
101
124
  assert_equal result, @action.host_role_paths
102
125
  end
103
126
  end
104
127
 
105
128
  context "folder path" do
106
129
  should "return a proper path to a single folder" do
107
- expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
130
+ expected = File.join(@config.provisioning_path, "cookbooks-5")
108
131
  assert_equal expected, @action.folder_path("cookbooks", 5)
109
132
  end
110
133
 
@@ -125,33 +148,33 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
125
148
  end
126
149
 
127
150
  should "properly format VM folder paths" do
128
- @env.config.chef.provisioning_path = "/foo"
151
+ @config.provisioning_path = "/foo"
129
152
  assert_equal "/foo/bar", @action.folders_path([:vm, "bar"], nil)
130
153
  end
131
154
  end
132
155
 
133
156
  context "cookbooks path" do
134
157
  should "return a proper path to a single cookbook" do
135
- expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
158
+ expected = File.join(@config.provisioning_path, "cookbooks-5")
136
159
  assert_equal expected, @action.cookbook_path(5)
137
160
  end
138
161
 
139
162
  should "properly call folders path and return result" do
140
163
  result = [:a, :b, :c]
141
- @action.expects(:folders_path).with(@env.config.chef.cookbooks_path, "cookbooks").once.returns(result)
164
+ @action.expects(:folders_path).with(@config.cookbooks_path, "cookbooks").once.returns(result)
142
165
  assert_equal result.to_json, @action.cookbooks_path
143
166
  end
144
167
  end
145
168
 
146
169
  context "roles path" do
147
170
  should "return a proper path to a single role" do
148
- expected = File.join(@env.config.chef.provisioning_path, "roles-5")
171
+ expected = File.join(@config.provisioning_path, "roles-5")
149
172
  assert_equal expected, @action.role_path(5)
150
173
  end
151
174
 
152
175
  should "properly call folders path and return result" do
153
176
  result = [:a, :b, :c]
154
- @action.expects(:folders_path).with(@env.config.chef.roles_path, "roles").once.returns(result)
177
+ @action.expects(:folders_path).with(@config.roles_path, "roles").once.returns(result)
155
178
  assert_equal result.to_json, @action.roles_path
156
179
  end
157
180
  end
@@ -160,15 +183,15 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
160
183
  setup do
161
184
  @vm.ssh.stubs(:upload!)
162
185
 
163
- @env.config.chef.recipe_url = "foo/bar/baz"
186
+ @config.recipe_url = "foo/bar/baz"
164
187
  end
165
188
 
166
189
  should "call setup_config with proper variables" do
167
190
  @action.expects(:setup_config).with("chef_solo_solo", "solo.rb", {
168
- :node_name => @env.config.chef.node_name,
169
- :provisioning_path => @env.config.chef.provisioning_path,
191
+ :node_name => @config.node_name,
192
+ :provisioning_path => @config.provisioning_path,
170
193
  :cookbooks_path => @action.cookbooks_path,
171
- :recipe_url => @env.config.chef.recipe_url,
194
+ :recipe_url => @config.recipe_url,
172
195
  :roles_path => @action.roles_path
173
196
  })
174
197
 
@@ -183,7 +206,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
183
206
  end
184
207
 
185
208
  should "cd into the provisioning directory and run chef solo" do
186
- @ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json").once
209
+ @ssh.expects(:exec!).with("sudo -i 'cd #{@config.provisioning_path} && chef-solo -c solo.rb -j dna.json'").once
187
210
  @action.run_chef_solo
188
211
  end
189
212