summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-10-21 10:52:43 -0700
committerSerdar Sutay <serdar@opscode.com>2014-10-21 10:52:43 -0700
commit8c1be56ff907abef6e8cc6f30734112a2d38db69 (patch)
treeb9bd9370604c9f4d71b79fa925c203ce47a2a6d9
parentc38f704f5fff50c5e5254add9593cbd83b06a8a2 (diff)
parentb266ca180c803887c2d41342840279c90ba6e931 (diff)
downloadchef-8c1be56ff907abef6e8cc6f30734112a2d38db69.tar.gz
Merge pull request #2259 from kwilczynski/chef-2258
Fix value of retries shown in the error report.
-rw-r--r--lib/chef/resource.rb13
-rw-r--r--spec/unit/resource_spec.rb34
2 files changed, 37 insertions, 10 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 0b8fb2cb12..e92ea28c69 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -652,6 +652,11 @@ F
# on accident
updated_by_last_action(false)
+ # Don't modify @retries directly and keep it intact, so that the
+ # recipe_snippet from ResourceFailureInspector can print the value
+ # that was set in the resource block initially.
+ remaining_retries = retries
+
begin
return if should_skip?(action)
provider_for_action(action).run_action
@@ -659,10 +664,10 @@ F
if ignore_failure
Chef::Log.error("#{custom_exception_message(e)}; ignore_failure is set, continuing")
events.resource_failed(self, action, e)
- elsif retries > 0
- events.resource_failed_retriable(self, action, retries, e)
- @retries -= 1
- Chef::Log.info("Retrying execution of #{self}, #{retries} attempt(s) left")
+ elsif remaining_retries > 0
+ events.resource_failed_retriable(self, action, remaining_retries, e)
+ remaining_retries -= 1
+ Chef::Log.info("Retrying execution of #{self}, #{remaining_retries} attempt(s) left")
sleep retry_delay
retry
else
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index bcc91d52bc..584ec8175c 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -394,22 +394,44 @@ describe Chef::Resource do
end
describe "retries" do
+ before do
+ @retriable_resource = Chef::Resource::Cat.new("precious", @run_context)
+ @retriable_resource.provider = Chef::Provider::SnakeOil
+ @retriable_resource.action = :purr
+
+ @node.automatic_attrs[:platform] = "fubuntu"
+ @node.automatic_attrs[:platform_version] = '10.04'
+ end
+
it "should default to not retrying if a provider fails for a resource" do
- @resource.retries.should == 0
+ @retriable_resource.retries.should == 0
end
it "should allow you to set how many retries a provider should attempt after a failure" do
- @resource.retries(2)
- @resource.retries.should == 2
+ @retriable_resource.retries(2)
+ @retriable_resource.retries.should == 2
end
it "should default to a retry delay of 2 seconds" do
- @resource.retry_delay.should == 2
+ @retriable_resource.retry_delay.should == 2
end
it "should allow you to set the retry delay" do
- @resource.retry_delay(10)
- @resource.retry_delay.should == 10
+ @retriable_resource.retry_delay(10)
+ @retriable_resource.retry_delay.should == 10
+ end
+
+ it "should keep given value of retries intact after the provider fails for a resource" do
+ @retriable_resource.retries(3)
+ @retriable_resource.retry_delay(0) # No need to wait.
+
+ provider = Chef::Provider::SnakeOil.new(@retriable_resource, @run_context)
+ Chef::Provider::SnakeOil.stub(:new).and_return(provider)
+ provider.stub(:action_purr).and_raise
+
+ @retriable_resource.should_receive(:sleep).exactly(3).times
+ expect { @retriable_resource.run_action(:purr) }.to raise_error
+ @retriable_resource.retries.should == 3
end
end