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

Service retirement request should be per region. #19143

Merged
merged 1 commit into from
Aug 20, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
[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
Expand Down
9 changes: 8 additions & 1 deletion spec/models/retirement_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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