summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2013-11-26 07:43:57 -0800
committerBryan McLellan <btm@opscode.com>2013-11-26 07:43:57 -0800
commitd156b4907efdd5641d662c8ad881244ed0c9edc2 (patch)
treeb0808a3e961a27873f16a50b4886da5b3c2bb852
parent57ebf9cbbb80573bde2cb8598733fade07190578 (diff)
parent7543633aad455c7d9c409ecc93b46357fc1a87bb (diff)
downloadchef-d156b4907efdd5641d662c8ad881244ed0c9edc2.tar.gz
Merge branch 'CHEF-4421' into contributions
-rw-r--r--lib/chef/client.rb19
-rw-r--r--spec/unit/client_spec.rb14
2 files changed, 22 insertions, 11 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 30b714cded..6a39395bb6 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -543,8 +543,8 @@ class Chef
end
end
- def directory_not_empty?(path)
- File.exists?(path) && (Dir.entries(path).size > 2)
+ def empty_directory?(path)
+ !File.exists?(path) || (Dir.entries(path).size <= 2)
end
def is_last_element?(index, object)
@@ -556,15 +556,12 @@ class Chef
# Check for cookbooks in the path given
# Chef::Config[:cookbook_path] can be a string or an array
# if it's an array, go through it and check each one, raise error at the last one if no files are found
- Chef::Log.debug "Loading from cookbook_path: #{Array(Chef::Config[:cookbook_path]).map { |path| File.expand_path(path) }.join(', ')}"
- Array(Chef::Config[:cookbook_path]).each_with_index do |cookbook_path, index|
- if directory_not_empty?(cookbook_path)
- break
- else
- msg = "No cookbook found in #{Chef::Config[:cookbook_path].inspect}, make sure cookbook_path is set correctly."
- Chef::Log.fatal(msg)
- raise Chef::Exceptions::CookbookNotFound, msg if is_last_element?(index, Chef::Config[:cookbook_path])
- end
+ cookbook_paths = Array(Chef::Config[:cookbook_path])
+ Chef::Log.debug "Loading from cookbook_path: #{cookbook_paths.map { |path| File.expand_path(path) }.join(', ')}"
+ if cookbook_paths.all? {|path| empty_directory?(path) }
+ msg = "None of the cookbook paths set in Chef::Config[:cookbook_path], #{cookbook_paths.inspect}, contain any cookbooks"
+ Chef::Log.fatal(msg)
+ raise Chef::Exceptions::CookbookNotFound, msg
end
else
Chef::Log.warn("Node #{node_name} has an empty run list.") if run_context.node.run_list.empty?
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index 11c887d734..eb705e0386 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -447,6 +447,20 @@ shared_examples_for Chef::Client do
end
end
+ describe "assert_cookbook_path_not_empty" do
+ before do
+ Chef::Config[:solo] = true
+ Chef::Config[:cookbook_path] = ["/path/to/invalid/cookbook_path"]
+ end
+ context "when any directory of cookbook_path contains no cookbook" do
+ it "raises CookbookNotFound error" do
+ expect do
+ @client.send(:assert_cookbook_path_not_empty, nil)
+ end.to raise_error(Chef::Exceptions::CookbookNotFound, 'None of the cookbook paths set in Chef::Config[:cookbook_path], ["/path/to/invalid/cookbook_path"], contain any cookbooks')
+ end
+ end
+ end
+
end
describe Chef::Client do