summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/file.rb8
-rw-r--r--lib/chef/resource.rb11
-rw-r--r--lib/chef/resource/file.rb18
-rw-r--r--lib/chef/resource_reporter.rb11
4 files changed, 36 insertions, 12 deletions
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 44ee91a079..fda8ad2e5e 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -386,8 +386,12 @@ class Chef
def update_file_contents
do_backup unless needs_creating?
- deployment_strategy.deploy(tempfile.path, ::File.realpath(@new_resource.path))
- Chef::Log.info("#{@new_resource} updated file contents #{@new_resource.path}")
+ deployment_strategy.deploy(tempfile.path, ::File.realpath(new_resource.path))
+ Chef::Log.info("#{new_resource} updated file contents #{new_resource.path}")
+ if managing_content?
+ # save final checksum for reporting.
+ new_resource.final_checksum = checksum(new_resource.path)
+ end
end
def do_contents_changes
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index d934ec8c47..3d319617d1 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -467,7 +467,7 @@ class Chef
#
# @return [Hash{Symbol => Object}] A Hash of attribute => value for the
# Resource class's `state_attrs`.
- def state
+ def state_for_resource_reporter
self.class.state_attrs.inject({}) do |state_attrs, attr_name|
state_attrs[attr_name] = send(attr_name)
state_attrs
@@ -475,6 +475,15 @@ class Chef
end
#
+ # Since there are collisions with LWRP parameters named 'state' this
+ # method is not used by the resource_reporter and is most likely unused.
+ # It certainly cannot be relied upon and cannot be fixed.
+ #
+ # @deprecated
+ #
+ alias_method :state, :state_for_resource_reporter
+
+ #
# The value of the identity attribute, if declared. Falls back to #name if
# no identity attribute is declared.
#
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb
index 53a6a160af..d1e34f5728 100644
--- a/lib/chef/resource/file.rb
+++ b/lib/chef/resource/file.rb
@@ -38,6 +38,15 @@ class Chef
attr_writer :checksum
+ #
+ # The checksum of the rendered file. This has to be saved on the
+ # new_resource for the 'after' state for reporting but we cannot
+ # mutate the new_resource.checksum which would change the
+ # user intent in the new_resource if the resource is reused.
+ #
+ # @returns [String] Checksum of the file we actually rendered
+ attr_accessor :final_checksum
+
provides :file
def initialize(name, run_context=nil)
@@ -129,6 +138,15 @@ class Chef
@verifications
end
end
+
+ def state_for_resource_reporter
+ state_attrs = super()
+ # fix up checksum state with final_checksum saved by the provider
+ if checksum.nil? && final_checksum
+ state_attrs['checksum'] = final_checksum
+ end
+ state_attrs
+ end
end
end
end
diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb
index 1816fc857d..96cc01d814 100644
--- a/lib/chef/resource_reporter.rb
+++ b/lib/chef/resource_reporter.rb
@@ -62,8 +62,8 @@ class Chef
as_hash["type"] = new_resource.class.dsl_name
as_hash["name"] = new_resource.name.to_s
as_hash["id"] = new_resource.identity.to_s
- as_hash["after"] = state(new_resource)
- as_hash["before"] = current_resource ? state(current_resource) : {}
+ as_hash["after"] = new_resource.state_for_resource_reporter
+ as_hash["before"] = current_resource ? current_resource.state_for_resource_reporter : {}
as_hash["duration"] = (elapsed_time * 1000).to_i.to_s
as_hash["delta"] = new_resource.diff if new_resource.respond_to?("diff")
as_hash["delta"] = "" if as_hash["delta"].nil?
@@ -89,13 +89,6 @@ class Chef
def success?
!self.exception
end
-
- def state(r)
- r.class.state_attrs.inject({}) do |state_attrs, attr_name|
- state_attrs[attr_name] = r.send(attr_name)
- state_attrs
- end
- end
end # End class ResouceReport
attr_reader :updated_resources