Verify chef binaries exist prior to running chef provisioning [closes GH-89]
This commit is contained in:
parent
4c8713ecd4
commit
503a9acf89
|
@ -75,6 +75,14 @@ module Vagrant
|
|||
raise Actions::ActionException.new(:chef_base_invalid_provisioner)
|
||||
end
|
||||
|
||||
def verify_binary(binary)
|
||||
vm.ssh.execute do |ssh|
|
||||
# Checks for the existence of chef binary and error if it
|
||||
# doesn't exist.
|
||||
ssh.exec!("which #{binary}", :error_key => :chef_not_detected, :error_data => {:binary => binary})
|
||||
end
|
||||
end
|
||||
|
||||
def chown_provisioning_folder
|
||||
logger.info "Setting permissions on chef provisioning folder..."
|
||||
vm.ssh.execute do |ssh|
|
||||
|
|
|
@ -16,6 +16,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
def provision!
|
||||
verify_binary("chef-client")
|
||||
chown_provisioning_folder
|
||||
create_client_key_folder
|
||||
upload_validation_key
|
||||
|
|
|
@ -8,6 +8,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
def provision!
|
||||
verify_binary("chef-solo")
|
||||
chown_provisioning_folder
|
||||
setup_json
|
||||
setup_solo_config
|
||||
|
|
|
@ -78,6 +78,11 @@
|
|||
The validation key set for `config.chef.validation_key_path` does not exist! This
|
||||
file needs to exist so it can be uploaded to the virtual machine. It is
|
||||
currently set to "<%= Vagrant.config.chef.validation_key_path %>"
|
||||
:chef_not_detected: |-
|
||||
The `<%= binary %>` binary appears to not be in the PATH of the guest. This
|
||||
could be because the PATH is not properly setup or perhaps chef is not
|
||||
installed on this guest. Chef provisioning can not continue without
|
||||
chef properly installed.
|
||||
:command_box_invalid: |-
|
||||
Please specify a valid action to take on the boxes, either
|
||||
`add` or `remove`. Examples:
|
||||
|
|
|
@ -10,6 +10,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
context "provisioning" do
|
||||
should "run the proper sequence of methods in order" do
|
||||
prov_seq = sequence("prov_seq")
|
||||
@action.expects(:verify_binary).with("chef-client").once.in_sequence(prov_seq)
|
||||
@action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
|
||||
@action.expects(:create_client_key_folder).once.in_sequence(prov_seq)
|
||||
@action.expects(:upload_validation_key).once.in_sequence(prov_seq)
|
||||
|
|
|
@ -22,6 +22,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
|||
context "provisioning" do
|
||||
should "run the proper sequence of methods in order" do
|
||||
prov_seq = sequence("prov_seq")
|
||||
@action.expects(:verify_binary).with("chef-solo").once.in_sequence(prov_seq)
|
||||
@action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
|
||||
@action.expects(:setup_json).once.in_sequence(prov_seq)
|
||||
@action.expects(:setup_solo_config).once.in_sequence(prov_seq)
|
||||
|
@ -29,7 +30,6 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
|||
@action.provision!
|
||||
end
|
||||
end
|
||||
|
||||
context "sharing cookbook folders" do
|
||||
setup do
|
||||
@host_cookbook_paths = ["foo", "bar"]
|
||||
|
|
|
@ -62,6 +62,18 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "verifying binary" do
|
||||
setup do
|
||||
@ssh = mock("ssh")
|
||||
@vm.ssh.stubs(:execute).yields(@ssh)
|
||||
end
|
||||
|
||||
should "verify binary exists" do
|
||||
binary = "foo"
|
||||
@ssh.expects(:exec!).with("which #{binary}", :error_key => :chef_not_detected, :error_data => { :binary => binary }).once
|
||||
@action.verify_binary(binary)
|
||||
end
|
||||
end
|
||||
context "permissions on provisioning folder" do
|
||||
should "create and chown the folder to the ssh user" do
|
||||
ssh_seq = sequence("ssh_seq")
|
||||
|
|
Loading…
Reference in New Issue