diff options
author | danielsdeleo <dan@getchef.com> | 2014-03-13 21:12:29 -0700 |
---|---|---|
committer | danielsdeleo <dan@getchef.com> | 2014-03-14 14:09:37 -0700 |
commit | becb0427f813f787fd492798f6c97de67fdd732c (patch) | |
tree | ea01bc7e6ee4860eee8111c2fa9a3a382c891207 /lib/chef/run_context | |
parent | 8c2a9753bdf8ee43226082825eb0a0531c94e202 (diff) | |
download | chef-becb0427f813f787fd492798f6c97de67fdd732c.tar.gz |
Raise an error when including a recipe from an unreachable cookbook
Fixes CHEF-4367.
When attempting to load a recipe belonging to a cookbook that is not in
the run_list or any dependencies of cookbooks in the run_list, chef
will now produce an error like this:
Chef::Exceptions::MissingCookbookDependency
-------------------------------------------
Recipe `ancient::aliens` is not in the run_list, and cookbook 'ancient'
is not a dependency of any cookbook in the run_list. To load thisrecipe,
first add a dependency on cookbook 'ancient' in the cookbook you're
including it from in that cookbook's metadata.
This error will occur when chef-solo users use `include_recipe` without
specifying the dependency in metadata; prior to this patch, chef would
typically fail reading an undefined attribute, which commonly would
result in a NoMethodError for nil.
Diffstat (limited to 'lib/chef/run_context')
-rw-r--r-- | lib/chef/run_context/cookbook_compiler.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/chef/run_context/cookbook_compiler.rb b/lib/chef/run_context/cookbook_compiler.rb index 0a05061152..abe5afa7ae 100644 --- a/lib/chef/run_context/cookbook_compiler.rb +++ b/lib/chef/run_context/cookbook_compiler.rb @@ -16,6 +16,7 @@ # limitations under the License. # +require 'set' require 'chef/log' require 'chef/recipe' require 'chef/resource/lwrp_base' @@ -149,6 +150,17 @@ class Chef @events.recipe_load_complete end + # Whether or not a cookbook is reachable from the set of cookbook given + # by the run_list plus those cookbooks' dependencies. + def unreachable_cookbook?(cookbook_name) + !reachable_cookbooks.include?(cookbook_name) + end + + # All cookbooks in the dependency graph, returned as a Set. + def reachable_cookbooks + @reachable_cookbooks ||= Set.new(cookbook_order) + end + private def load_attributes_from_cookbook(cookbook_name) |