Skip to content

Commit

Permalink
Merge pull request #14460 from agrare/bz_1378984_new_folder_targeted_…
Browse files Browse the repository at this point in the history
…refresh

New folder targeted refresh [Depends on vmware/32]
  • Loading branch information
blomquisg authored Apr 24, 2017
2 parents c9f40e8 + 98e6995 commit d199f44
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/ems_refresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def self.refresh(target, id = nil)
def self.refresh_new_target(target_hash, ems_id)
ems = ExtManagementSystem.find(ems_id)

target = save_new_target(target_hash)
target = save_new_target(ems, target_hash)
if target.nil?
_log.warn "Unknown target for event data: #{target_hash}."
return
Expand Down
7 changes: 4 additions & 3 deletions app/models/ems_refresh/save_inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,14 @@ def save_event_logs_inventory(os, hashes)
save_inventory_multi(os.event_logs, hashes, :use_association, [:uid])
end

def save_new_target(target_hash)
unless target_hash[:vm].nil?
def save_new_target(ems, target_hash)
if target_hash[:vm]
vm_hash = target_hash[:vm]
existing_vm = VmOrTemplate.find_by(:ems_ref => vm_hash[:ems_ref], :ems_id => target_hash[:ems_id])
unless existing_vm.nil?
return existing_vm
end

ems = ExtManagementSystem.find_by(:id => target_hash[:ems_id])
old_cluster = get_cluster(ems, target_hash[:cluster], target_hash[:resource_pools], target_hash[:folders])

vm_hash[:ems_cluster_id] = old_cluster[:id]
Expand All @@ -379,6 +378,8 @@ def save_new_target(target_hash)
resource_pool.save!

new_vm
elsif target_hash[:folder]
ems.ems_folders.create!(target_hash[:folder])
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/ems_refresh/save_inventory_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def save_ems_infra_inventory(ems, hashes, target = nil)
log_header = "EMS: [#{ems.name}], id: [#{ems.id}]"

# Check if the data coming in reflects a complete removal from the ems
if hashes.blank? || (hashes[:hosts].blank? && hashes[:vms].blank? && hashes[:storages].blank?)
if hashes.blank? || (hashes[:hosts].blank? && hashes[:vms].blank? && hashes[:storages].blank? && hashes[:folders].blank?)
target.disconnect_inv
return
end
Expand Down
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 d199f44

Please sign in to comment.