summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2016-09-16 14:18:58 -0400
committerGitHub <noreply@github.com>2016-09-16 14:18:58 -0400
commit2e64a669f28bbe3fa6f1a3b120a15d3c17ae4e47 (patch)
treebef26a3b87493a52b7091195be323bfd013443c0
parente50207b4315823954a8826fff57ee54140ffc8e2 (diff)
parentc7387e683cacaf7c5adcf2f2a96700c2b8d32c30 (diff)
downloadchef-2e64a669f28bbe3fa6f1a3b120a15d3c17ae4e47.tar.gz
Merge pull request #5267 from MsysTechnologiesllc/nim/update_resource_count
Added count_log_resource_updates config attribute
-rw-r--r--chef-config/lib/chef-config/config.rb4
-rw-r--r--lib/chef/provider/log.rb2
-rw-r--r--spec/unit/provider/log_spec.rb14
3 files changed, 19 insertions, 1 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index be5ca2099c..f2db54aa17 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -659,6 +659,10 @@ module ChefConfig
ENV.key?("CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS")
end
+ # Whether the resource count should be updated for log resource
+ # on running chef-client
+ default :count_log_resource_updates, true
+
# knife configuration data
config_context :knife do
# XXX: none of these default values are applied to knife (and would create a backcompat
diff --git a/lib/chef/provider/log.rb b/lib/chef/provider/log.rb
index eef4077c07..567781cb41 100644
--- a/lib/chef/provider/log.rb
+++ b/lib/chef/provider/log.rb
@@ -45,7 +45,7 @@ class Chef
# true:: Always return true
def action_write
Chef::Log.send(@new_resource.level, @new_resource.message)
- @new_resource.updated_by_last_action(true)
+ @new_resource.updated_by_last_action(true) if Chef::Config[:count_log_resource_updates]
end
end
diff --git a/spec/unit/provider/log_spec.rb b/spec/unit/provider/log_spec.rb
index 2e4f9c4e52..ce7b1af55a 100644
--- a/spec/unit/provider/log_spec.rb
+++ b/spec/unit/provider/log_spec.rb
@@ -72,4 +72,18 @@ describe Chef::Provider::Log::ChefLog do
expect(Chef::Log).to receive(:info).with(log_str).and_return(true)
provider.run_action(:write)
end
+
+ context "when count_log_resource_updates is passed in knife.rb" do
+ it "updates the resource count if count_log_resource_updates=true" do
+ Chef::Config[:count_log_resource_updates] = true
+ expect(new_resource).to receive(:updated_by_last_action)
+ provider.run_action(:write)
+ end
+
+ it "doesn't update the resource count if count_log_resource_updates=false" do
+ Chef::Config[:count_log_resource_updates] = false
+ expect(new_resource).not_to receive(:updated_by_last_action)
+ provider.run_action(:write)
+ end
+ end
end