Skip to content

Commit

Permalink
Check all costs fields for relevancy for the report
Browse files Browse the repository at this point in the history
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1576101

Manual backport of ManageIQ#17387

If a user asks only for some of the fields (memory cost) in a chargeback report
and they didn't request specific ones (memory allocated cost), we would skip
calculating the memory cost because we thought it wasn't relevant.  We need to
check all cost fields to see if they're relevant for the requested fields in the
report.
  • Loading branch information
jrafanie authored and d-m-u committed Jun 6, 2018
1 parent e6b7894 commit 27322e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/chargeback_rate_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChargebackRateDetail < ApplicationRecord

def charge(relevant_fields, consumption)
result = {}
if (relevant_fields & [metric_key, cost_keys[0]]).present?
if (relevant_fields & ([metric_key] + cost_keys)).present?
metric_value, cost = metric_and_cost_by(consumption)
if !consumption.chargeback_fields_present && chargeable_field.fixed?
cost = 0
Expand Down
11 changes: 11 additions & 0 deletions spec/models/chargeback_vm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@
expect(subject.storage_cost).to eq(subject.storage_allocated_cost + subject.storage_used_cost)
end

context "only memory_cost instead of all report columns" do
let(:options) { base_options.merge(:interval => 'daily', :report_cols => %w(memory_cost)) }

it "brings in relevant fields needed for calculation" do
memory_allocated_cost = memory_available * hourly_rate * hours_in_day
used_metric = used_average_for(:derived_memory_used, hours_in_day, @vm1)
memory_used_cost = used_metric * hourly_rate * hours_in_day
expect(subject.memory_cost).to eq(memory_allocated_cost + memory_used_cost)
end
end

context "fixed rates" do
let(:hourly_fixed_rate) { 10.0 }

Expand Down

0 comments on commit 27322e0

Please sign in to comment.