Skip to content

Commit

Permalink
Merge pull request #14079 from zeari/enterprize_rate_parent
Browse files Browse the repository at this point in the history
Enterprise rate parent for containers chargeback
  • Loading branch information
gtanzillo authored Feb 27, 2017
2 parents ed573c0 + 920be37 commit 0b91241
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/metric/chargeback_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def parents_determining_rate
when VmOrTemplate.name
(resource_parents + [MiqEnterprise.my_enterprise]).compact
when ContainerProject.name
[parent_ems].compact
[parent_ems, MiqEnterprise.my_enterprise].compact
when Container.name
[parent_ems]
end
Expand Down
27 changes: 27 additions & 0 deletions spec/models/chargeback_container_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,31 @@
expect(subject.fixed_compute_metric).to eq(@metric_size / 2)
end
end

context "gets rate from enterprise" do
let(:options) { base_options.merge(:interval => 'monthly', :entity_id => @project.id, :tag => nil) }
let(:miq_enterprise) { FactoryGirl.create(:miq_enterprise) }

before do
add_metric_rollups_for(@project, month_beginning...month_end, 24.hours, metric_rollup_params)

metric_rollup_params[:cpu_usage_rate_average] = 0.0
metric_rollup_params[:derived_memory_used] = 0.0

add_metric_rollups_for(@project, (month_beginning + 12.hours)...month_end, 24.hours, metric_rollup_params, nil)

@metric_size = @project.metric_rollups.size

temp = {:cb_rate => chargeback_rate, :object => miq_enterprise}
ChargebackRate.set_assignments(:compute, [temp])
end

subject { ChargebackContainerProject.build_results_for_report_ChargebackContainerProject(options).first.first }

it "fixed_compute" do
# .to be_within(0.01) is used since theres a float error here
expect(subject.fixed_compute_1_cost).to be_within(0.01).of(hourly_rate * hours_in_month)
expect(subject.fixed_compute_metric).to eq(@metric_size / 2)
end
end
end

0 comments on commit 0b91241

Please sign in to comment.