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

Properly generate report yml include with virtual attributes #18205

Merged
merged 1 commit into from
Nov 29, 2018
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
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
Copy link
Member

Choose a reason for hiding this comment

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

My question in #18205 (comment) is really asking, can we remove include.presence from this section entirely?

Copy link
Member Author

@kbrock kbrock Nov 15, 2018

Choose a reason for hiding this comment

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

users tend to copy paste the report templates, and most of the report views have a blank include block. Of our 180 reports, 95 are a blank hash.

$ ag -l '^include:\n\n' product/views/ | wc -l
      95
$ ag -l '^include:\n' product/views/ | wc -l
     170
$ find product/views | wc -l
     180

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