Refactor and tests for GH-342 (chef enhancements)

This commit is contained in:
Mitchell Hashimoto 2011-05-16 12:49:05 -07:00
parent ab2fff4b5b
commit c117dba4ab
5 changed files with 27 additions and 20 deletions

View File

@ -5,6 +5,8 @@
- Get rid of RubyGems deprecations introduced with RubyGems 1.8.x - Get rid of RubyGems deprecations introduced with RubyGems 1.8.x
- Search in pre-release gems for plugins as well as release gems. - Search in pre-release gems for plugins as well as release gems.
- Support for Chef-solo `data_bags_path` [GH-362] - Support for Chef-solo `data_bags_path` [GH-362]
- Can specify path to Chef binary using `binary_path` [GH-342]
- Can specify additional environment data for Chef using `binary_env` [GH-342]
## 0.7.4 (May 12, 2011) ## 0.7.4 (May 12, 2011)

View File

@ -16,6 +16,13 @@ module Vagrant
end end
end end
# Returns the path to the Chef binary, taking into account the
# `binary_path` configuration option.
def chef_binary_path(binary)
return binary if !config.binary_path
return File.join(config.binary_path, binary)
end
def chown_provisioning_folder def chown_provisioning_folder
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
ssh.sudo!("mkdir -p #{config.provisioning_path}") ssh.sudo!("mkdir -p #{config.provisioning_path}")

View File

@ -41,7 +41,7 @@ module Vagrant
end end
def provision! def provision!
verify_binary(chef_client_binary) verify_binary(chef_binary_path("chef-client"))
chown_provisioning_folder chown_provisioning_folder
create_client_key_folder create_client_key_folder
upload_validation_key upload_validation_key
@ -78,8 +78,9 @@ module Vagrant
end end
def run_chef_client def run_chef_client
command_env = config.binary_env ? "#{config.binary_env} " : ""
commands = ["cd #{config.provisioning_path}", commands = ["cd #{config.provisioning_path}",
"#{config.binary_env} #{chef_client_binary} -c client.rb -j dna.json"] "#{command_env}#{chef_binary_path("chef-client")} -c client.rb -j dna.json"]
env.ui.info I18n.t("vagrant.provisioners.chef.running_client") env.ui.info I18n.t("vagrant.provisioners.chef.running_client")
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
@ -93,14 +94,6 @@ module Vagrant
end end
end end
def chef_client_binary
if config.binary_path.nil? || config.binary_path.empty?
"chef-client"
else
File.join(config.binary_path, "chef-client")
end
end
def validation_key_path def validation_key_path
File.expand_path(config.validation_key_path, env.root_path) File.expand_path(config.validation_key_path, env.root_path)
end end

View File

@ -33,7 +33,7 @@ module Vagrant
end end
def provision! def provision!
verify_binary(chef_solo_binary) verify_binary(chef_binary_path("chef-solo"))
chown_provisioning_folder chown_provisioning_folder
setup_json setup_json
setup_solo_config setup_solo_config
@ -70,7 +70,8 @@ module Vagrant
end end
def run_chef_solo def run_chef_solo
commands = ["cd #{config.provisioning_path}", "#{config.binary_env} #{chef_solo_binary} -c solo.rb -j dna.json"] command_env = config.binary_env ? "#{config.binary_env} " : ""
commands = ["cd #{config.provisioning_path}", "#{command_env}#{chef_binary_path("chef-solo")} -c solo.rb -j dna.json"]
env.ui.info I18n.t("vagrant.provisioners.chef.running_solo") env.ui.info I18n.t("vagrant.provisioners.chef.running_solo")
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
@ -84,14 +85,6 @@ module Vagrant
end end
end end
def chef_solo_binary
if config.binary_path.nil? || config.binary_path.empty?
"chef-solo"
else
File.join(config.binary_path, "chef-solo")
end
end
def host_folder_paths(paths) def host_folder_paths(paths)
# Convert single cookbook paths such as "cookbooks" or [:vm, "cookbooks"] # Convert single cookbook paths such as "cookbooks" or [:vm, "cookbooks"]
# into a proper array representation. # into a proper array representation.

View File

@ -78,6 +78,18 @@ class ChefProvisionerTest < Test::Unit::TestCase
end end
end end
context "chef binary path" do
should "return just the binary if no binary path is set" do
@config.binary_path = nil
assert_equal "foo", @action.chef_binary_path("foo")
end
should "return the joined binary path and binary if set" do
@config.binary_path = "/foo"
assert_equal File.join(@config.binary_path, "bar"), @action.chef_binary_path("bar")
end
end
context "permissions on provisioning folder" do context "permissions on provisioning folder" do
should "create and chown the folder to the ssh user" do should "create and chown the folder to the ssh user" do
ssh_seq = sequence("ssh_seq") ssh_seq = sequence("ssh_seq")