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:

committed by
Emilien Macchi

parent
d25bb915f4
commit
806f31d740
@@ -48,7 +48,7 @@ class Puppet::Provider::Openstack < Puppet::Provider
|
|||||||
openstack_command *args
|
openstack_command *args
|
||||||
end
|
end
|
||||||
rescue Timeout::Error
|
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
|
||||||
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
|
# Returns an array of hashes, where the keys are the downcased CSV headers
|
||||||
# with underscores instead of spaces
|
# 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 : {}
|
env = credentials ? credentials.to_env : {}
|
||||||
|
no_retry = options[:no_retry_exception_msgs]
|
||||||
|
|
||||||
Puppet::Util.withenv(env) do
|
Puppet::Util.withenv(env) do
|
||||||
rv = nil
|
rv = nil
|
||||||
end_time = current_time + request_timeout
|
end_time = current_time + request_timeout
|
||||||
@@ -121,6 +126,12 @@ class Puppet::Provider::Openstack < Puppet::Provider
|
|||||||
end
|
end
|
||||||
|
|
||||||
raise exception if no_retry_actions.include? action
|
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"
|
debug "Non-fatal error: '#{exception.message}'. Retrying for #{end_time - current_time} more seconds"
|
||||||
sleep retry_sleep
|
sleep retry_sleep
|
||||||
retry_count += 1
|
retry_count += 1
|
||||||
|
@@ -29,7 +29,7 @@ module Puppet::Provider::Openstack::Auth
|
|||||||
RCFILENAME
|
RCFILENAME
|
||||||
end
|
end
|
||||||
|
|
||||||
def request(service, action, properties=nil)
|
def request(service, action, properties=nil, options={})
|
||||||
properties ||= []
|
properties ||= []
|
||||||
set_credentials(@credentials, get_os_vars_from_env)
|
set_credentials(@credentials, get_os_vars_from_env)
|
||||||
unless @credentials.set?
|
unless @credentials.set?
|
||||||
@@ -39,7 +39,7 @@ module Puppet::Provider::Openstack::Auth
|
|||||||
unless @credentials.set?
|
unless @credentials.set?
|
||||||
raise(Puppet::Error::OpenstackAuthInputError, 'Insufficient credentials to authenticate')
|
raise(Puppet::Error::OpenstackAuthInputError, 'Insufficient credentials to authenticate')
|
||||||
end
|
end
|
||||||
super(service, action, properties, @credentials)
|
super(service, action, properties, @credentials, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_credentials(creds, env)
|
def set_credentials(creds, env)
|
||||||
|
@@ -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>`__
|
Reference in New Issue
Block a user