From 806f31d740ac96c15bd26e3f776ce6f008757d37 Mon Sep 17 00:00:00 2001 From: Sofer Athlan-Guyot Date: Wed, 29 Jun 2016 19:33:06 +0200 Subject: [PATCH] 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 --- lib/puppet/provider/openstack.rb | 15 +++++++++++++-- lib/puppet/provider/openstack/auth.rb | 4 ++-- ...usion_to_retry_mechanism-2acb52fa25bd315c.yaml | 5 +++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/feature_add_exclusion_to_retry_mechanism-2acb52fa25bd315c.yaml diff --git a/lib/puppet/provider/openstack.rb b/lib/puppet/provider/openstack.rb index 19f847bd..bcbf77b2 100644 --- a/lib/puppet/provider/openstack.rb +++ b/lib/puppet/provider/openstack.rb @@ -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] 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 diff --git a/lib/puppet/provider/openstack/auth.rb b/lib/puppet/provider/openstack/auth.rb index 1dc7e3db..584bfc72 100644 --- a/lib/puppet/provider/openstack/auth.rb +++ b/lib/puppet/provider/openstack/auth.rb @@ -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) diff --git a/releasenotes/notes/feature_add_exclusion_to_retry_mechanism-2acb52fa25bd315c.yaml b/releasenotes/notes/feature_add_exclusion_to_retry_mechanism-2acb52fa25bd315c.yaml new file mode 100644 index 00000000..81b1d1b1 --- /dev/null +++ b/releasenotes/notes/feature_add_exclusion_to_retry_mechanism-2acb52fa25bd315c.yaml @@ -0,0 +1,5 @@ +--- +features: + - Add the possibility to exclude some exception from retry + mechanism. It helps to fix `bug 1597357 + `__