Skip to content

Commit

Permalink
bugfix for resource reporter interaction with nested providers in dep…
Browse files Browse the repository at this point in the history
…loy resource
  • Loading branch information
Lamont Granquist committed Jul 3, 2012
1 parent 3e906d3 commit 762eaca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions chef/lib/chef/event_dispatch/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ def resource_failed(resource, action, exception)
def resource_skipped(resource, action, conditional)
end

# Called when a resource action has been completed
def resource_completed(resource)
end

# Called after #load_current_resource has run.
def resource_current_state_loaded(resource, action, current_resource)
end
Expand Down
1 change: 1 addition & 0 deletions chef/lib/chef/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ def run_action(action, notification_type=nil, notifying_resource=nil)
raise customize_exception(e)
end
ensure
events.resource_completed(self)
@elapsed_time = Time.now - start_time
end
end
Expand Down
17 changes: 9 additions & 8 deletions chef/lib/chef/resource_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,26 @@ def resource_up_to_date(new_resource, action)

def resource_skipped(resource, action, conditional)
@total_res_count += 1
@pending_update = nil unless nested_resource?(resource)
end

def resource_updated(new_resource, action)
@total_res_count += 1
resource_completed unless nested_resource?(new_resource)
end

def resource_failed(new_resource, action, exception)
@total_res_count += 1
unless nested_resource?(new_resource)
@pending_update ||= ResourceReport.new_for_exception(new_resource, action)
@pending_update.exception = exception
resource_completed
end
end

def resource_completed(new_resource)
if @pending_update && !nested_resource?(new_resource)
@pending_update.finish
@updated_resources << @pending_update
@pending_update = nil
end
end

Expand Down Expand Up @@ -185,11 +192,5 @@ def nested_resource?(new_resource)
@pending_update && @pending_update.new_resource != new_resource
end

def resource_completed
@pending_update.finish
@updated_resources << @pending_update
@pending_update = nil
end

end
end
9 changes: 9 additions & 0 deletions chef/spec/unit/resource_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
@exception = Exception.new
@resource_reporter.resource_action_start(@new_resource, :create)
@resource_reporter.resource_failed(@new_resource, :create, @exception)
@resource_reporter.resource_completed(@new_resource)
end

it "collects the resource as an updated resource" do
Expand Down Expand Up @@ -117,6 +118,7 @@
@new_resource.content("this is the old content")
@current_resource.content("this is the new hotness")
@resource_reporter.resource_updated(@new_resource, :create)
@resource_reporter.resource_completed(@new_resource)
end

it "collects the updated resource" do
Expand All @@ -140,6 +142,7 @@
@next_new_resource = Chef::Resource::Service.new("apache2")
@exception = Exception.new
@resource_reporter.resource_failed(@next_new_resource, :create, @exception)
@resource_reporter.resource_completed(@next_new_resource)
end

it "collects the desired state of the failed resource" do
Expand All @@ -164,7 +167,9 @@
@resource_reporter.resource_action_start(@implementation_resource , :create)
@resource_reporter.resource_current_state_loaded(@implementation_resource, :create, @implementation_resource)
@resource_reporter.resource_updated(@implementation_resource, :create)
@resource_reporter.resource_completed(@implementation_resource)
@resource_reporter.resource_updated(@new_resource, :create)
@resource_reporter.resource_completed(@new_resource)
end

it "does not collect data about the nested resource" do
Expand All @@ -178,7 +183,9 @@
@resource_reporter.resource_action_start(@implementation_resource , :create)
@resource_reporter.resource_current_state_loaded(@implementation_resource, :create, @implementation_resource)
@resource_reporter.resource_up_to_date(@implementation_resource, :create)
@resource_reporter.resource_completed(@implementation_resource)
@resource_reporter.resource_updated(@new_resource, :create)
@resource_reporter.resource_completed(@new_resource)
end

it "does not collect data about the nested resource" do
Expand All @@ -190,6 +197,7 @@
before do
@exception = Exception.new
@resource_reporter.resource_failed(@new_resource, :create, @exception)
@resource_reporter.resource_completed(@new_resource)
end

it "collects the resource as an updated resource" do
Expand Down Expand Up @@ -249,6 +257,7 @@
@resource_reporter.resource_action_start(@new_resource, :create)
@resource_reporter.resource_current_state_loaded(@new_resource, :create, @current_resource)
@resource_reporter.resource_updated(@new_resource, :create)
@resource_reporter.resource_completed(@new_resource)
@report = @resource_reporter.report(@node)
@first_update_report = @report["resources"].first
end
Expand Down

0 comments on commit 762eaca

Please sign in to comment.