diff --git a/app/models/miq_vim_broker_worker/runner.rb b/app/models/miq_vim_broker_worker/runner.rb index e0f3830b371..085e7a86003 100644 --- a/app/models/miq_vim_broker_worker/runner.rb +++ b/app/models/miq_vim_broker_worker/runner.rb @@ -162,9 +162,13 @@ def drain_event }.freeze def on_create_event(ems_id, event) - # TODO: Implement - _log.debug("Ignoring refresh for EMS id: [#{ems_id}] on event [#{event[:objType]}-create]") - nil + target_hash = ManageIQ::Providers::Vmware::InfraManager::EventParser.obj_update_to_hash(event) + if target_hash.nil? + _log.debug("Ignoring refresh for EMS id: [#{ems_id}] on event [#{event[:objType]}-create]") + else + ems = ExtManagementSystem.find(ems_id) + EmsRefresh.queue_refresh_new_target(target_hash, ems) + end end def on_delete_event(ems_id, event) diff --git a/spec/models/miq_vim_broker_worker/runner_spec.rb b/spec/models/miq_vim_broker_worker/runner_spec.rb index 0fd77cd24db..c80337d5590 100644 --- a/spec/models/miq_vim_broker_worker/runner_spec.rb +++ b/spec/models/miq_vim_broker_worker/runner_spec.rb @@ -249,6 +249,34 @@ expect(q.args).to eq([[[host.class.name, host.id]]]) end + it "will handle create events properly" do + event = { + :server => @ems.address, + :username => @ems.authentication_userid, + :objType => "Folder", + :op => "create", + :mor => "group-v123" + } + + expected_folder_hash = { + :folder => { + :type => "EmsFolder", + :ems_ref => "group-v123", + :ems_ref_obj => "group-v123", + :uid_ems => "group-v123" + } + } + + @vim_broker_worker.instance_variable_get(:@queue).enq(event.dup) + + @vim_broker_worker.drain_event + expect(MiqQueue.count).to eq(1) + q = MiqQueue.first + expect(q.class_name).to eq("EmsRefresh") + expect(q.method_name).to eq("refresh_new_target") + expect(q.args).to eq([expected_folder_hash, @ems.id]) + end + it "will ignore updates to unknown properties" do vm = FactoryGirl.create(:vm_with_ref, :ext_management_system => @ems) @vim_broker_worker.instance_variable_get(:@queue).enq(:server => @ems.address,