diff --git a/app/models/service_retire_task.rb b/app/models/service_retire_task.rb index 1ce69626cf9..c9da2b47187 100644 --- a/app/models/service_retire_task.rb +++ b/app/models/service_retire_task.rb @@ -36,6 +36,7 @@ def after_request_task_create def create_retire_subtasks(parent_service, parent_task) parent_service.service_resources.collect do |svc_rsc| + next if svc_rsc.resource.respond_to?(:retired?) && svc_rsc.resource.retired? next unless svc_rsc.resource.try(:retireable?) # TODO: the next line deals with the filtering for provisioning # (https://github.com/ManageIQ/manageiq/blob/3921e87915b5a69937b9d4a70bb24ab71b97c165/app/models/service_template/filter.rb#L5) diff --git a/spec/models/service_retire_task_spec.rb b/spec/models/service_retire_task_spec.rb index 9ff4cbb9fb0..30a98f2c4b7 100644 --- a/spec/models/service_retire_task_spec.rb +++ b/spec/models/service_retire_task_spec.rb @@ -144,6 +144,15 @@ expect(VmRetireTask.count).to eq(1) expect(ServiceRetireTask.count).to eq(1) end + + it "does not create vm retire subtask for retired vm" do + service.add_resource!(FactoryBot.create(:vm_openstack, :retired => true)) + service_retire_task.after_request_task_create + + expect(service_retire_task.description).to eq("Service Retire for: #{service.name} - ") + expect(VmRetireTask.count).to eq(0) + expect(ServiceRetireTask.count).to eq(1) + end end context "bundled service retires all children" do