Chef server provisioner works. Added the auto-creation of the client key config.

This commit is contained in:
Mitchell Hashimoto 2010-03-10 22:42:42 -08:00
parent a4428cd201
commit 9384917b81
4 changed files with 50 additions and 4 deletions

View File

@ -10,6 +10,7 @@ module Vagrant
attr_accessor :chef_server_url
attr_accessor :validation_key_path
attr_accessor :validation_client_name
attr_accessor :client_key_path
# Chef solo specific config
attr_accessor :cookbooks_path
@ -20,6 +21,8 @@ module Vagrant
def initialize
@validation_client_name = "chef-validator"
@client_key_path = "/etc/chef/client.pem"
@cookbooks_path = "cookbooks"
@provisioning_path = "/tmp/vagrant-chef"
@json = {

View File

@ -23,15 +23,25 @@ msg
def provision!
chown_provisioning_folder
create_client_key_folder
upload_validation_key
setup_json
setup_config
run_chef_client
end
def create_client_key_folder
logger.info "Creating folder to hold client key..."
path = Pathname.new(Vagrant.config.chef.client_key_path)
SSH.execute do |ssh|
ssh.exec!("sudo mkdir -p #{path.dirname}")
end
end
def upload_validation_key
logger.info "Uploading chef client validation key..."
SSH.upload!(Vagrant.config.chef.validation_key_path, guest_validation_key_path)
SSH.upload!(validation_key_path, guest_validation_key_path)
end
def setup_config
@ -43,7 +53,7 @@ chef_server_url "#{Vagrant.config.chef.chef_server_url}"
validation_client_name "#{Vagrant.config.chef.validation_client_name}"
validation_key "#{guest_validation_key_path}"
client_key "/etc/chef/client.pem"
client_key "#{Vagrant.config.chef.client_key_path}"
file_store_path "/srv/chef/file_store"
file_cache_path "/srv/chef/cache"
@ -68,6 +78,10 @@ solo
end
end
def validation_key_path
File.expand_path(Vagrant.config.chef.validation_key_path, Env.root_path)
end
def guest_validation_key_path
File.join(Vagrant.config.chef.provisioning_path, "validation.pem")
end

View File

@ -45,6 +45,7 @@ class Test::Unit::TestCase
# Chef
config.chef.chef_server_url = "http://localhost:4000"
config.chef.validation_key_path = "validation.pem"
config.chef.client_key_path = "/zoo/foo/bar.pem"
config.chef.cookbooks_path = "cookbooks"
config.chef.provisioning_path = "/tmp/hobo-chef"
config.chef.json = {

View File

@ -14,6 +14,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
should "run the proper sequence of methods in order" do
prov_seq = 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)
@action.expects(:setup_json).once.in_sequence(prov_seq)
@action.expects(:setup_config).once.in_sequence(prov_seq)
@ -60,14 +61,41 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
end
end
context "creating the client key folder" do
setup do
@raw_path = "/foo/bar/baz.pem"
mock_config do |config|
config.chef.client_key_path = @raw_path
end
@path = Pathname.new(@raw_path)
end
should "create the folder using the dirname of the path" do
ssh = mock("ssh")
ssh.expects(:exec!).with("sudo mkdir -p #{@path.dirname}").once
Vagrant::SSH.expects(:execute).yields(ssh)
@action.create_client_key_folder
end
end
context "uploading the validation key" do
should "upload the validation key to the provisioning path" do
@action.expects(:validation_key_path).once.returns("foo")
@action.expects(:guest_validation_key_path).once.returns("bar")
Vagrant::SSH.expects(:upload!).with(Vagrant.config.chef.validation_key_path, "bar").once
Vagrant::SSH.expects(:upload!).with("foo", "bar").once
@action.upload_validation_key
end
end
context "the validation key path" do
should "expand the configured key path" do
result = mock("result")
File.expects(:expand_path).with(Vagrant.config.chef.validation_key_path, Vagrant::Env.root_path).once.returns(result)
assert_equal result, @action.validation_key_path
end
end
context "the guest validation key path" do
should "be the provisioning path joined with validation.pem" do
result = mock("result")
@ -90,7 +118,7 @@ chef_server_url "#{Vagrant.config.chef.chef_server_url}"
validation_client_name "#{Vagrant.config.chef.validation_client_name}"
validation_key "#{@action.guest_validation_key_path}"
client_key "/etc/chef/client.pem"
client_key "#{Vagrant.config.chef.client_key_path}"
file_store_path "/srv/chef/file_store"
file_cache_path "/srv/chef/cache"