Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Retry (Idempotency requests) #462

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ If you're not sure whether your OpenStack cloud uses Keystone V2 or V3 then you

If you need a version of OpenStack to test against, get youself a copy of [DevStack](http://docs.openstack.org/developer/devstack/).

### Auto Retry Requests

Failed requests can be handled to allow retries capability.

One use case is to be able to resubmit request when facing network latency.

By default auto retry is deactivated.
To activate auto retry set `idempotency` option to `true`

The default values are:
- retry limit is 2 times
- retry interval is 5 seconds

Those values can be overriden using `:retry_limit` and `:retry_interval` options.

### Networking Gotcha

Note that tenants (aka projects) in OpenStack usually require that you create a default gateway router in order to allow external access to your instances.
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/baremetal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Baremetal < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

## MODELS
#
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Compute < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

## MODELS
#
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/container_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class ContainerInfra < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/container_infra/models'

Expand Down
13 changes: 13 additions & 0 deletions lib/fog/openstack/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def initialize(options = {})
private

def request(params, parse_json = true)
if @idempotent && @idempotent_verbs.include?(params[:method])
params.merge!(
:idempotent => @idempotent,
:retry_limit => @retry_limit,
:retry_interval => @retry_interval
)
end

retried = false
begin
authenticate! if @expires && (@expires - Time.now.utc).to_i < 60
Expand Down Expand Up @@ -172,6 +180,11 @@ def setup(options)
instance_variable_set "@#{openstack_param}".to_sym, value
end

@idempotent_verbs ||= %w(GET DELETE)
@idempotent ||= !!options[:idempotent]
@retry_interval ||= options[:retry_interval] || 5 # Seconds
@retry_limit ||= options[:retry_limit] || 2

Copy link
Member

@aufi aufi Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, but if I'm not mistaken, 3 lines above could be written in shorter way (also matching to pattern few lines bellow)

@idempotent     ||= !!options[:idempotent]
@retry_interval ||= options[:retry_interval] || 5 # Seconds
@retry_limit    ||= options[:retry_limit] || 2

Some test would be nice too..

Generally nice PR, overall looks good to me!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's neat.

Absolutely, I'lll looking into adding some tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aufi, sorry didn't get the bandwidth to do it.

# Ensure OpenStack User's Password is always a String
@openstack_api_key = @openstack_api_key.to_s if @openstack_api_key

Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/dns/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class V1 < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl
:openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl,
:idempotent, :retry_interval, :retry_limit

request_path 'fog/openstack/dns/v1/requests'

Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/dns/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class V2 < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl
:openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/dns/v2/models'
model :zone
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Event < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/event/models'

Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/identity/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class V2 < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version, :no_path_prefix
:openstack_identity_api_version, :no_path_prefix,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/identity/v2/models'
model :tenant
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/identity/v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class V3 < Fog::Service
:openstack_user_domain_id, :openstack_project_domain_id,
:openstack_api_key, :openstack_current_user_id, :openstack_userid, :openstack_username,
:current_user, :current_user_id, :current_tenant,
:provider, :openstack_identity_api_version, :openstack_cache_ttl
:provider, :openstack_identity_api_version, :openstack_cache_ttl,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/identity/v3/models'
model :domain
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/image/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class V1 < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/image/v1/models'

Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/image/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class V2 < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/image/v2/models'

Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/introspection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Introspection < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

## REQUESTS
#
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/key_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class KeyManager < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl
:openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl,
:idempotent, :retry_interval, :retry_limit


## MODELS
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/metering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Metering < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/metering/models'

Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Metric < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/metric/models'

Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class Monitoring < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl
:openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/monitoring/models'
model :metric
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Network < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

## MODELS
#
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/nfv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class NFV < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

## REQUESTS
#
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/orchestration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Orchestration < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/orchestration/models'
model :stack
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/planning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Planning < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit

## MODELS
#
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/shared_file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class SharedFileSystem < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version, :openstack_shared_file_system_microversion
:openstack_identity_api_version, :openstack_shared_file_system_microversion,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/shared_file_system/models'
model :network
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Storage < Fog::Service
:openstack_project_name, :openstack_project_id, :openstack_cache_ttl,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version, :openstack_temp_url_key
:openstack_identity_api_version, :openstack_temp_url_key,
:idempotent, :retry_interval, :retry_limit

model_path 'fog/openstack/storage/models'
model :directory
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Volume < Fog::Service
:openstack_project_name, :openstack_project_id,
:openstack_project_domain, :openstack_user_domain, :openstack_domain_name,
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version]
:openstack_identity_api_version,
:idempotent, :retry_interval, :retry_limit]

# Fog::OpenStack::Image.new() will return a Fog::OpenStack::Volume::V2 or a Fog::OpenStack::Volume::V1,
# choosing the V2 by default, as V1 is deprecated since OpenStack Juno
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/workflow/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class V2 < Fog::Service

requires :openstack_auth_url
recognizes :openstack_username, :openstack_api_key,
:openstack_project_name, :openstack_domain_id
:openstack_project_name, :openstack_domain_id,
:idempotent, :retry_interval, :retry_limit

## REQUESTS
#
Expand Down