Skip to content

Commit

Permalink
Merge pull request #19143 from lfu/dup_service_retire_request_18558
Browse files Browse the repository at this point in the history
Service retirement request should be per region.

(cherry picked from commit 3ab4626)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1764197
  • Loading branch information
bdunne authored and simaishi committed Oct 22, 2019
1 parent 85e92a1 commit f5a156b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/models/miq_schedule_worker/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions app/models/retirement_manager.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 10 additions & 3 deletions spec/models/retirement_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f5a156b

Please sign in to comment.