From c8b91c34881e53a735bca4cd112b91793a0208e1 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 8 Aug 2019 15:35:13 -0400 Subject: [PATCH] Merge pull request #19101 from yrudman/make-chargeback-for-service-region-aware Fix: make chargeback generation for service to be region aware and do not generate for retired service (cherry picked from commit 3bcda0474cb200acb526c8ea3be5974700a021e2) https://bugzilla.redhat.com/show_bug.cgi?id=1763862 --- app/models/service.rb | 4 ++-- spec/models/service_spec.rb | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/models/service.rb b/app/models/service.rb index bf1b3f9039a..786660067b8 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -390,8 +390,8 @@ def chargeback_report end def self.queue_chargeback_reports(options = {}) - Service.all.each do |s| - s.queue_chargeback_report_generation(options) unless s.vms.empty? + Service.in_my_region.each do |s| + s.queue_chargeback_report_generation(options) unless s.vms.empty? || s.retired end end diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index f21f10d7278..739648afd2d 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -429,15 +429,30 @@ end describe ".queue_chargeback_reports" do - it "queue request to generate chargeback report for each service" do + before do @service_c1 = FactoryGirl.create(:service, :service => @service) @service_c1.name = "Test_Service_2" @service_c1 << @vm1 @service_c1.save + end + it "queue request to generate chargeback report for each service" do expect(MiqQueue).to receive(:put).twice described_class.queue_chargeback_reports end + + it "queue request to generate chargeback report only in service's region" do + allow(Service).to receive(:in_my_region).and_return([@service_c1]) + expect(MiqQueue).to receive(:put).once + described_class.queue_chargeback_reports + end + + it "does not queue request to generate chargeback report if service retired" do + @service_c1.update(:retired => true) + allow(Service).to receive(:in_my_region).and_return([@service_c1]) + expect(MiqQueue).not_to receive(:put) + described_class.queue_chargeback_reports + end end describe "#chargeback_report_name" do