Chef-solo configuration script is generated and uploaded.

This commit is contained in:
Mitchell Hashimoto 2010-02-09 18:29:52 -08:00
parent 8abb4e1d6e
commit 4a6d6074d2
2 changed files with 43 additions and 4 deletions

View File

@ -7,17 +7,17 @@ module Hobo
# Share the cookbook folder. We'll use the provisioning path exclusively for
# chef stuff.
cookbooks_path = File.join(Hobo.config.chef.provisioning_path, "cookbooks")
@vm.share_folder("hobo-provisioning", File.expand_path(Hobo.config.chef.cookbooks_path, Env.root_path), cookbooks_path)
end
def run
chown_provisioning_folder
setup_json
setup_solo_config
end
def chown_provisioning_folder
logger.info "Setting permissions on deployment folder..."
logger.info "Setting permissions on provisioning folder..."
SSH.execute do |ssh|
ssh.exec!("sudo chown #{Hobo.config.ssh.username} #{Hobo.config.chef.provisioning_path}")
end
@ -27,5 +27,19 @@ module Hobo
logger.info "Generating JSON and uploading..."
SSH.upload!(StringIO.new(Hobo.config.chef.json.to_json), File.join(Hobo.config.chef.provisioning_path, "dna.json"))
end
def setup_solo_config
solo_file = <<-solo
file_cache_path "#{Hobo.config.chef.provisioning_path}"
cookbook_path "#{cookbooks_path}"
solo
logger.info "Uploading chef-solo configuration script..."
SSH.upload!(StringIO.new(solo_file), File.join(Hobo.config.chef.provisioning_path, "solo.rb"))
end
def cookbooks_path
File.join(Hobo.config.chef.provisioning_path, "cookbooks")
end
end
end

View File

@ -13,11 +13,16 @@ class ProvisioningTest < Test::Unit::TestCase
context "initializing" do
should "setup shared folder on VM for the cookbooks" do
File.expects(:expand_path).with(Hobo.config.chef.cookbooks_path, Hobo::Env.root_path).returns("foo")
cookbooks_path = File.join(Hobo.config.chef.provisioning_path, "cookbooks")
Hobo::Provisioning.any_instance.expects(:cookbooks_path).returns("bar")
vm = mock("vm")
vm.expects(:share_folder).with("hobo-provisioning", "foo", cookbooks_path)
vm.expects(:share_folder).with("hobo-provisioning", "foo", "bar")
Hobo::Provisioning.new(vm)
end
should "return the proper cookbook path" do
cookbooks_path = File.join(Hobo.config.chef.provisioning_path, "cookbooks")
assert_equal cookbooks_path, @prov.cookbooks_path
end
end
context "permissions on provisioning folder" do
@ -43,4 +48,24 @@ class ProvisioningTest < Test::Unit::TestCase
@prov.setup_json
end
end
context "generating and uploading chef solo configuration file" do
should "upload properly generate the configuration file using configuration data" do
expected_config = <<-config
file_cache_path "#{Hobo.config.chef.provisioning_path}"
cookbook_path "#{@prov.cookbooks_path}"
config
StringIO.expects(:new).with(expected_config).once
@prov.setup_solo_config
end
should "upload this file as solo.rb to the provisioning folder" do
@prov.expects(:cookbooks_path).returns("cookbooks")
StringIO.expects(:new).returns("foo")
File.expects(:join).with(Hobo.config.chef.provisioning_path, "solo.rb").once.returns("bar")
Hobo::SSH.expects(:upload!).with("foo", "bar").once
@prov.setup_solo_config
end
end
end