Skip to content

Commit

Permalink
Merge pull request #18513 from agrare/fix_base_refresher_targeted_ref…
Browse files Browse the repository at this point in the history
…resh

Only run preprocess_targets_manager_refresh when doing graph refresh and add specs
  • Loading branch information
gtanzillo authored Mar 4, 2019
2 parents a08f919 + e8ee67a commit 71524f8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
6 changes: 1 addition & 5 deletions app/models/manageiq/providers/base_manager/refresher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,7 @@ def group_targets_by_ems(targets)
def preprocess_targets_manager_refresh
@targets_by_ems_id.each do |ems_id, targets|
ems = @ems_by_ems_id[ems_id]

if targets.any? { |t| t.kind_of?(ExtManagementSystem) }
targets_for_log = targets.map { |t| "#{t.class} [#{t.name}] id [#{t.id}] " }
_log.info("Defaulting to full refresh for EMS: [#{ems.name}], id: [#{ems.id}], from targets: #{targets_for_log}") if targets.length > 1
end
next unless ems.inventory_object_refresh?

# We want all targets of class EmsEvent to be merged into one target, so they can be refreshed together, otherwise
# we could be missing some crosslinks in the refreshed data
Expand Down
45 changes: 45 additions & 0 deletions spec/models/manageiq/providers/base_manager/refresher_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
describe ManageIQ::Providers::BaseManager::Refresher do
context "#initialize" do
let(:ems1) { FactoryBot.create(:ext_management_system) }
let(:ems2) { FactoryBot.create(:ext_management_system) }
let(:vm1) { FactoryBot.create(:vm, :ext_management_system => ems1) }
let(:vm2) { FactoryBot.create(:vm, :ext_management_system => ems2) }

it "groups targets by ems" do
refresher = described_class.new([vm1, vm2])
expect(refresher.targets_by_ems_id.keys).to include(ems1.id, ems2.id)
end
end

context "#refresh" do
context "#preprocess_targets" do
let(:ems) { FactoryBot.create(:ext_management_system) }
let(:vm) { FactoryBot.create(:vm, :ext_management_system => ems) }
let(:lots_of_vms) do
num_targets = Settings.ems_refresh.full_refresh_threshold + 1
Array.new(num_targets) { FactoryBot.create(:vm, :ext_management_system => ems) }
end

it "keeps a single vm target" do
refresher = described_class.new([vm])
refresher.preprocess_targets

expect(refresher.targets_by_ems_id[vm.ext_management_system.id]).to eq([vm])
end

it "does a full refresh with an EMS and a VM" do
refresher = described_class.new([vm, ems])
refresher.preprocess_targets

expect(refresher.targets_by_ems_id[vm.ext_management_system.id]).to eq([ems])
end

it "does a full refresh with a lot of targets" do
refresher = described_class.new(lots_of_vms)
refresher.preprocess_targets

expect(refresher.targets_by_ems_id[ems.id]).to eq([ems])
end
end
end
end

0 comments on commit 71524f8

Please sign in to comment.