Skip to content

Commit

Permalink
Create retire subtasks for multiple services
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jun 24, 2019
1 parent fff2760 commit c6b874e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/models/service_retire_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def task_active

def after_request_task_create
update_attributes(:description => get_description)
parent_svc = Service.find_by(:id => options[:src_ids])
if create_subtasks?(parent_svc)
_log.info("- creating service subtasks for service task <#{self.class.name}:#{id}>, service <#{parent_svc.id}>")
create_retire_subtasks(parent_svc, self)
Service.where(id: options[:src_ids]).each do |parent_svc|
if create_subtasks?(parent_svc)
_log.info("- creating service subtasks for service task <#{self.class.name}:#{id}>, service <#{parent_svc.id}>")
create_retire_subtasks(parent_svc, self)
end
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/models/service_retire_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@
expect(VmRetireTask.count).to eq(0)
expect(ServiceRetireTask.count).to eq(1)
end

context "multiple service retirement" do
it "creates multiple retire subtasks" do
s1 = FactoryBot.create(:service)
s2 = FactoryBot.create(:service)
s1.add_resource!(FactoryBot.create(:vm_openstack))
s2.add_resource!(FactoryBot.create(:vm_openstack))

service_retire_task1 = FactoryBot.create(:service_retire_task, :source => s1, :miq_request => miq_request, :options => {:src_ids => [s1.id, s2.id] })
service_retire_task1.after_request_task_create

expect(VmRetireTask.count).to eq(2)
end
end
end

context "bundled service retires all children" do
Expand Down

0 comments on commit c6b874e

Please sign in to comment.