Skip to content

Commit

Permalink
Merge pull request #19101 from yrudman/make-chargeback-for-service-re…
Browse files Browse the repository at this point in the history
…gion-aware

Fix: make chargeback generation for service to be region aware and do not generate for retired service
(cherry picked from commit 3bcda04)

https://bugzilla.redhat.com/show_bug.cgi?id=1763862
  • Loading branch information
bdunne authored and simaishi committed Oct 21, 2019
1 parent 0224c07 commit c8b91c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 16 additions & 1 deletion spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8b91c3

Please sign in to comment.