summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyota Arai <ryota.arai@gmail.com>2013-10-30 23:39:09 +0900
committerBryan McLellan <btm@opscode.com>2013-11-26 07:31:26 -0800
commit0d04ea2672e0ec5d492e5640fe3fd94a64e47554 (patch)
tree15dde784f0f58ea3f364cbcc90d36fd52eddafef
parent711a8baebd6ccbdac54a30aa6fe8d7b0493e84b7 (diff)
downloadchef-0d04ea2672e0ec5d492e5640fe3fd94a64e47554.tar.gz
Raise CookbookNotFound error if any directory of cookbook_path contains no cookbook.
-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 456c6e9505..38b771147e 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -557,17 +557,14 @@ class Chef
# 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 #{cookbook_path}, make sure cookbook_path is set correctly."
- Chef::Log.fatal(msg)
- if is_last_element?(index, Chef::Config[:cookbook_path])
- msg = "No cookbook found in #{Chef::Config[:cookbook_path].inspect}, make sure cookbook_path is set correctly."
- raise Chef::Exceptions::CookbookNotFound, msg
- end
- end
+ empty_cookbook_paths = []
+ Array(Chef::Config[:cookbook_path]).each do |cookbook_path|
+ empty_cookbook_paths << cookbook_path unless directory_not_empty?(cookbook_path)
+ end
+ unless empty_cookbook_paths.empty?
+ msg = "No cookbook found in #{empty_cookbook_paths.inspect}, make sure cookbook_path is set correctly."
+ 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..67b6623402 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, 'No cookbook found in ["/path/to/invalid/cookbook_path"], make sure cookbook_path is set correctly.')
+ end
+ end
+ end
+
end
describe Chef::Client do