Add the possibility to execute without retry.
It may be useful to be able to execute a command without a retry. A good use case is provider in [1], where the keystone_user resource try to get an user by fetching it. It is expected to fail when the user is absent. With the current implementation, it will takes 60 seconds for the provider to give up on the user. [1] https://review.openstack.org/299301 Closes-Bug: #1563898 Change-Id: I5b334e3ffd26df4ba8584d77a5e41b56e73536c8
This commit is contained in:
parent
18c3ffa0cf
commit
fedb3152c9
|
@ -13,10 +13,19 @@ class Puppet::Provider::Openstack < Puppet::Provider
|
||||||
initvars # so commands will work
|
initvars # so commands will work
|
||||||
commands :openstack_command => 'openstack'
|
commands :openstack_command => 'openstack'
|
||||||
|
|
||||||
# this actions are not idempotent and retries can cause
|
@@no_retry_actions = %w(create remove delete)
|
||||||
# duplications or endless loops
|
@@command_timeout = 20
|
||||||
def self.no_retry_actions
|
@@request_timeout = 60
|
||||||
%w(create remove delete)
|
@@retry_sleep = 3
|
||||||
|
class << self
|
||||||
|
[:no_retry_actions, :request_timeout, :retry_sleep].each do |m|
|
||||||
|
define_method m do
|
||||||
|
self.class_variable_get("@@#{m}")
|
||||||
|
end
|
||||||
|
define_method :"#{m}=" do |value|
|
||||||
|
self.class_variable_set("@@#{m}", value)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# timeout the openstack command
|
# timeout the openstack command
|
||||||
|
@ -26,22 +35,9 @@ class Puppet::Provider::Openstack < Puppet::Provider
|
||||||
def self.command_timeout(action=nil)
|
def self.command_timeout(action=nil)
|
||||||
# give no_retry actions the full time limit to finish
|
# give no_retry actions the full time limit to finish
|
||||||
return self.request_timeout() if no_retry_actions.include? action
|
return self.request_timeout() if no_retry_actions.include? action
|
||||||
20
|
self.class_variable_get("@@command_timeout")
|
||||||
end
|
end
|
||||||
|
|
||||||
# timeout the entire request with error
|
|
||||||
# after this number of seconds
|
|
||||||
def self.request_timeout
|
|
||||||
60
|
|
||||||
end
|
|
||||||
|
|
||||||
# sleep for this number of seconds
|
|
||||||
# between command retries
|
|
||||||
def self.retry_sleep
|
|
||||||
3
|
|
||||||
end
|
|
||||||
|
|
||||||
# run the openstack command
|
|
||||||
# with command_timeout
|
# with command_timeout
|
||||||
def self.openstack(*args)
|
def self.openstack(*args)
|
||||||
begin
|
begin
|
||||||
|
@ -59,6 +55,18 @@ class Puppet::Provider::Openstack < Puppet::Provider
|
||||||
Time.now.to_i
|
Time.now.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.request_without_retry(&block)
|
||||||
|
previous_timeout = self.request_timeout
|
||||||
|
rc = nil
|
||||||
|
if block_given?
|
||||||
|
self.request_timeout = 0
|
||||||
|
rc = yield
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
self.request_timeout = previous_timeout
|
||||||
|
rc
|
||||||
|
end
|
||||||
|
|
||||||
# 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)
|
def self.request(service, action, properties, credentials=nil)
|
||||||
|
|
Loading…
Reference in New Issue