From f5a156b6583ca757b84e372455df7b1c5b95e368 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=1764197 --- app/models/miq_schedule_worker/jobs.rb | 1 + app/models/retirement_manager.rb | 7 +++++-- spec/models/retirement_manager_spec.rb | 13 ++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/models/miq_schedule_worker/jobs.rb b/app/models/miq_schedule_worker/jobs.rb index 6db46c8a24c..f23da9f3c4f 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 9ee5529c66b..17075d02ee5 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 - [LoadBalancer, OrchestrationStack, Vm, Service].flat_map do |i| + [LoadBalancer, 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 e698e5386fd..6e31994bd29 100644 --- a/spec/models/retirement_manager_spec.rb +++ b/spec/models/retirement_manager_spec.rb @@ -10,10 +10,17 @@ FactoryGirl.create(:orchestration_stack, :retired => true) vm = FactoryGirl.create(:vm, :retires_on => Time.zone.today + 1.day, :ems_id => ems.id) FactoryGirl.create(:vm, :retired => true) - service = FactoryGirl.create(:service, :retires_on => Time.zone.today + 1.day) - FactoryGirl.create(:service, :retired => true) - expect(RetirementManager.check).to match_array([load_balancer, orchestration_stack, vm, service]) + expect(RetirementManager.check).to match_array([load_balancer, 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_per_region).to match_array([service]) end end end