vagrant 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/Gemfile +4 -4
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/bin/vagrant +5 -13
  5. data/config/default.rb +1 -0
  6. data/keys/README.md +8 -1
  7. data/keys/vagrant.ppk +26 -0
  8. data/lib/vagrant.rb +3 -3
  9. data/lib/vagrant/actions/base.rb +15 -4
  10. data/lib/vagrant/actions/box/add.rb +1 -1
  11. data/lib/vagrant/actions/box/download.rb +72 -66
  12. data/lib/vagrant/actions/box/unpackage.rb +1 -4
  13. data/lib/vagrant/actions/runner.rb +1 -1
  14. data/lib/vagrant/actions/vm/boot.rb +5 -7
  15. data/lib/vagrant/actions/vm/customize.rb +2 -2
  16. data/lib/vagrant/actions/vm/destroy.rb +2 -2
  17. data/lib/vagrant/actions/vm/down.rb +7 -0
  18. data/lib/vagrant/actions/vm/export.rb +10 -4
  19. data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
  20. data/lib/vagrant/actions/vm/halt.rb +5 -3
  21. data/lib/vagrant/actions/vm/import.rb +10 -3
  22. data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
  23. data/lib/vagrant/actions/vm/package.rb +33 -10
  24. data/lib/vagrant/actions/vm/provision.rb +4 -4
  25. data/lib/vagrant/actions/vm/reload.rb +1 -1
  26. data/lib/vagrant/actions/vm/resume.rb +1 -1
  27. data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
  28. data/lib/vagrant/actions/vm/start.rb +3 -2
  29. data/lib/vagrant/actions/vm/suspend.rb +2 -2
  30. data/lib/vagrant/actions/vm/up.rb +7 -17
  31. data/lib/vagrant/active_list.rb +52 -45
  32. data/lib/vagrant/box.rb +18 -11
  33. data/lib/vagrant/busy.rb +7 -0
  34. data/lib/vagrant/command.rb +27 -0
  35. data/lib/vagrant/commands/base.rb +163 -0
  36. data/lib/vagrant/commands/box.rb +16 -0
  37. data/lib/vagrant/commands/box/add.rb +24 -0
  38. data/lib/vagrant/commands/box/list.rb +30 -0
  39. data/lib/vagrant/commands/box/remove.rb +31 -0
  40. data/lib/vagrant/commands/destroy.rb +23 -0
  41. data/lib/vagrant/commands/down.rb +16 -0
  42. data/lib/vagrant/commands/halt.rb +23 -0
  43. data/lib/vagrant/commands/init.rb +32 -0
  44. data/lib/vagrant/commands/package.rb +46 -0
  45. data/lib/vagrant/commands/reload.rb +22 -0
  46. data/lib/vagrant/commands/resume.rb +22 -0
  47. data/lib/vagrant/commands/ssh.rb +22 -0
  48. data/lib/vagrant/commands/ssh_config.rb +30 -0
  49. data/lib/vagrant/commands/status.rb +58 -0
  50. data/lib/vagrant/commands/suspend.rb +23 -0
  51. data/lib/vagrant/commands/up.rb +26 -0
  52. data/lib/vagrant/config.rb +21 -11
  53. data/lib/vagrant/downloaders/file.rb +5 -5
  54. data/lib/vagrant/downloaders/http.rb +10 -15
  55. data/lib/vagrant/environment.rb +259 -0
  56. data/lib/vagrant/provisioners/base.rb +7 -0
  57. data/lib/vagrant/provisioners/chef.rb +24 -9
  58. data/lib/vagrant/provisioners/chef_server.rb +23 -48
  59. data/lib/vagrant/provisioners/chef_solo.rb +48 -22
  60. data/lib/vagrant/ssh.rb +95 -46
  61. data/lib/vagrant/util.rb +2 -2
  62. data/lib/vagrant/util/errors.rb +36 -0
  63. data/lib/vagrant/util/platform.rb +12 -0
  64. data/lib/vagrant/util/progress_meter.rb +33 -0
  65. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  66. data/lib/vagrant/util/template_renderer.rb +83 -0
  67. data/lib/vagrant/vm.rb +1 -0
  68. data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
  69. data/templates/chef_server_client.erb +16 -0
  70. data/templates/chef_solo_solo.erb +4 -0
  71. data/templates/errors.yml +157 -0
  72. data/templates/package_Vagrantfile.erb +11 -0
  73. data/templates/ssh_config.erb +7 -0
  74. data/test/test_helper.rb +12 -15
  75. data/test/vagrant/actions/box/add_test.rb +1 -2
  76. data/test/vagrant/actions/box/destroy_test.rb +0 -1
  77. data/test/vagrant/actions/box/download_test.rb +40 -15
  78. data/test/vagrant/actions/box/unpackage_test.rb +2 -3
  79. data/test/vagrant/actions/collection_test.rb +8 -5
  80. data/test/vagrant/actions/runner_test.rb +8 -6
  81. data/test/vagrant/actions/vm/boot_test.rb +12 -11
  82. data/test/vagrant/actions/vm/customize_test.rb +2 -3
  83. data/test/vagrant/actions/vm/destroy_test.rb +2 -3
  84. data/test/vagrant/actions/vm/down_test.rb +16 -3
  85. data/test/vagrant/actions/vm/export_test.rb +4 -5
  86. data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
  87. data/test/vagrant/actions/vm/halt_test.rb +8 -2
  88. data/test/vagrant/actions/vm/import_test.rb +5 -5
  89. data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
  90. data/test/vagrant/actions/vm/package_test.rb +60 -22
  91. data/test/vagrant/actions/vm/provision_test.rb +7 -16
  92. data/test/vagrant/actions/vm/reload_test.rb +3 -2
  93. data/test/vagrant/actions/vm/resume_test.rb +0 -1
  94. data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
  95. data/test/vagrant/actions/vm/start_test.rb +10 -3
  96. data/test/vagrant/actions/vm/suspend_test.rb +1 -2
  97. data/test/vagrant/actions/vm/up_test.rb +19 -11
  98. data/test/vagrant/active_list_test.rb +148 -129
  99. data/test/vagrant/box_test.rb +26 -14
  100. data/test/vagrant/busy_test.rb +15 -6
  101. data/test/vagrant/command_test.rb +53 -0
  102. data/test/vagrant/commands/base_test.rb +118 -0
  103. data/test/vagrant/commands/box/add_test.rb +34 -0
  104. data/test/vagrant/commands/box/list_test.rb +32 -0
  105. data/test/vagrant/commands/box/remove_test.rb +41 -0
  106. data/test/vagrant/commands/destroy_test.rb +32 -0
  107. data/test/vagrant/commands/down_test.rb +17 -0
  108. data/test/vagrant/commands/halt_test.rb +28 -0
  109. data/test/vagrant/commands/init_test.rb +55 -0
  110. data/test/vagrant/commands/package_test.rb +84 -0
  111. data/test/vagrant/commands/reload_test.rb +28 -0
  112. data/test/vagrant/commands/resume_test.rb +33 -0
  113. data/test/vagrant/commands/ssh_config_test.rb +54 -0
  114. data/test/vagrant/commands/ssh_test.rb +32 -0
  115. data/test/vagrant/commands/status_test.rb +20 -0
  116. data/test/vagrant/commands/suspend_test.rb +33 -0
  117. data/test/vagrant/commands/up_test.rb +41 -0
  118. data/test/vagrant/config_test.rb +42 -17
  119. data/test/vagrant/downloaders/file_test.rb +7 -0
  120. data/test/vagrant/downloaders/http_test.rb +12 -0
  121. data/test/vagrant/environment_test.rb +595 -0
  122. data/test/vagrant/provisioners/base_test.rb +7 -1
  123. data/test/vagrant/provisioners/chef_server_test.rb +41 -51
  124. data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
  125. data/test/vagrant/provisioners/chef_test.rb +61 -15
  126. data/test/vagrant/ssh_test.rb +166 -38
  127. data/test/vagrant/util/errors_test.rb +57 -0
  128. data/test/vagrant/util/progress_meter_test.rb +33 -0
  129. data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
  130. data/test/vagrant/util/template_renderer_test.rb +138 -0
  131. data/test/vagrant/vm_test.rb +3 -2
  132. data/vagrant.gemspec +88 -33
  133. metadata +94 -51
  134. data/bin/vagrant-box +0 -34
  135. data/bin/vagrant-down +0 -27
  136. data/bin/vagrant-halt +0 -28
  137. data/bin/vagrant-init +0 -27
  138. data/bin/vagrant-package +0 -29
  139. data/bin/vagrant-reload +0 -29
  140. data/bin/vagrant-resume +0 -27
  141. data/bin/vagrant-ssh +0 -27
  142. data/bin/vagrant-status +0 -29
  143. data/bin/vagrant-suspend +0 -27
  144. data/bin/vagrant-up +0 -29
  145. data/lib/vagrant/commands.rb +0 -234
  146. data/lib/vagrant/env.rb +0 -189
  147. data/lib/vagrant/stacked_proc_runner.rb +0 -33
  148. data/test/vagrant/commands_test.rb +0 -269
  149. data/test/vagrant/env_test.rb +0 -418
@@ -7,7 +7,13 @@ class BaseProvisionerTest < Test::Unit::TestCase
7
7
 
8
8
  context "base instance" do
9
9
  setup do
10
- @base = Vagrant::Provisioners::Base.new
10
+ @env = mock_environment
11
+ @base = Vagrant::Provisioners::Base.new(@env)
12
+ end
13
+
14
+ should "set the environment" do
15
+ base = Vagrant::Provisioners::Base.new(@env)
16
+ assert_equal @env, base.env
11
17
  end
12
18
 
13
19
  should "implement provision! which does nothing" do
@@ -2,12 +2,8 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
2
 
3
3
  class ChefServerProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
- @action = Vagrant::Provisioners::ChefServer.new
6
-
7
- Vagrant::SSH.stubs(:execute)
8
- Vagrant::SSH.stubs(:upload!)
9
-
10
- mock_config
5
+ @env = mock_environment
6
+ @action = Vagrant::Provisioners::ChefServer.new(@env)
11
7
  end
12
8
 
13
9
  context "provisioning" do
@@ -17,7 +13,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
17
13
  @action.expects(:create_client_key_folder).once.in_sequence(prov_seq)
18
14
  @action.expects(:upload_validation_key).once.in_sequence(prov_seq)
19
15
  @action.expects(:setup_json).once.in_sequence(prov_seq)
20
- @action.expects(:setup_config).once.in_sequence(prov_seq)
16
+ @action.expects(:setup_server_config).once.in_sequence(prov_seq)
21
17
  @action.expects(:run_chef_client).once.in_sequence(prov_seq)
22
18
  @action.provision!
23
19
  end
@@ -29,56 +25,70 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
29
25
  end
30
26
 
31
27
  should "not raise an exception if validation_key_path is set" do
32
- mock_config do |config|
28
+ @env = mock_environment do |config|
33
29
  config.chef.validation_key_path = "7"
34
30
  end
35
31
 
32
+ @action.stubs(:env).returns(@env)
33
+
36
34
  assert_nothing_raised { @action.prepare }
37
35
  end
38
36
 
39
37
  should "raise an exception if validation_key_path is nil" do
40
- mock_config do |config|
38
+ @env = mock_environment do |config|
41
39
  config.chef.validation_key_path = nil
42
40
  end
43
41
 
42
+ @action.stubs(:env).returns(@env)
43
+
44
44
  assert_raises(Vagrant::Actions::ActionException) {
45
45
  @action.prepare
46
46
  }
47
47
  end
48
48
 
49
49
  should "not raise an exception if validation_key_path does exist" do
50
- mock_config do |config|
50
+ @env = mock_environment do |config|
51
51
  config.chef.validation_key_path = "7"
52
52
  end
53
53
 
54
- File.expects(:file?).with(Vagrant.config.chef.validation_key_path).returns(true)
54
+ @action.stubs(:env).returns(@env)
55
+ @action.stubs(:validation_key_path).returns("9")
56
+
57
+ File.expects(:file?).with(@action.validation_key_path).returns(true)
55
58
  assert_nothing_raised { @action.prepare }
56
59
  end
57
60
 
58
61
  should "raise an exception if validation_key_path doesn't exist" do
59
- mock_config do |config|
62
+ @env = mock_environment do |config|
60
63
  config.chef.validation_key_path = "7"
61
64
  end
62
65
 
63
- File.expects(:file?).with(Vagrant.config.chef.validation_key_path).returns(false)
66
+ @action.stubs(:env).returns(@env)
67
+ @action.stubs(:validation_key_path).returns("9")
68
+
69
+ File.expects(:file?).with(@action.validation_key_path).returns(false)
64
70
  assert_raises(Vagrant::Actions::ActionException) {
65
71
  @action.prepare
66
72
  }
67
73
  end
68
74
 
69
75
  should "not raise an exception if chef_server_url is set" do
70
- mock_config do |config|
76
+ @env = mock_environment do |config|
71
77
  config.chef.chef_server_url = "7"
72
78
  end
73
79
 
80
+ @action.stubs(:env).returns(@env)
81
+
74
82
  assert_nothing_raised { @action.prepare }
75
83
  end
76
84
 
77
85
  should "raise an exception if chef_server_url is nil" do
78
- mock_config do |config|
86
+ @env = mock_environment do |config|
79
87
  config.chef.chef_server_url = nil
80
88
  end
81
89
 
90
+ @action.stubs(:env).returns(@env)
91
+
82
92
  assert_raises(Vagrant::Actions::ActionException) {
83
93
  @action.prepare
84
94
  }
@@ -88,9 +98,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
88
98
  context "creating the client key folder" do
89
99
  setup do
90
100
  @raw_path = "/foo/bar/baz.pem"
91
- mock_config do |config|
92
- config.chef.client_key_path = @raw_path
93
- end
101
+ @env.config.chef.client_key_path = @raw_path
94
102
 
95
103
  @path = Pathname.new(@raw_path)
96
104
  end
@@ -98,7 +106,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
98
106
  should "create the folder using the dirname of the path" do
99
107
  ssh = mock("ssh")
100
108
  ssh.expects(:exec!).with("sudo mkdir -p #{@path.dirname}").once
101
- Vagrant::SSH.expects(:execute).yields(ssh)
109
+ @env.ssh.expects(:execute).yields(ssh)
102
110
  @action.create_client_key_folder
103
111
  end
104
112
  end
@@ -107,7 +115,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
107
115
  should "upload the validation key to the provisioning path" do
108
116
  @action.expects(:validation_key_path).once.returns("foo")
109
117
  @action.expects(:guest_validation_key_path).once.returns("bar")
110
- Vagrant::SSH.expects(:upload!).with("foo", "bar").once
118
+ @env.ssh.expects(:upload!).with("foo", "bar").once
111
119
  @action.upload_validation_key
112
120
  end
113
121
  end
@@ -115,7 +123,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
115
123
  context "the validation key path" do
116
124
  should "expand the configured key path" do
117
125
  result = mock("result")
118
- File.expects(:expand_path).with(Vagrant.config.chef.validation_key_path, Vagrant::Env.root_path).once.returns(result)
126
+ File.expects(:expand_path).with(@env.config.chef.validation_key_path, @env.root_path).once.returns(result)
119
127
  assert_equal result, @action.validation_key_path
120
128
  end
121
129
  end
@@ -123,7 +131,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
123
131
  context "the guest validation key path" do
124
132
  should "be the provisioning path joined with validation.pem" do
125
133
  result = mock("result")
126
- File.expects(:join).with(Vagrant.config.chef.provisioning_path, "validation.pem").once.returns(result)
134
+ File.expects(:join).with(@env.config.chef.provisioning_path, "validation.pem").once.returns(result)
127
135
  assert_equal result, @action.guest_validation_key_path
128
136
  end
129
137
  end
@@ -133,42 +141,24 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
133
141
  @action.stubs(:guest_validation_key_path).returns("foo")
134
142
  end
135
143
 
136
- should "upload properly generate the configuration file using configuration data" do
137
- expected_config = <<-config
138
- log_level :info
139
- log_location STDOUT
140
- ssl_verify_mode :verify_none
141
- chef_server_url "#{Vagrant.config.chef.chef_server_url}"
142
-
143
- validation_client_name "#{Vagrant.config.chef.validation_client_name}"
144
- validation_key "#{@action.guest_validation_key_path}"
145
- client_key "#{Vagrant.config.chef.client_key_path}"
146
-
147
- file_store_path "/srv/chef/file_store"
148
- file_cache_path "/srv/chef/cache"
149
-
150
- pid_file "/var/run/chef/chef-client.pid"
151
-
152
- Mixlib::Log::Formatter.show_time = true
153
- config
154
-
155
- StringIO.expects(:new).with(expected_config).once
156
- @action.setup_config
157
- end
144
+ should "call setup_config with proper variables" do
145
+ @action.expects(:setup_config).with("chef_server_client", "client.rb", {
146
+ :node_name => @env.config.chef.node_name,
147
+ :chef_server_url => @env.config.chef.chef_server_url,
148
+ :validation_client_name => @env.config.chef.validation_client_name,
149
+ :validation_key => @action.guest_validation_key_path,
150
+ :client_key => @env.config.chef.client_key_path
151
+ })
158
152
 
159
- should "upload this file as client.rb to the provisioning folder" do
160
- StringIO.expects(:new).returns("foo")
161
- File.expects(:join).with(Vagrant.config.chef.provisioning_path, "client.rb").once.returns("bar")
162
- Vagrant::SSH.expects(:upload!).with("foo", "bar").once
163
- @action.setup_config
153
+ @action.setup_server_config
164
154
  end
165
155
  end
166
156
 
167
157
  context "running chef client" do
168
158
  should "cd into the provisioning directory and run chef client" do
169
159
  ssh = mock("ssh")
170
- ssh.expects(:exec!).with("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json").once
171
- Vagrant::SSH.expects(:execute).yields(ssh)
160
+ ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json").once
161
+ @env.ssh.expects(:execute).yields(ssh)
172
162
  @action.run_chef_client
173
163
  end
174
164
  end
@@ -2,12 +2,8 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
2
 
3
3
  class ChefSoloProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
- @action = Vagrant::Provisioners::ChefSolo.new
6
-
7
- Vagrant::SSH.stubs(:execute)
8
- Vagrant::SSH.stubs(:upload!)
9
-
10
- mock_config
5
+ @env = mock_environment
6
+ @action = Vagrant::Provisioners::ChefSolo.new(@env)
11
7
  end
12
8
 
13
9
  context "preparing" do
@@ -15,6 +11,11 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
15
11
  @action.expects(:share_cookbook_folders).once
16
12
  @action.prepare
17
13
  end
14
+
15
+ should "share role folders" do
16
+ @action.expects(:share_role_folders).once
17
+ @action.prepare
18
+ end
18
19
  end
19
20
 
20
21
  context "provisioning" do
@@ -37,96 +38,126 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
37
38
  should "share each cookbook folder" do
38
39
  share_seq = sequence("share_seq")
39
40
  @host_cookbook_paths.each_with_index do |cookbook, i|
40
- Vagrant.config.vm.expects(:share_folder).with("vagrant-chef-solo-#{i}", @action.cookbook_path(i), cookbook).in_sequence(share_seq)
41
+ @env.config.vm.expects(:share_folder).with("v-csc-#{i}", @action.cookbook_path(i), cookbook).in_sequence(share_seq)
41
42
  end
42
43
 
43
44
  @action.share_cookbook_folders
44
45
  end
45
46
  end
46
47
 
47
- context "host cookbooks paths" do
48
- should "expand the path of the cookbooks relative to the environment root path" do
49
- @cookbook = "foo"
50
- @expanded = "bar"
51
- File.expects(:expand_path).with(@cookbook, Vagrant::Env.root_path).returns(@expanded)
48
+ context "sharing role folders" do
49
+ setup do
50
+ @host_role_paths = ["foo", "bar"]
51
+ @action.stubs(:host_role_paths).returns(@host_role_paths)
52
+ end
52
53
 
53
- mock_config do |config|
54
- config.chef.cookbooks_path = @cookbook
54
+ should "share each role folder" do
55
+ share_seq = sequence("share_seq")
56
+ @host_role_paths.each_with_index do |role, i|
57
+ @env.config.vm.expects(:share_folder).with("v-csr-#{i}", @action.role_path(i), role).in_sequence(share_seq)
55
58
  end
56
59
 
57
- assert_equal [@expanded], @action.host_cookbook_paths
60
+ @action.share_role_folders
58
61
  end
62
+ end
59
63
 
64
+ context "host folder paths" do
60
65
  should "return as an array if was originally a string" do
61
- File.stubs(:expand_path).returns("foo")
66
+ folder = "foo"
67
+ File.stubs(:expand_path).returns("bar")
68
+ assert_equal ["bar"], @action.host_folder_paths(folder)
69
+ end
62
70
 
63
- mock_config do |config|
64
- config.chef.cookbooks_path = "foo"
65
- end
71
+ should "return the array of folders if its an array" do
72
+ folders = ["foo", "bar"]
73
+ expand_seq = sequence('expand_seq')
74
+ folders.collect! { |folder| File.expand_path(folder, @env.root_path) }
66
75
 
67
- assert_equal ["foo"], @action.host_cookbook_paths
76
+ assert_equal folders, @action.host_folder_paths(folders)
68
77
  end
78
+ end
69
79
 
70
- should "return the array of cookbooks if its an array" do
71
- cookbooks = ["foo", "bar"]
72
- mock_config do |config|
73
- config.chef.cookbooks_path = cookbooks
74
- end
75
-
76
- expand_seq = sequence('expand_seq')
77
- cookbooks.each do |cookbook|
78
- File.expects(:expand_path).with(cookbook, Vagrant::Env.root_path).returns(cookbook)
79
- end
80
+ context "host cookbooks paths" do
81
+ should "get folders path for configured cookbooks path" do
82
+ result = mock("result")
83
+ @env.config.chef.stubs(:cookbooks_path).returns("foo")
84
+ @action.expects(:host_folder_paths).with(@env.config.chef.cookbooks_path).returns(result)
85
+ assert_equal result, @action.host_cookbook_paths
86
+ end
87
+ end
80
88
 
81
- assert_equal cookbooks, @action.host_cookbook_paths
89
+ context "host roles paths" do
90
+ should "get folders path for configured roles path" do
91
+ result = mock("result")
92
+ @env.config.chef.stubs(:roles_path).returns("foo")
93
+ @action.expects(:host_folder_paths).with(@env.config.chef.roles_path).returns(result)
94
+ assert_equal result, @action.host_role_paths
82
95
  end
83
96
  end
84
97
 
85
- context "cookbooks path" do
86
- should "return a proper path to a single cookbook" do
87
- expected = File.join(Vagrant.config.chef.provisioning_path, "cookbooks-5")
88
- assert_equal expected, @action.cookbook_path(5)
98
+ context "folder path" do
99
+ should "return a proper path to a single folder" do
100
+ expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
101
+ assert_equal expected, @action.folder_path("cookbooks", 5)
89
102
  end
90
103
 
91
- should "return array-representation of cookbook paths if multiple" do
92
- @cookbooks = (0..5).inject([]) do |acc, i|
104
+ should "return array-representation of folder paths if multiple" do
105
+ @folders = (0..5).to_a
106
+ @cookbooks = @folders.inject([]) do |acc, i|
93
107
  acc << @action.cookbook_path(i)
94
108
  end
95
109
 
96
- mock_config do |config|
97
- config.chef.cookbooks_path = @cookbooks
98
- end
110
+ assert_equal @cookbooks.to_json, @action.folders_path(@folders, "cookbooks")
111
+ end
99
112
 
100
- assert_equal @cookbooks.to_json, @action.cookbooks_path
113
+ should "return a single string representation if folder paths is single" do
114
+ @folder = "cookbooks"
115
+ @cookbooks = @action.folder_path(@folder, 0)
116
+
117
+ assert_equal @cookbooks.to_json, @action.folders_path([0], @folder)
118
+ end
119
+ end
120
+
121
+ context "cookbooks path" do
122
+ should "return a proper path to a single cookbook" do
123
+ expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
124
+ assert_equal expected, @action.cookbook_path(5)
101
125
  end
102
126
 
103
- should "return a single string representation if cookbook paths is single" do
104
- @cookbooks = @action.cookbook_path(0)
127
+ should "properly call folders path and return result" do
128
+ result = mock("result")
129
+ @action.stubs(:host_cookbook_paths).returns([])
130
+ @action.expects(:folders_path).with(@action.host_cookbook_paths, "cookbooks").once.returns(result)
131
+ assert_equal result, @action.cookbooks_path
132
+ end
133
+ end
105
134
 
106
- mock_config do |config|
107
- config.chef.cookbooks_path = @cookbooks
108
- end
135
+ context "roles path" do
136
+ should "return a proper path to a single role" do
137
+ expected = File.join(@env.config.chef.provisioning_path, "roles-5")
138
+ assert_equal expected, @action.role_path(5)
139
+ end
109
140
 
110
- assert_equal @cookbooks.to_json, @action.cookbooks_path
141
+ should "properly call folders path and return result" do
142
+ result = mock("result")
143
+ @action.stubs(:host_role_paths).returns([])
144
+ @action.expects(:folders_path).with(@action.host_role_paths, "roles").once.returns(result)
145
+ assert_equal result, @action.roles_path
111
146
  end
112
147
  end
113
148
 
114
149
  context "generating and uploading chef solo configuration file" do
115
- should "upload properly generate the configuration file using configuration data" do
116
- expected_config = <<-config
117
- file_cache_path "#{Vagrant.config.chef.provisioning_path}"
118
- cookbook_path #{@action.cookbooks_path}
119
- config
120
-
121
- StringIO.expects(:new).with(expected_config).once
122
- @action.setup_solo_config
150
+ setup do
151
+ @env.ssh.stubs(:upload!)
123
152
  end
124
153
 
125
- should "upload this file as solo.rb to the provisioning folder" do
126
- @action.expects(:cookbooks_path).returns("cookbooks")
127
- StringIO.expects(:new).returns("foo")
128
- File.expects(:join).with(Vagrant.config.chef.provisioning_path, "solo.rb").once.returns("bar")
129
- Vagrant::SSH.expects(:upload!).with("foo", "bar").once
154
+ should "call setup_config with proper variables" do
155
+ @action.expects(:setup_config).with("chef_solo_solo", "solo.rb", {
156
+ :provisioning_path => @env.config.chef.provisioning_path,
157
+ :cookbooks_path => @action.cookbooks_path,
158
+ :roles_path => @action.roles_path
159
+ })
160
+
130
161
  @action.setup_solo_config
131
162
  end
132
163
  end
@@ -134,8 +165,8 @@ config
134
165
  context "running chef solo" do
135
166
  should "cd into the provisioning directory and run chef solo" do
136
167
  ssh = mock("ssh")
137
- ssh.expects(:exec!).with("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json").once
138
- Vagrant::SSH.expects(:execute).yields(ssh)
168
+ ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json").once
169
+ @env.ssh.expects(:execute).yields(ssh)
139
170
  @action.run_chef_solo
140
171
  end
141
172
  end
@@ -2,12 +2,8 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
2
 
3
3
  class ChefProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
- @action = Vagrant::Provisioners::Chef.new
6
-
7
- Vagrant::SSH.stubs(:execute)
8
- Vagrant::SSH.stubs(:upload!)
9
-
10
- mock_config
5
+ @env = mock_environment
6
+ @action = Vagrant::Provisioners::Chef.new(@env)
11
7
  end
12
8
 
13
9
  context "preparing" do
@@ -69,16 +65,66 @@ class ChefProvisionerTest < Test::Unit::TestCase
69
65
  should "create and chown the folder to the ssh user" do
70
66
  ssh_seq = sequence("ssh_seq")
71
67
  ssh = mock("ssh")
72
- ssh.expects(:exec!).with("sudo mkdir -p #{Vagrant.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
73
- ssh.expects(:exec!).with("sudo chown #{Vagrant.config.ssh.username} #{Vagrant.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
74
- Vagrant::SSH.expects(:execute).yields(ssh)
68
+ ssh.expects(:exec!).with("sudo mkdir -p #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
69
+ ssh.expects(:exec!).with("sudo chown #{@env.config.ssh.username} #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
70
+ @env.ssh.expects(:execute).yields(ssh)
75
71
  @action.chown_provisioning_folder
76
72
  end
77
73
  end
78
74
 
75
+ context "generating and uploading chef configuration file" do
76
+ setup do
77
+ @env.ssh.stubs(:upload!)
78
+
79
+ @template = "template"
80
+ @filename = "foo.rb"
81
+
82
+ Vagrant::Util::TemplateRenderer.stubs(:render).returns("foo")
83
+ end
84
+
85
+ should "render and upload file" do
86
+ template_data = mock("data")
87
+ string_io = mock("string_io")
88
+ Vagrant::Util::TemplateRenderer.expects(:render).with(@template, anything).returns(template_data)
89
+ StringIO.expects(:new).with(template_data).returns(string_io)
90
+ File.expects(:join).with(@env.config.chef.provisioning_path, @filename).once.returns("bar")
91
+ @env.ssh.expects(:upload!).with(string_io, "bar")
92
+
93
+ @action.setup_config(@template, @filename, {})
94
+ end
95
+
96
+ should "provide log level by default" do
97
+ Vagrant::Util::TemplateRenderer.expects(:render).returns("foo").with() do |template, vars|
98
+ assert vars.has_key?(:log_level)
99
+ assert_equal @env.config.chef.log_level.to_sym, vars[:log_level]
100
+ true
101
+ end
102
+
103
+ @action.setup_config(@template, @filename, {})
104
+ end
105
+
106
+ should "allow custom template variables" do
107
+ custom = {
108
+ :foo => "bar",
109
+ :int => 7
110
+ }
111
+
112
+ Vagrant::Util::TemplateRenderer.expects(:render).returns("foo").with() do |template, vars|
113
+ custom.each do |key, value|
114
+ assert vars.has_key?(key)
115
+ assert_equal value, vars[key]
116
+ end
117
+
118
+ true
119
+ end
120
+
121
+ @action.setup_config(@template, @filename, custom)
122
+ end
123
+ end
124
+
79
125
  context "generating and uploading json" do
80
126
  def assert_json
81
- Vagrant::SSH.expects(:upload!).with do |json, path|
127
+ @env.ssh.expects(:upload!).with do |json, path|
82
128
  data = JSON.parse(json.read)
83
129
  yield data
84
130
  true
@@ -88,7 +134,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
88
134
  end
89
135
 
90
136
  should "merge in the extra json specified in the config" do
91
- Vagrant.config.chef.json = { :foo => "BAR" }
137
+ @env.config.chef.json = { :foo => "BAR" }
92
138
  assert_json do |data|
93
139
  assert_equal "BAR", data["foo"]
94
140
  end
@@ -96,20 +142,20 @@ class ChefProvisionerTest < Test::Unit::TestCase
96
142
 
97
143
  should "add the directory as a special case to the JSON" do
98
144
  assert_json do |data|
99
- assert_equal Vagrant.config.vm.project_directory, data["vagrant"]["directory"]
145
+ assert_equal @env.config.vm.project_directory, data["vagrant"]["directory"]
100
146
  end
101
147
  end
102
148
 
103
149
  should "add the config to the JSON" do
104
150
  assert_json do |data|
105
- assert_equal Vagrant.config.vm.project_directory, data["vagrant"]["config"]["vm"]["project_directory"]
151
+ assert_equal @env.config.vm.project_directory, data["vagrant"]["config"]["vm"]["project_directory"]
106
152
  end
107
153
  end
108
154
 
109
155
  should "upload a StringIO to dna.json" do
110
156
  StringIO.expects(:new).with(anything).returns("bar")
111
- File.expects(:join).with(Vagrant.config.chef.provisioning_path, "dna.json").once.returns("baz")
112
- Vagrant::SSH.expects(:upload!).with("bar", "baz").once
157
+ File.expects(:join).with(@env.config.chef.provisioning_path, "dna.json").once.returns("baz")
158
+ @env.ssh.expects(:upload!).with("bar", "baz").once
113
159
  @action.setup_json
114
160
  end
115
161
  end