Add optional exceptions regex to avoid to retry.

This is useful when the user (a puppet provider) is expecting a error.
With this it doesn't have to wait for the long retry cycle to have its
error back.  This replace the awkward mechanism in
self.request_without_retry which was dynamically mangling
request_timeout and disabled even legit retry.

Examples of such function are self.fetch_user, self.fetch_project in the
keystone provider.

Change-Id: I589da0100ad3ccf3abf17ac8b26c827793ace484
Related-Bug: 1597357
This commit is contained in:
Sofer Athlan-Guyot
2016-06-29 19:33:06 +02:00
committed by Emilien Macchi
parent d25bb915f4
commit 806f31d740
3 changed files with 20 additions and 4 deletions

View File

@@ -48,7 +48,7 @@ class Puppet::Provider::Openstack < Puppet::Provider
openstack_command *args
end
rescue Timeout::Error
raise Puppet::ExecutionFailure, "Command: 'openstack #{args.inspect}' has been running for more then #{command_timeout(action)} seconds"
raise Puppet::ExecutionFailure, "Command: 'openstack #{args.inspect}' has been running for more than #{command_timeout(action)} seconds"
end
end
@@ -71,8 +71,13 @@ class Puppet::Provider::Openstack < Puppet::Provider
# Returns an array of hashes, where the keys are the downcased CSV headers
# with underscores instead of spaces
def self.request(service, action, properties, credentials=nil)
#
# @param options [Hash] Other options
# @options :no_retry_exception_msgs [Array<Regexp>,Regexp] exception without retries
def self.request(service, action, properties, credentials=nil, options={})
env = credentials ? credentials.to_env : {}
no_retry = options[:no_retry_exception_msgs]
Puppet::Util.withenv(env) do
rv = nil
end_time = current_time + request_timeout
@@ -121,6 +126,12 @@ class Puppet::Provider::Openstack < Puppet::Provider
end
raise exception if no_retry_actions.include? action
if no_retry
no_retry = [no_retry] unless no_retry.is_a?(Array)
no_retry.each do |nr|
raise exception if exception.message.match(nr)
end
end
debug "Non-fatal error: '#{exception.message}'. Retrying for #{end_time - current_time} more seconds"
sleep retry_sleep
retry_count += 1

View File

@@ -29,7 +29,7 @@ module Puppet::Provider::Openstack::Auth
RCFILENAME
end
def request(service, action, properties=nil)
def request(service, action, properties=nil, options={})
properties ||= []
set_credentials(@credentials, get_os_vars_from_env)
unless @credentials.set?
@@ -39,7 +39,7 @@ module Puppet::Provider::Openstack::Auth
unless @credentials.set?
raise(Puppet::Error::OpenstackAuthInputError, 'Insufficient credentials to authenticate')
end
super(service, action, properties, @credentials)
super(service, action, properties, @credentials, options)
end
def set_credentials(creds, env)

View File

@@ -0,0 +1,5 @@
---
features:
- Add the possibility to exclude some exception from retry
mechanism. It helps to fix `bug 1597357
<https://bugs.launchpad.net/puppet-keystone/+bug/1597357>`__