From 8aa71e17972cb0c3cf9fd061cf5f425b42907d2a Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 8 Apr 2020 10:08:53 -0400 Subject: [PATCH] Fix messaging_client exception if no ENV and no yaml are present If the messaging_type is set to artemis or kafka but no ENV vars for messaging are set and no config/messaging.yml file is created the messaging_client_options method throws a NilClass exception. --- app/models/miq_queue.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/miq_queue.rb b/app/models/miq_queue.rb index d1f0c0bfa61..5bd87986b14 100644 --- a/app/models/miq_queue.rb +++ b/app/models/miq_queue.rb @@ -47,7 +47,10 @@ def self.messaging_client(client_ref) # caching the client works, even if the connection becomes unavailable # internally the client will track the state of the connection and re-open it, # once it's available again - at least thats true for a stomp connection - ManageIQ::Messaging::Client.open(messaging_client_options.merge(:client_ref => client_ref)) + options = messaging_client_options&.merge(:client_ref => client_ref) + return if options.nil? + + ManageIQ::Messaging::Client.open(options) rescue => err _log.warn("Failed to open messaging client: #{err}") nil @@ -643,10 +646,10 @@ def self.optional_values(options, keys = [:zone]) private_class_method :optional_values def self.messaging_client_options - (messaging_options_from_env || messaging_options_from_file).merge( + (messaging_options_from_env || messaging_options_from_file)&.merge( :encoding => "json", :protocol => messaging_protocol, - ).tap { |h| h[:password] = MiqPassword.try_decrypt(h.delete(:password)) } + )&.tap { |h| h[:password] = MiqPassword.try_decrypt(h.delete(:password)) } end private_class_method :messaging_client_options