From 46e60de1cbb805ee5611e43f2fa6cd330e5ecefb Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 12 Oct 2017 12:45:25 -0400 Subject: [PATCH 1/2] Fix the ems_event add_queue method https://github.com/ManageIQ/manageiq/pull/16073 introduced a new option for a artemis queue but broke the method handling for the standard MiqQueue. --- app/models/ems_event.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ems_event.rb b/app/models/ems_event.rb index 88e0cfa890c..87b248761df 100644 --- a/app/models/ems_event.rb +++ b/app/models/ems_event.rb @@ -58,7 +58,7 @@ def self.group_name(group) group[:name] end - def self.add_queue(_meth, ems_id, event) + def self.add_queue(meth, ems_id, event) if Settings.prototype.queue_type == 'artemis' MiqQueue.artemis_client('event_handler').publish_topic( :service => "events", From 0062162a5b3be56d5c291acc8df90b2275d22adc Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 12 Oct 2017 13:08:17 -0400 Subject: [PATCH 2/2] Add spec tests for EmsEvent.add_queue --- spec/models/ems_event_spec.rb | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/spec/models/ems_event_spec.rb b/spec/models/ems_event_spec.rb index 2d11f46530d..7507c2b1a74 100644 --- a/spec/models/ems_event_spec.rb +++ b/spec/models/ems_event_spec.rb @@ -177,6 +177,55 @@ end end + context ".add_queue" do + let(:ems) { FactoryGirl.create(:ems_kubernetes) } + let(:event_hash) do + { + :ems_ref => "event-ref", + :ems_id => ems.id, + :event_type => "STUFF_HAPPENED" + } + end + + context "queue_type: artemis" do + before { stub_settings_merge(:prototype => {:queue_type => 'artemis'}) } + + it "Adds event to Artemis queue" do + queue_client = double("ManageIQ::Messaging") + + expected_queue_payload = { + :service => "events", + :sender => ems.id, + :event => event_hash[:event_type], + :payload => event_hash, + } + + expect(queue_client).to receive(:publish_topic).with(expected_queue_payload) + expect(MiqQueue).to receive(:artemis_client).with('event_handler').and_return(queue_client) + + described_class.add_queue('add', ems.id, event_hash) + end + end + + context "queue_type: miq_queue" do + before { stub_settings_merge(:prototype => {:queue_type => 'miq_queue'}) } + + it "Adds event to MiqQueue" do + expected_queue_payload = { + :service => "event", + :target_id => ems.id, + :class_name => described_class.name, + :method_name => 'add', + :args => [event_hash], + } + + expect(MiqQueue).to receive(:submit_job).with(expected_queue_payload) + + described_class.add_queue('add', ems.id, event_hash) + end + end + end + context ".add" do before :each do @event_hash = {