Skip to content

Commit

Permalink
Safely load orchestration stack relations
Browse files Browse the repository at this point in the history
Safely load orchestration stack relations

Fixes BZ:
https://bugzilla.redhat.com/show_bug.cgi?id=1297002
  • Loading branch information
Ladas committed Apr 21, 2016
1 parent 80a62bc commit 575de9f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Expand Up @@ -2,6 +2,7 @@

module ManageIQ::Providers
class Openstack::CloudManager::RefreshParser < ManageIQ::Providers::CloudManager::RefreshParser
include Vmdb::Logging
include ManageIQ::Providers::Openstack::RefreshParserCommon::HelperMethods
include ManageIQ::Providers::Openstack::RefreshParserCommon::Images
include ManageIQ::Providers::Openstack::RefreshParserCommon::Objects
Expand Down
Expand Up @@ -5,7 +5,8 @@ module HelperMethods
def process_collection(collection, key, &block)
@data[key] ||= []
return if @options && @options[:inventory_ignore] && @options[:inventory_ignore].include?(key)
collection.each { |item| process_collection_item(item, key, &block) }
# safe_call catches and ignores all Fog relation calls inside processing, causing allowed excon errors
collection.each { |item| safe_call { process_collection_item(item, key, &block) } }
end

def process_collection_item(item, key)
Expand All @@ -17,6 +18,27 @@ def process_collection_item(item, key)
@data_index.store_path(key, uid, new_result)
new_result
end

def safe_call
# Safe call wrapper for any Fog call not going through handled_list
yield
rescue Excon::Errors::Forbidden => err
# It can happen user doesn't have rights to read some tenant, in that case log warning but continue refresh
_log.warn "Forbidden response code returned in provider: #{@os_handle.address}. Message=#{err.message}"
_log.warn err.backtrace.join("\n")
nil
rescue Excon::Errors::NotFound => err
# It can happen that some data do not exist anymore,, in that case log warning but continue refresh
_log.warn "Not Found response code returned in provider: #{@os_handle.address}. Message=#{err.message}"
_log.warn err.backtrace.join("\n")
nil
end

alias safe_get safe_call

def safe_list(&block)
safe_call(&block) || []
end
end
end
end
Expand Down
Expand Up @@ -5,7 +5,7 @@ module OrchestrationStacks
def stack_resources(stack)
return @resources[stack.id] if @resources && !@resources.fetch_path(stack.id).blank?
@resources = {} unless @resources
@resources[stack.id] = stack.resources
@resources[stack.id] = safe_list { stack.resources }
end

def load_orchestration_stacks
Expand Down Expand Up @@ -133,7 +133,7 @@ def get_stack_template(stack)
end

def find_stack_parameters(stack)
raw_parameters = stack.parameters
raw_parameters = safe_list { stack.parameters }
get_stack_parameters(stack.id, raw_parameters)
raw_parameters.collect do |parameter|
@data_index.fetch_path(:orchestration_stack_parameters, compose_ems_ref(stack.id, parameter[0]))
Expand All @@ -146,7 +146,7 @@ def find_stack_template(stack)
end

def find_stack_outputs(stack)
raw_outputs = stack.outputs || []
raw_outputs = safe_list { stack.outputs }
get_stack_outputs(stack.id, raw_outputs)
raw_outputs.collect do |output|
@data_index.fetch_path(:orchestration_stack_outputs, compose_ems_ref(stack.id, output['output_key']))
Expand Down
6 changes: 6 additions & 0 deletions gems/pending/openstack/openstack_handle/handled_list.rb
Expand Up @@ -23,6 +23,12 @@ def handled_list(collection_type, options = {})
"in provider: #{@os_handle.address}. Message=#{err.message}"
_log.warn err.backtrace.join("\n")
[]
rescue Excon::Errors::NotFound => err
# It can happen that some data do not exist anymore, in that case log warning but continue refresh
_log.warn "Data not found in project: #{@os_handle.project_name}, for collection type: #{collection_type}, "\
"in provider: #{@os_handle.address}. Message=#{err.message}"
_log.warn err.backtrace.join("\n")
[]
rescue => err
# Show any list related exception in a nice format.
openstack_service_name = Handle::SERVICE_NAME_MAP[self.class::SERVICE_NAME]
Expand Down

0 comments on commit 575de9f

Please sign in to comment.