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

Revert "Remove unused Service::RetirementManagement.retire_service_resources method" #19417

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
13 changes: 13 additions & 0 deletions app/models/service/retirement_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ def before_retirement
children.each(&:retire_now)
end

def retire_service_resources
# TODO: delete me per https://github.com/ManageIQ/manageiq/pull/16933#discussion_r175805070
return
direct_service_children.each(&:retire_service_resources)

service_resources.each do |sr|
if sr.resource.respond_to?(:retire_now)
$log.info("Retiring service resource for service: #{name} resource ID: #{sr.id}")
sr.resource.retire_now(retirement_requester)
end
end
end

def automate_retirement_entrypoint
r = service_template.resource_actions.detect { |ra| ra.action == 'Retirement' } unless service_template.nil?
state_machine_entry_point = r.try(:fqname)
Expand Down
29 changes: 29 additions & 0 deletions spec/models/service/retirement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,35 @@
expect(@service.retires_on).to eq(options[:date])
end

it "#retire_service_resources" do
ems = FactoryBot.create(:ems_vmware, :zone => @server.zone)
vm = FactoryBot.create(:vm_vmware, :ems_id => ems.id)
@service << vm
expect(@service.service_resources.size).to eq(1)
expect(@service.service_resources.first.resource).to_not receive(:retire_now)
@service.retire_service_resources
end

it "#retire_service_resources should get service's retirement_requester" do
ems = FactoryBot.create(:ems_vmware, :zone => @server.zone)
vm = FactoryBot.create(:vm_vmware, :ems_id => ems.id)
userid = 'freddy'
@service.update(:retirement_requester => userid)
@service << vm
expect(@service.service_resources.size).to eq(1)
expect(@service.service_resources.first.resource).to_not receive(:retire_now).with(userid)
@service.retire_service_resources
end

it "#retire_service_resources should get service's nil retirement_requester" do
ems = FactoryBot.create(:ems_vmware, :zone => @server.zone)
vm = FactoryBot.create(:vm_vmware, :ems_id => ems.id)
@service << vm
expect(@service.service_resources.size).to eq(1)
expect(@service.service_resources.first.resource).to_not receive(:retire_now).with(nil)
@service.retire_service_resources
end

it "#finish_retirement" do
message = "Service: [#{@service.name}], Retires On: [#{Time.zone.now.strftime("%x %R %Z")}], has been retired"
expect(@service).to receive(:raise_audit_event).with("service_retired", message, nil)
Expand Down