diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-11-16 18:03:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-16 18:03:12 -0800 |
commit | 3401bdbd31ef371e38d6d76738716db3e56b3305 (patch) | |
tree | 712dd1d9062fb5444c6f01c76bffe733b8f777cb | |
parent | af42f190e31c8cc4d79426aef09a2bf68c269711 (diff) | |
parent | e7057a5cd4c49b8325571d3ea7eb824f17fcb68c (diff) | |
download | chef-3401bdbd31ef371e38d6d76738716db3e56b3305.tar.gz |
Merge pull request #4838 from chef/lcg/resource-cloning-toggle
add global and per-resource toggles for resource cloning behavior
-rw-r--r-- | chef-config/lib/chef-config/config.rb | 6 | ||||
-rw-r--r-- | lib/chef/resource_builder.rb | 4 | ||||
-rw-r--r-- | spec/unit/recipe_spec.rb | 32 |
3 files changed, 40 insertions, 2 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index c9c2ca77df..23e4d75168 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -1053,6 +1053,12 @@ module ChefConfig default :rubygems_url, "https://rubygems.org" + # This controls the behavior of resource cloning (and CHEF-3694 warnings). For Chef < 12 the behavior + # has been that this is 'true', in Chef 13 this will change to false. Setting this to 'true' in Chef + # 13 is not a viable or supported migration strategy since Chef 13 community cookbooks will be expected + # to break with this setting set to 'true'. + default :resource_cloning, true + # If installed via an omnibus installer, this gives the path to the # "embedded" directory which contains all of the software packaged with # omnibus. This is used to locate the cacert.pem file on windows. diff --git a/lib/chef/resource_builder.rb b/lib/chef/resource_builder.rb index 78b2fcd4d1..1aee852f5d 100644 --- a/lib/chef/resource_builder.rb +++ b/lib/chef/resource_builder.rb @@ -56,7 +56,7 @@ class Chef # This behavior is very counter-intuitive and should be removed. # See CHEF-3694, https://tickets.opscode.com/browse/CHEF-3694 # Moved to this location to resolve CHEF-5052, https://tickets.opscode.com/browse/CHEF-5052 - if prior_resource + if prior_resource && Chef::Config[:resource_cloning] resource.load_from(prior_resource) end @@ -80,7 +80,7 @@ class Chef end # emit a cloned resource warning if it is warranted - if prior_resource + if prior_resource && Chef::Config[:resource_cloning] if is_trivial_resource?(prior_resource) && identicalish_resources?(prior_resource, resource) emit_harmless_cloning_debug else diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index eea1a41998..e1e3e0ad72 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -193,6 +193,38 @@ describe Chef::Recipe do end end + describe "when resource cloning is disabled" do + def not_expect_warning + expect(Chef::Log).not_to receive(:warn).with(/3694/) + expect(Chef::Log).not_to receive(:warn).with(/Previous/) + expect(Chef::Log).not_to receive(:warn).with(/Current/) + end + + before do + Chef::Config[:resource_cloning] = false + end + + it "should emit a 3694 warning when attributes change" do + recipe.zen_master "klopp" do + something "bvb" + end + not_expect_warning + recipe.zen_master "klopp" do + something "vbv" + end + end + + it "should not copy attributes from a prior resource" do + recipe.zen_master "klopp" do + something "bvb" + end + not_expect_warning + recipe.zen_master "klopp" + expect(run_context.resource_collection.first.something).to eql("bvb") + expect(run_context.resource_collection[1].something).to be nil + end + end + describe "when cloning resources" do def expect_warning expect(Chef).to receive(:deprecated).with(:resource_cloning, /^Cloning resource attributes for zen_master\[klopp\]/) |