diff options
author | jamesc <james@opscode.com> | 2013-10-11 16:24:48 -0700 |
---|---|---|
committer | jamesc <james@opscode.com> | 2013-10-15 14:53:09 -0700 |
commit | 62265ff2b7a75a6dc0135ae8105002a9803f01ce (patch) | |
tree | 7609785a1dead6a43b14cfa2ca678b3e4def0d66 /lib/chef/resource_reporter.rb | |
parent | 6d58ff931dda2d5bfa0eb8b7feadf5cd0fb37c8e (diff) | |
download | chef-62265ff2b7a75a6dc0135ae8105002a9803f01ce.tar.gz |
When reporting a resource, before and after should always be a hash
If a Resource (or LWRP) overrides Resource#state (meaning to set an
attribute named state) this collides with the state function used to
gather up the state_attrs
Fix this by not using Resource#state, but copying that logic
into ResourceReporter#state.
Leaving Resource#state as it's used by other things. A full fix so
LWRPs can't override functions in Resource is in scope for Chef 12
Diffstat (limited to 'lib/chef/resource_reporter.rb')
-rw-r--r-- | lib/chef/resource_reporter.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb index 434150e83d..d29949086e 100644 --- a/lib/chef/resource_reporter.rb +++ b/lib/chef/resource_reporter.rb @@ -52,8 +52,8 @@ class Chef as_hash["type"] = new_resource.class.dsl_name as_hash["name"] = new_resource.name as_hash["id"] = new_resource.identity - as_hash["after"] = new_resource.state - as_hash["before"] = current_resource ? current_resource.state : {} + as_hash["after"] = state(new_resource) + as_hash["before"] = current_resource ? state(current_resource) : {} 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? @@ -80,6 +80,12 @@ class Chef !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 |