summaryrefslogtreecommitdiff
path: root/lib/chef/policy_builder
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-08-23 15:01:12 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-08-26 14:09:12 -0700
commita8a6ea0734998c32e015259b385ee4fc3e9ccfa8 (patch)
treeb743de046fb7455920cd034df42c642e2ed857ab /lib/chef/policy_builder
parentdd0009d7e77f192cadb1632f2159a6dbc880980f (diff)
downloadchef-a8a6ea0734998c32e015259b385ee4fc3e9ccfa8.tar.gz
Fix node[:cookbooks] attribute
closes #8817 Note that if any calling code winds up seeing this error message: ``` NoMethodError: undefined method `set_cookbook_attribute' for nil:NilClass ``` That means that the cookbook_collection was set before the node was set on the run_context. That wouldn't be a bug in core chef, that must be fixed in the caller to reverse the order of operations. Since I only made the positional arguments to the run_context constructor optional in Chef-15.0 though I don't expect this breaks any existing code written in the past month or two, but if anything crops up in the future, consider this a definitive statement that the caller must reverse the order of their operations and this error being thrown is a feature not a bug to be fixed. (The fact that we silently aborted rather than threw a NoMethodError on NilClass meant that we shipped this defect -- sometimes defensive programming can be overly defensive and swallow real errors). Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/policy_builder')
-rw-r--r--lib/chef/policy_builder/expand_node_object.rb2
-rw-r--r--lib/chef/policy_builder/policyfile.rb7
2 files changed, 5 insertions, 4 deletions
diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb
index 4afb4d7d60..bb5e2e199b 100644
--- a/lib/chef/policy_builder/expand_node_object.rb
+++ b/lib/chef/policy_builder/expand_node_object.rb
@@ -75,7 +75,6 @@ class Chef
#
def setup_run_context(specific_recipes = nil, run_context = nil)
run_context ||= Chef::RunContext.new
-
run_context.events = events
run_context.node = node
@@ -93,6 +92,7 @@ class Chef
cookbook_collection.validate!
cookbook_collection.install_gems(events)
+
run_context.cookbook_collection = cookbook_collection
# TODO: move this into the cookbook_compilation_start hook
diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb
index 70a2e44635..7eb9de042e 100644
--- a/lib/chef/policy_builder/policyfile.rb
+++ b/lib/chef/policy_builder/policyfile.rb
@@ -177,16 +177,17 @@ class Chef
#
# @return [Chef::RunContext]
def setup_run_context(specific_recipes = nil, run_context = nil)
+ run_context ||= Chef::RunContext.new
+ run_context.node = node
+ run_context.events = events
+
Chef::Cookbook::FileVendor.fetch_from_remote(api_service)
sync_cookbooks
cookbook_collection = Chef::CookbookCollection.new(cookbooks_to_sync)
cookbook_collection.validate!
cookbook_collection.install_gems(events)
- run_context ||= Chef::RunContext.new
- run_context.node = node
run_context.cookbook_collection = cookbook_collection
- run_context.events = events
setup_chef_class(run_context)