Skip to content

Commit

Permalink
Added active provisions to quota count.
Browse files Browse the repository at this point in the history
Modified used method to count active provisions for quota.
Added log messages to method.

https://bugzilla.redhat.com/show_bug.cgi?id=1456819

Log messages display counts and type of quota.
Sample log messages below:

<AEMethod used> Quota Used: {:cpu=>373, :memory=>922780434432, :vms=>141, :storage=>9111136632832, :provisioned_storage=>10033917067264}

<AEMethod used> Quota active_provisions_by_tenant: {:cpu=>1, :memory=>1073741824, :vms=>1, :storage=>44023414784, :provisioned_storage=>0}
<AEMethod used> Quota Totals: {:cpu=>374, :memory=>923854176256, :vms=>142, :storage=>9155160047616, :provisioned_storage=>10033917067264}

<AEMethod used> Quota Used: {:cpu=>1, :memory=>1073741824, :vms=>1, :storage=>8589934592, :provisioned_storage=>9663676416}
<AEMethod used> Quota active_provisions_by_group: {:cpu=>1, :memory=>1073741824, :vms=>1, :storage=>44023414784, :provisioned_storage=>0}
<AEMethod used> Quota Totals: {:cpu=>2, :memory=>2147483648, :vms=>2, :storage=>52613349376, :provisioned_storage=>9663676416}

<AEMethod used> Quota Used: {:cpu=>1, :memory=>1073741824, :vms=>1, :storage=>8589934592, :provisioned_storage=>9663676416}
<AEMethod used> Quota active_provisions_by_owner: {:cpu=>0, :memory=>0, :vms=>0, :storage=>0, :provisioned_storage=>0}
<AEMethod used> Quota Totals: {:cpu=>1, :memory=>1073741824, :vms=>1, :storage=>8589934592, :provisioned_storage=>9663676416}
  • Loading branch information
billfitzgerald0120 committed Oct 11, 2017
1 parent ae2736d commit 5d4c745
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Description: calculate entity used quota values
#
Expand All @@ -19,7 +20,13 @@ def main
private

def used(quota_source)
@handle.root['quota_used'] = consumption(quota_source)
quota_used = consumption(quota_source)
@handle.log("info", "Quota Used: #{quota_used.inspect}")

quota_active = active_provision_counts
@handle.log("info", "Quota #{active_method_name}: #{quota_active.inspect}")

merge_counts(quota_used, quota_active)
end

def quota_source
Expand All @@ -36,6 +43,26 @@ def consumption(source)
:provisioned_storage => source.provisioned_storage
}
end

def active_method_name
quota_source = @handle.root['quota_source_type'].downcase
source = quota_source == 'user' ? 'owner' : quota_source
"active_provisions_by_#{source}".to_sym
end

def active_provision_counts
active_provisions = @handle.root['miq_request'].check_quota(active_method_name)
{:cpu => active_provisions[:cpu],
:memory => active_provisions[:memory],
:vms => active_provisions[:count],
:storage => active_provisions[:storage],
:provisioned_storage => 0}
end

def merge_counts(quota_used, quota_active)
@handle.root['quota_used'] = quota_used.merge(quota_active) { |_key, val1, val2| val1 + val2 }
@handle.log("info", "Quota Totals: #{@handle.root['quota_used'].inspect}")
end
end
end
end
Expand Down
26 changes: 0 additions & 26 deletions spec/automation/unit/method_validation/calculate_used_spec.rb

This file was deleted.

Expand Up @@ -6,15 +6,25 @@
let!(:model) { setup_model }
let(:root_hash) do
{
'miq_provision_request' => @miq_provision_request,
'miq_request' => @miq_provision_request,
'miq_provision_request' => svc_miq_request,
'miq_request' => svc_miq_request,
'quota_source' => quota_source,
'quota_source_type' => quota_source_type
}
end

let(:svc_miq_request) { MiqAeMethodService::MiqAeServiceMiqRequest.find(@miq_provision_request.id) }

let(:counts_hash) do
{:storage => 1_000_000, :cpu => 0, :vms => 4, :memory => 1_073_741_824}
{:storage => 1_000_000, :cpu => 0, :vms => 1, :memory => 1_073_741_824}
end

let(:active_counts_hash) do
{:storage => 2_000_000, :cpu => 8, :count => 9, :memory => 6_000_000_000}
end

let(:result_counts_hash) do
{:storage => 3_000_000, :cpu => 8, :vms => 10, :memory => 7_073_741_824}
end

let(:root_object) do
Expand All @@ -31,33 +41,41 @@

shared_examples_for "used" do
it "check" do
expect(svc_miq_request).to receive(:check_quota).with(active_method).and_return(active_counts_hash)
described_class.new(ae_service).main
expect(ae_service.root['quota_used']).to include(counts_hash)
expect(ae_service.root['quota_used']).to include(result_counts_hash)
end
end

context "returns ok for tenant counts" do
let(:quota_source) { @tenant }
let(:quota_source) { MiqAeMethodService::MiqAeServiceTenant.find(@tenant.id) }
let(:quota_source_type) { 'tenant' }
let(:active_method) { 'active_provisions_by_tenant'.to_sym }

it_behaves_like "used"
end

context "returns ok for user counts" do
let(:quota_source) { @tenant }
let(:quota_source) { MiqAeMethodService::MiqAeServiceUser.find(@user.id) }
let(:quota_source_type) { 'user' }
let(:active_method) { 'active_provisions_by_owner'.to_sym }

it_behaves_like "used"
end

context "returns ok for group counts" do
let(:quota_source) { @tenant }
let(:quota_source) { MiqAeMethodService::MiqAeServiceMiqGroup.find(@miq_group.id) }
let(:quota_source_type) { 'group' }
let(:active_method) { 'active_provisions_by_group'.to_sym }

it_behaves_like "used"
end

context "returns error " do
let(:quota_source_type) { nil }
let(:quota_source) { nil }
let(:errormsg) { 'ERROR - quota_source not found' }

it "when no quota source" do
expect { described_class.new(ae_service).main }.to raise_error(errormsg)
end
Expand Down

0 comments on commit 5d4c745

Please sign in to comment.