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", 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 = {