`config.chef.recipe_url` to download cookbooks via chef solo [closes GH-121]

This commit is contained in:
Mitchell Hashimoto 2010-07-28 21:34:28 -07:00
parent d68ac2e7e8
commit d17765c3dd
6 changed files with 34 additions and 12 deletions

View File

@ -1,5 +1,8 @@
## 0.5.1 (unreleased) ## 0.5.1 (unreleased)
- Added `config.chef.recipe_url` which allows you to specify a URL to
a gzipped tar file for chef solo to download cookbooks. See the
[chef-solo docs](http://wiki.opscode.com/display/chef/Chef+Solo#ChefSolo-RunningfromaURL) for more information.
- Added `vagrant box repackage` which repackages boxes which have - Added `vagrant box repackage` which repackages boxes which have
been added. This is useful in case you want to redistribute a base been added. This is useful in case you want to redistribute a base
box you have but may have lost the actual "box" file. box you have but may have lost the actual "box" file.

View File

@ -16,6 +16,7 @@ module Vagrant
# Chef solo specific config # Chef solo specific config
attr_accessor :cookbooks_path attr_accessor :cookbooks_path
attr_accessor :roles_path attr_accessor :roles_path
attr_accessor :recipe_url
# Shared config # Shared config
attr_accessor :provisioning_path attr_accessor :provisioning_path

View File

@ -32,7 +32,8 @@ module Vagrant
:node_name => env.config.chef.node_name, :node_name => env.config.chef.node_name,
:provisioning_path => env.config.chef.provisioning_path, :provisioning_path => env.config.chef.provisioning_path,
:cookbooks_path => cookbooks_path, :cookbooks_path => cookbooks_path,
:roles_path => roles_path :recipe_url => env.config.chef.recipe_url,
:roles_path => roles_path,
}) })
end end
@ -65,7 +66,7 @@ module Vagrant
# We're lucky that ruby's string and array syntax for strings is the # We're lucky that ruby's string and array syntax for strings is the
# same as JSON, so we can just convert to JSON here and use that # same as JSON, so we can just convert to JSON here and use that
result = result[0].to_s if result.length == 1 result = result[0].to_s if result.length == 1
result.to_json result
end end
def host_cookbook_paths def host_cookbook_paths
@ -85,11 +86,14 @@ module Vagrant
end end
def cookbooks_path def cookbooks_path
folders_path(host_cookbook_paths, "cookbooks") result = folders_path(host_cookbook_paths, "cookbooks")
result = [result, File.join(env.config.chef.provisioning_path, "cookbooks")].flatten if env.config.chef.recipe_url
result.to_json
end end
def roles_path def roles_path
folders_path(host_role_paths, "roles") folders_path(host_role_paths, "roles").to_json
end end
end end
end end

View File

@ -3,3 +3,7 @@ file_cache_path "<%= provisioning_path %>"
cookbook_path <%= cookbooks_path %> cookbook_path <%= cookbooks_path %>
role_path <%= roles_path %> role_path <%= roles_path %>
log_level <%= log_level.inspect %> log_level <%= log_level.inspect %>
<% if recipe_url %>
recipe_url "<%= recipe_url %>"
<% end %>

View File

@ -53,6 +53,7 @@ class Test::Unit::TestCase
config.chef.validation_key_path = "validation.pem" config.chef.validation_key_path = "validation.pem"
config.chef.client_key_path = "/zoo/foo/bar.pem" config.chef.client_key_path = "/zoo/foo/bar.pem"
config.chef.node_name = "baz" config.chef.node_name = "baz"
config.chef.recipe_url = nil
config.chef.cookbooks_path = "cookbooks" config.chef.cookbooks_path = "cookbooks"
config.chef.provisioning_path = "/tmp/vagrant-chef" config.chef.provisioning_path = "/tmp/vagrant-chef"
config.chef.log_level = :info config.chef.log_level = :info

View File

@ -111,14 +111,14 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
acc << @action.cookbook_path(i) acc << @action.cookbook_path(i)
end end
assert_equal @cookbooks.to_json, @action.folders_path(@folders, "cookbooks") assert_equal @cookbooks, @action.folders_path(@folders, "cookbooks")
end end
should "return a single string representation if folder paths is single" do should "return a single string representation if folder paths is single" do
@folder = "cookbooks" @folder = "cookbooks"
@cookbooks = @action.folder_path(@folder, 0) @cookbooks = @action.folder_path(@folder, 0)
assert_equal @cookbooks.to_json, @action.folders_path([0], @folder) assert_equal @cookbooks, @action.folders_path([0], @folder)
end end
end end
@ -129,10 +129,17 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
end end
should "properly call folders path and return result" do should "properly call folders path and return result" do
result = mock("result") result = [:a, :b, :c]
@action.stubs(:host_cookbook_paths).returns([])
@action.expects(:folders_path).with(@action.host_cookbook_paths, "cookbooks").once.returns(result) @action.expects(:folders_path).with(@action.host_cookbook_paths, "cookbooks").once.returns(result)
assert_equal result, @action.cookbooks_path assert_equal result.to_json, @action.cookbooks_path
end
should "append a bare cookbooks path to the cookbooks path for recipe URL" do
@env.config.chef.recipe_url = "foo"
@action.stubs(:folders_path).returns([])
result = @action.cookbooks_path
assert result
assert result =~ /\/cookbooks"\]$/
end end
end end
@ -143,16 +150,17 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
end end
should "properly call folders path and return result" do should "properly call folders path and return result" do
result = mock("result") result = [:a, :b, :c]
@action.stubs(:host_role_paths).returns([])
@action.expects(:folders_path).with(@action.host_role_paths, "roles").once.returns(result) @action.expects(:folders_path).with(@action.host_role_paths, "roles").once.returns(result)
assert_equal result, @action.roles_path assert_equal result.to_json, @action.roles_path
end end
end end
context "generating and uploading chef solo configuration file" do context "generating and uploading chef solo configuration file" do
setup do setup do
@vm.ssh.stubs(:upload!) @vm.ssh.stubs(:upload!)
@env.config.chef.recipe_url = "foo/bar/baz"
end end
should "call setup_config with proper variables" do should "call setup_config with proper variables" do
@ -160,6 +168,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
:node_name => @env.config.chef.node_name, :node_name => @env.config.chef.node_name,
:provisioning_path => @env.config.chef.provisioning_path, :provisioning_path => @env.config.chef.provisioning_path,
:cookbooks_path => @action.cookbooks_path, :cookbooks_path => @action.cookbooks_path,
:recipe_url => @env.config.chef.recipe_url,
:roles_path => @action.roles_path :roles_path => @action.roles_path
}) })