diff options
author | Andy Buecker <andy@tower3.io> | 2014-05-09 15:28:18 -0700 |
---|---|---|
committer | Bryan McLellan <btm@getchef.com> | 2014-06-10 09:05:39 -0700 |
commit | 77119f0f37cc100d450e4f2d2f9dcfb9a57a74a8 (patch) | |
tree | 4adf044b71b2dde3653ee7ddd81cea384bef8fca | |
parent | 96a163bf0e5955f983c6b2b9d50f550c17c22876 (diff) | |
download | chef-77119f0f37cc100d450e4f2d2f9dcfb9a57a74a8.tar.gz |
CHEF-4028 - Log resource no longer counts as an updated resource unless a write actually happens
-rw-r--r-- | lib/chef/provider/log.rb | 16 | ||||
-rw-r--r-- | spec/unit/provider/log_spec.rb | 18 |
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/chef/provider/log.rb b/lib/chef/provider/log.rb index 1c970cc888..a98ad1e1a2 100644 --- a/lib/chef/provider/log.rb +++ b/lib/chef/provider/log.rb @@ -25,6 +25,9 @@ class Chef # Chef log provider, allows logging to chef's logs from recipes class ChefLog < Chef::Provider + # ordered array of the log levels + @@levels = [ :debug, :info, :warn, :error, :fatal ] + # No concept of a 'current' resource for logs, this is a no-op # # === Return @@ -39,7 +42,18 @@ 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) + + # resolve the integers for the current log levels + global_level = @@levels.index(Chef::Log.level) + resource_level = @@levels.index(@new_resource.level) + + # If the resource level is greater than or the same os the global + # level, then it should have been written to the log. Mark the + # resource as updated. + if resource_level >= global_level + @new_resource.updated_by_last_action(true) + end + end end diff --git a/spec/unit/provider/log_spec.rb b/spec/unit/provider/log_spec.rb index f6ff526dd4..8f411e461a 100644 --- a/spec/unit/provider/log_spec.rb +++ b/spec/unit/provider/log_spec.rb @@ -78,4 +78,22 @@ describe Chef::Provider::Log::ChefLog do @provider.action_write end + it "should not update the resource if the message was not written to the log" do + Chef::Log.level = :fatal + @new_resource = Chef::Resource::Log.new(@log_str) + @new_resource.level :info + @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context) + @provider.action_write + @new_resource.updated.should be_false + end + + it "should update the resource if the message has been written to the log" do + Chef::Log.level = :debug + @new_resource = Chef::Resource::Log.new(@log_str) + @new_resource.level :info + @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context) + @provider.action_write + @new_resource.updated.should be_true + end + end |