From 541bf15ec244bc033bbdc7b3ca40c710ceec74b4 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Tue, 20 Aug 2019 16:36:52 -0400 Subject: [PATCH] Merge pull request #19143 from lfu/dup_service_retire_request_18558 Service retirement request should be per region. (cherry picked from commit 3ab4626c51447481724d8b720c9e83c0ee788a9d) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1767824 --- app/models/miq_schedule_worker/jobs.rb | 1 + app/models/retirement_manager.rb | 7 +++++-- spec/models/retirement_manager_spec.rb | 9 ++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/miq_schedule_worker/jobs.rb b/app/models/miq_schedule_worker/jobs.rb index bd56ac789d4..e0a731dcd28 100644 --- a/app/models/miq_schedule_worker/jobs.rb +++ b/app/models/miq_schedule_worker/jobs.rb @@ -30,6 +30,7 @@ def job_check_jobs_for_timeout def retirement_check queue_work_on_each_zone(:class_name => 'RetirementManager', :method_name => 'check') + queue_work(:class_name => 'RetirementManager', :method_name => 'check_per_region', :zone => nil) end def host_authentication_check_schedule diff --git a/app/models/retirement_manager.rb b/app/models/retirement_manager.rb index 9b5883f5576..270164346d9 100644 --- a/app/models/retirement_manager.rb +++ b/app/models/retirement_manager.rb @@ -1,14 +1,17 @@ class RetirementManager def self.check ems_ids = MiqServer.my_server.zone.ext_management_system_ids - [OrchestrationStack, Vm, Service].flat_map do |i| + [OrchestrationStack, Vm].flat_map do |i| instances = not_retired_with_ems(i, ems_ids) instances.each(&:retirement_check) end end + def self.check_per_region + Service.scheduled_to_retire.each(&:retirement_check) + end + def self.not_retired_with_ems(model, ems_ids) - return model.scheduled_to_retire unless model.column_names.include?('ems_id') # Service not assigned to ems_ids model.scheduled_to_retire.where(:ems_id => ems_ids) end private_class_method :not_retired_with_ems diff --git a/spec/models/retirement_manager_spec.rb b/spec/models/retirement_manager_spec.rb index 1302e371baf..b0fc89fe56c 100644 --- a/spec/models/retirement_manager_spec.rb +++ b/spec/models/retirement_manager_spec.rb @@ -8,10 +8,17 @@ FactoryBot.create(:orchestration_stack, :retired => true) vm = FactoryBot.create(:vm, :retires_on => Time.zone.today + 1.day, :ems_id => ems.id) FactoryBot.create(:vm, :retired => true) + + expect(RetirementManager.check).to match_array([orchestration_stack, vm]) + end + end + + describe "#check_per_region" do + it "with retirement date, runs retirement checks" do service = FactoryBot.create(:service, :retires_on => Time.zone.today + 1.day) FactoryBot.create(:service, :retired => true) - expect(RetirementManager.check).to match_array([orchestration_stack, vm, service]) + expect(RetirementManager.check_per_region).to match_array([service]) end end end