diff --git a/app/models/service_retire_task.rb b/app/models/service_retire_task.rb index 88d323139ce..6704d376061 100644 --- a/app/models/service_retire_task.rb +++ b/app/models/service_retire_task.rb @@ -37,6 +37,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 0e35521db58..bca214ffd24 100644 --- a/spec/models/service_retire_task_spec.rb +++ b/spec/models/service_retire_task_spec.rb @@ -163,6 +163,15 @@ it "returns a description based upon the source service name" do expect(ServiceRetireTask.get_description(miq_request)).to eq("Service Retire for: #{service.name}") 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