Skip to content

Commit

Permalink
Merge pull request ManageIQ#19417 from chessbyte/revert_22531a23451af…
Browse files Browse the repository at this point in the history
…1e90b1a58523e0fe75794f4d39d

Revert "Remove unused Service::RetirementManagement.retire_service_resources method"
  • Loading branch information
Fryguy authored Oct 18, 2019
2 parents 6006ece + b2d9ef9 commit 17f5175
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
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

0 comments on commit 17f5175

Please sign in to comment.