Skip to content

Commit

Permalink
Merge pull request ManageIQ#16277 from lpichler/allow-dynamic-storage…
Browse files Browse the repository at this point in the history
…-types-in-chargeback-report

Offer dynamic storage types in chargeback report
  • Loading branch information
gtanzillo authored Oct 26, 2017
2 parents 7dcddfa + 587e042 commit 41fdc2b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/chargeback_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class ChargebackVm < Chargeback
:total_cost => :float,
)

def self.refresh_dynamic_metric_columns
dynamic_columns = CloudVolume.volume_types.each_with_object({}) do |volume_type, result|
[:metric, :cost].collect do |type|
result["storage_allocated_#{volume_type || 'unclassified'}_#{type}"] = :integer
end
end

set_columns_hash(dynamic_columns)
end

def self.build_results_for_report_ChargebackVm(options)
# Options: a hash transformable to Chargeback::ReportOptions

Expand Down
1 change: 1 addition & 0 deletions lib/miq_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ def self.reporting_available_fields(model, interval = nil)
model_details(model, :include_model => false, :include_tags => true, :interval => interval)
elsif Chargeback.db_is_chargeback?(model)
cb_model = Chargeback.report_cb_model(model)
model.constantize.try(:refresh_dynamic_metric_columns)
md = model_details(model, :include_model => false, :include_tags => true).select do |c|
c.last.ends_with?(*ReportController::Reports::Editor::CHARGEBACK_ALLOWED_FIELD_SUFFIXES)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/models/chargeback_vm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@
let(:start_time) { report_run_time - 17.hours }
let(:finish_time) { report_run_time - 14.hours }

let(:cloud_volume) { FactoryGirl.create(:cloud_volume_openstack) }

it 'contains also columns with sub_metric(from cloud_volume)' do
skip('this feature needs to be added to new chargeback rating') if Settings.new_chargeback

cloud_volume_type_chargeback_colums = []
%w(metric cost).each do |key|
cloud_volume_type_chargeback_colums << "storage_allocated_#{cloud_volume.volume_type}_#{key}"
end

described_class.refresh_dynamic_metric_columns

expect(cloud_volume_type_chargeback_colums & described_class.attribute_names).to match_array(cloud_volume_type_chargeback_colums)
end

before do
add_metric_rollups_for(@vm1, start_time...finish_time, 1.hour, metric_rollup_params)
end
Expand Down

0 comments on commit 41fdc2b

Please sign in to comment.