Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: make chargeback generation for service to be region aware and do not generate for retired service #19101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,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 @@ -425,15 +425,30 @@
end

describe ".queue_chargeback_reports" do
it "queue request to generate chargeback report for each service" do
before do
@service_c1 = FactoryBot.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