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)
  • Loading branch information
kbrock committed Nov 15, 2018
1 parent 391cf5d commit c97e707
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
11 changes: 1 addition & 10 deletions app/models/miq_report/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 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,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

0 comments on commit c97e707

Please sign in to comment.