Skip to content

Commit

Permalink
Properly generate report include with va
Browse files Browse the repository at this point in the history
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)

leaving invent_includes around for report_sanity_checker
  • Loading branch information
kbrock committed Nov 19, 2018
1 parent f0f22c3 commit 1d26993
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
9 changes: 2 additions & 7 deletions app/models/miq_report/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,11 @@ def table2class(table)
end

def get_include_for_find
(include_as_hash.presence || invent_includes).deep_merge(include_for_find || {}).presence
include_as_hash(include.presence || invent_report_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(invent_report_includes)
end

# would like this format to go away
Expand Down
46 changes: 46 additions & 0 deletions spec/models/miq_report/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,50 @@ def create_rollup(host, profile, used_mem)
expect(rpt.cols_for_report).to match_array(%w(vendor host.name host.hostname))
end
end

describe "#get_include_for_find (private)" do
it "returns nil with empty include" do
rpt = MiqReport.new(:db => "VmOrTemplate",
:include => {})
expect(rpt.get_include_for_find).to be_nil
end

it "includes virtual_includes from virtual_attributes that are not sql friendly" do
rpt = MiqReport.new(:db => "VmOrTemplate",
:cols => %w(name platform))
expect(rpt.get_include_for_find).to eq(:platform => {})
end

it "does not include sql friendly virtual_attributes" do
rpt = MiqReport.new(:db => "VmOrTemplate",
:cols => %w(name v_total_snapshots))
expect(rpt.get_include_for_find).to be_nil
end

it "uses include and include_as_hash" do
rpt = MiqReport.new(:db => "VmOrTemplate",
:cols => %w(name platform),
: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),
:col_order => %w(name 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 host.name storage.name),
:include_for_find => {:snapshots => {}})
expect(rpt.get_include_for_find).to eq(:num_cpu => {}, :host => {}, :storage => {}, :snapshots => {})
end
end
end

0 comments on commit 1d26993

Please sign in to comment.