diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-03-14 22:59:00 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-03-14 22:59:00 -0700 |
commit | 61c8f96347ed8824792d63babb6f336ca7a4a335 (patch) | |
tree | c33decb7aee038a350bdb9148b62b8888f5fb720 /lib/chef/policy_builder | |
parent | bd82cb8df423582cc59d4f587c5fb4ba056c5206 (diff) | |
download | chef-61c8f96347ed8824792d63babb6f336ca7a4a335.tar.gz |
Early alloction of the Chef::RunContext
Allow for allocation of the Chef::RunContext without its arguments and
use that to allocate it early. The APIs are kept backcompatible since
otherwise this has a decent chance of blowing up something like
chefspec.
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.rb | 40 | ||||
-rw-r--r-- | lib/chef/policy_builder/policyfile.rb | 9 |
2 files changed, 27 insertions, 22 deletions
diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb index 839c3bb526..dda4a2b4c3 100644 --- a/lib/chef/policy_builder/expand_node_object.rb +++ b/lib/chef/policy_builder/expand_node_object.rb @@ -3,7 +3,7 @@ # Author:: Tim Hinderliter (<tim@chef.io>) # Author:: Christopher Walters (<cw@chef.io>) # Author:: Daniel DeLeo (<dan@chef.io>) -# Copyright:: Copyright 2008-2018, Chef Software Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -73,25 +73,27 @@ class Chef # attribute files and recipes, and constructing the entire resource collection. # (FIXME: break up creating the run_context and compiling the cookbooks) # - def setup_run_context(specific_recipes = nil) - if Chef::Config[:solo_legacy_mode] - Chef::Cookbook::FileVendor.fetch_from_disk(Chef::Config[:cookbook_path]) - cl = Chef::CookbookLoader.new(Chef::Config[:cookbook_path]) - cl.load_cookbooks - cookbook_collection = Chef::CookbookCollection.new(cl) - cookbook_collection.validate! - cookbook_collection.install_gems(events) - - run_context = Chef::RunContext.new(node, cookbook_collection, @events) - else - Chef::Cookbook::FileVendor.fetch_from_remote(api_service) - cookbook_hash = sync_cookbooks - cookbook_collection = Chef::CookbookCollection.new(cookbook_hash) - cookbook_collection.validate! - cookbook_collection.install_gems(events) + def setup_run_context(specific_recipes = nil, run_context = nil) + run_context ||= Chef::RunContext.new + + run_context.events = events + run_context.node = node + + cookbook_collection = + if Chef::Config[:solo_legacy_mode] + Chef::Cookbook::FileVendor.fetch_from_disk(Chef::Config[:cookbook_path]) + cl = Chef::CookbookLoader.new(Chef::Config[:cookbook_path]) + cl.load_cookbooks + Chef::CookbookCollection.new(cl) + else + Chef::Cookbook::FileVendor.fetch_from_remote(api_service) + cookbook_hash = sync_cookbooks + Chef::CookbookCollection.new(cookbook_hash) + end - run_context = Chef::RunContext.new(node, cookbook_collection, @events) - end + cookbook_collection.validate! + cookbook_collection.install_gems(events) + run_context.cookbook_collection = cookbook_collection # TODO: move this into the cookbook_compilation_start hook setup_chef_class(run_context) diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb index 30818266f0..a4134c02bd 100644 --- a/lib/chef/policy_builder/policyfile.rb +++ b/lib/chef/policy_builder/policyfile.rb @@ -3,7 +3,7 @@ # Author:: Tim Hinderliter (<tim@chef.io>) # Author:: Christopher Walters (<cw@chef.io>) # Author:: Daniel DeLeo (<dan@chef.io>) -# Copyright:: Copyright 2008-2018, Chef Software Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -175,14 +175,17 @@ class Chef # run. # # @return [Chef::RunContext] - def setup_run_context(specific_recipes = nil) + def setup_run_context(specific_recipes = nil, run_context = nil) 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(node, cookbook_collection, 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) |