Skip to content

Commit

Permalink
Implement VimBroker#on_create_event
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Apr 24, 2017
1 parent 82b1c04 commit 98e6995
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/models/miq_vim_broker_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions spec/models/miq_vim_broker_worker/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 98e6995

Please sign in to comment.