From c97e7071fa850ed6ead756654c9bef85f50627b6 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Thu, 15 Nov 2018 11:24:21 -0500 Subject: [PATCH] Properly generate report include with va If a report yml file has virtual attributes in the cols and no :include it was not generating the proper includes hash. Now it is generating the includes from :col_order or :include regardless of whether virtual attributes are in the col (or col_order) --- app/models/miq_report/generator.rb | 11 +------ spec/models/miq_report/generator_spec.rb | 38 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/app/models/miq_report/generator.rb b/app/models/miq_report/generator.rb index a196b5c85dc2..08bbb54d0cb6 100644 --- a/app/models/miq_report/generator.rb +++ b/app/models/miq_report/generator.rb @@ -81,16 +81,7 @@ def table2class(table) end def get_include_for_find - (include_as_hash.presence || invent_includes).deep_merge(include_for_find || {}).presence - end - - def invent_includes - return {} unless col_order - col_order.each_with_object({}) do |col, ret| - next unless col.include?(".") - *rels, _col = col.split(".") - rels.inject(ret) { |h, rel| h[rel.to_sym] ||= {} } unless col =~ /managed\./ - end + include_as_hash(include.presence || invent_report_includes).deep_merge(include_for_find || {}).presence end # would like this format to go away diff --git a/spec/models/miq_report/generator_spec.rb b/spec/models/miq_report/generator_spec.rb index c061aab64e99..7d7f2758a511 100644 --- a/spec/models/miq_report/generator_spec.rb +++ b/spec/models/miq_report/generator_spec.rb @@ -163,4 +163,42 @@ def create_rollup(host, profile, used_mem) expect(rpt.cols_for_report).to match_array(%w(vendor host.name host.hostname)) end end + + # It is private, but testing that it is able to take a report file + # and properly generate the necessary includes + describe "#get_include_for_find" do + it "returns nil with empty include" do + rpt = MiqReport.new(:db => "VmOrTemplate", + :include => {}) + expect(rpt.get_include_for_find).to be_nil + end + + # note: virtual attribute is_evm_appliance is included + # note: virtual attribute v_total_snapshots is not included (because it is sql friendly) + it "uses include and include_as_hash" do + rpt = MiqReport.new(:db => "VmOrTemplate", + :cols => %w(name platform v_total_snapshots), + :include => { :host => {:columns => %w(name)}, :storage => {:columns => %w(name)} }, + :include_for_find => {:snapshots => {}}) + expect(rpt.get_include_for_find).to eq(:platform => {}, :host => {}, :storage => {}, :snapshots => {}) + end + + it "uses col, col_order, and virtual attributes and ignores empty include" do + # it also allows cols to override col_order for requesting extra columns + rpt = MiqReport.new(:db => "VmOrTemplate", + :include => {}, + :cols => %w(name num_cpu v_total_snapshots), + :col_order => %w(name v_total_snapshots host.name storage.name), + :include_for_find => {:snapshots => {}}) + expect(rpt.get_include_for_find).to eq(:num_cpu => {}, :host => {}, :storage => {}, :snapshots => {}) + end + + it "uses col_order and virtual attributes" do + rpt = MiqReport.new(:db => "VmOrTemplate", + :include => {}, + :col_order => %w(name num_cpu v_total_snapshots host.name storage.name), + :include_for_find => {:snapshots => {}}) + expect(rpt.get_include_for_find).to eq(:num_cpu => {}, :host => {}, :storage => {}, :snapshots => {}) + end + end end