Skip to content

Commit

Permalink
Fix metering report for resources without rollups
Browse files Browse the repository at this point in the history
  • Loading branch information
lpichler committed Aug 14, 2018
1 parent 262bef6 commit 486c3d3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/chargeback/consumption_without_rollups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def current_value(metric, sub_metric = nil)
end
alias avg current_value
alias max current_value
alias sum current_value
alias sum_of_maxes_from_grouped_values current_value
private :current_value
end
Expand Down
43 changes: 43 additions & 0 deletions spec/models/metering_vm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,49 @@
:parent_storage_id => storage.id,
}
end
context 'without metric rollups' do
let(:cores) { 7 }
let(:mem_mb) { 1777 }
let(:disk_gb) { 7 }
let(:disk_b) { disk_gb * 1024**3 }
let(:metering_used_hours) { 24 }

let(:hardware) do
FactoryGirl.create(:hardware,
:cpu_total_cores => cores,
:memory_mb => mem_mb,
:disks => [FactoryGirl.create(:disk, :size => disk_b)])
end

context 'for SCVMM (hyper-v)' do
before do
cat = FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true)
FactoryGirl.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id)
@tag = Tag.find_by(:name => "/managed/environment/prod")
end

let!(:vm1) do
vm = FactoryGirl.create(:vm_microsoft, :hardware => hardware, :created_on => report_run_time - 1.day)
vm.tag_with(@tag.name, :ns => '*')
vm
end

let(:options) { base_options.merge(:interval => 'daily', :tag => '/managed/environment/prod') }

subject { MeteringVm.build_results_for_report_ChargebackVm(options).first.first }

it 'fixed compute is calculated properly' do
expect(subject.fixed_compute_metric).to eq(1) # One day of fixed compute metric
end

it 'allocated metrics are calculated properly' do
expect(subject.memory_allocated_metric).to eq(mem_mb)
expect(subject.metering_used_metric).to eq(0) # metric rollups are not used
expect(subject.cpu_allocated_metric).to eq(cores)
expect(subject.storage_allocated_metric).to eq(disk_b)
end
end
end

context 'monthly' do
subject { MeteringVm.build_results_for_report_MeteringVm(options).first.first }
Expand Down

0 comments on commit 486c3d3

Please sign in to comment.