diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f83755f0..b8548c594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 0.5.1 (unreleased) + - Allow specifying cookbook paths which exist only on the VM in `config.chef.cookbooks_path`. + This is used for specifying cookbook paths when `config.chef.recipe_url` is used. [GH-130] + See updated chef solo documentation for more information on this. - No longer show "Disabling host only networks..." if no host only networks are destroyed. Quiets `destroy`, `halt`, etc output a bit. - Updated getting started guide to be more up to date and generic. [GH-125] diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index 962d96f85..a38c94990 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -50,17 +50,37 @@ module Vagrant end def host_folder_paths(paths) - [paths].flatten.collect { |path| File.expand_path(path, env.root_path) } + # Convert single cookbook paths such as "cookbooks" or [:vm, "cookbooks"] + # into a proper array representation. + paths = [paths] if paths.is_a?(String) || paths.first.is_a?(Symbol) + + paths.inject([]) do |acc, path| + path = [:host, path] if !path.is_a?(Array) + type, path = path + + acc << File.expand_path(path, env.root_path) if type == :host + acc + end end - def folder_path(folder, i) - File.join(env.config.chef.provisioning_path, "#{folder}-#{i}") + def folder_path(*args) + File.expand_path(args.join("-"), env.config.chef.provisioning_path) end def folders_path(folders, folder) + # Convert single cookbook paths such as "cookbooks" or [:vm, "cookbooks"] + # into a proper array representation. + folders = [folders] if folders.is_a?(String) || folders.first.is_a?(Symbol) + + # Convert each path to the proper absolute path depending on if the path + # is a host path or a VM path result = [] - folders.each_with_index do |host_path, i| - result << folder_path(folder, i) + folders.each_with_index do |path, i| + path = [:host, path] if !path.is_a?(Array) + type, path = path + + result << folder_path(folder, i) if type == :host + result << folder_path(path) if type == :vm end # We're lucky that ruby's string and array syntax for strings is the @@ -86,14 +106,14 @@ module Vagrant end def cookbooks_path - result = folders_path(host_cookbook_paths, "cookbooks") + result = folders_path(env.config.chef.cookbooks_path, "cookbooks") result = [result, File.join(env.config.chef.provisioning_path, "cookbooks")].flatten if env.config.chef.recipe_url result.to_json end def roles_path - folders_path(host_role_paths, "roles").to_json + folders_path(env.config.chef.roles_path, "roles").to_json end end end diff --git a/test/vagrant/provisioners/chef_solo_test.rb b/test/vagrant/provisioners/chef_solo_test.rb index 71467a84a..f74aa938f 100644 --- a/test/vagrant/provisioners/chef_solo_test.rb +++ b/test/vagrant/provisioners/chef_solo_test.rb @@ -66,6 +66,10 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase end context "host folder paths" do + should "ignore VM paths" do + assert @action.host_folder_paths([:vm, "foo"]).empty? + end + should "return as an array if was originally a string" do folder = "foo" File.stubs(:expand_path).returns("bar") @@ -120,6 +124,11 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase assert_equal @cookbooks, @action.folders_path([0], @folder) end + + should "properly format VM folder paths" do + @env.config.chef.provisioning_path = "/foo" + assert_equal "/foo/bar", @action.folders_path([:vm, "bar"], nil) + end end context "cookbooks path" do @@ -130,7 +139,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase should "properly call folders path and return result" do result = [:a, :b, :c] - @action.expects(:folders_path).with(@action.host_cookbook_paths, "cookbooks").once.returns(result) + @action.expects(:folders_path).with(@env.config.chef.cookbooks_path, "cookbooks").once.returns(result) assert_equal result.to_json, @action.cookbooks_path end @@ -151,7 +160,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase should "properly call folders path and return result" do result = [:a, :b, :c] - @action.expects(:folders_path).with(@action.host_role_paths, "roles").once.returns(result) + @action.expects(:folders_path).with(@env.config.chef.roles_path, "roles").once.returns(result) assert_equal result.to_json, @action.roles_path end end