Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only run preprocess_targets_manager_refresh when doing graph refresh and add specs #18513

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is handled down here

_log.info("Defaulting to full refresh for EMS: [#{ems.name}], id: [#{ems.id}].") if targets.length > 1
so this isn't needed anymore

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