From c6822d3f9cf2731ad69114ee6360abe27ade7f87 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Wed, 19 Jun 2019 11:44:25 -0400 Subject: [PATCH] Don't create tasks for things that are already retired --- app/models/service_retire_task.rb | 1 + spec/models/service_retire_task_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+) 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