Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds task to subservices for correct retirement completion #17912

Merged
merged 2 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions app/models/service_retire_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,43 @@ def after_request_task_create
update_attributes(:description => get_description)
parent_svc = Service.find_by(:id => options[:src_ids])
_log.info("- creating service tasks for service <#{self.class.name}:#{id}>")

create_retire_subtasks(parent_svc)
create_retire_subtasks(parent_svc, self)
end

def create_retire_subtasks(parent_service)
parent_service.direct_service_children.each { |child| create_retire_subtasks(child) }
def create_retire_subtasks(parent_service, parent_task)
parent_service.service_resources.collect do |svc_rsc|
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)
# which should be extended to retirement as part of later work
# svc_rsc.resource_type != "ServiceTemplate" || self.class.include_service_template?(self, srr.id, parent_service)
nh = attributes.except("id", "created_on", "updated_on", "type", "state", "status", "message")

# TODO: use changes here: https://github.com/ManageIQ/manageiq/pull/17996 to not have to filter by col_names
# 17996 removes virtual attributes from @attrs list
nh = attributes.slice(*self.class.column_names).except!("id", "created_on", "updated_on", "type", "state", "status", "message")
nh['options'] = options.except(:child_tasks)
# Initial Options[:dialog] to an empty hash so we do not pass down dialog values to child services tasks
nh['options'][:dialog] = {}
new_task = create_task(svc_rsc, parent_service, nh)
new_task = create_task(svc_rsc, parent_service, nh, parent_task)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u The nh has is pulling in virtual columns which is causing the test failure:

Failure/Error: new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh)
ActiveModel::MissingAttributeError:
  can't write unknown attribute `href_slug`
# ./app/models/service_retire_task.rb:53:in `create_task'
# ./app/models/service_retire_task.rb:43:in `block in create_retire_subtasks'
...

You can fix this by excluding the virtual columns on line 39 using self.class.virtual_attribute_names

nh = attributes.except("id", "created_on", "updated_on", "type", "state", "status", "message", *self.class.virtual_attribute_names)

create_retire_subtasks(svc_rsc.resource, new_task) if svc_rsc.resource.kind_of?(Service)
new_task.after_request_task_create
miq_request.miq_request_tasks << new_task
new_task.deliver_to_automate
new_task
new_task.tap(&:deliver_to_automate)
end.compact!
end

def create_task(svc_rsc, parent_service, nh)
new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh)
new_task.options.merge!(
:src_id => svc_rsc.resource.id,
:service_resource_id => svc_rsc.id,
:parent_service_id => parent_service.id,
:parent_task_id => id,
)
new_task.source = svc_rsc.resource
new_task.request_type = svc_rsc.resource.type.demodulize.downcase + "_retire"
new_task.save!
new_task
def create_task(svc_rsc, parent_service, nh, parent_task)
(svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh).tap do |task|
task.options.merge!(
:src_id => svc_rsc.resource.id,
:service_resource_id => svc_rsc.id,
:parent_service_id => parent_service.id,
:parent_task_id => parent_task.id,
)
task.request_type = svc_rsc.resource.type.demodulize.downcase + "_retire"
task.source = svc_rsc.resource
parent_task.miq_request_tasks << task
task.save!
end
end
end
4 changes: 2 additions & 2 deletions spec/models/service_retire_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "Service", :service_id => service_c1.id, :resource_id => service_c1.id)

@service_retire_task.after_request_task_create
expect(VmRetireTask.count).to eq(4)
expect(VmRetireTask.all.pluck(:message)).to eq(["Automation Starting", "Automation Starting", "Automation Starting", "Automation Starting"])
expect(VmRetireTask.count).to eq(2)
expect(VmRetireTask.all.pluck(:message)).to eq(["Automation Starting", "Automation Starting"])
expect(ServiceRetireTask.count).to eq(1)
expect(ServiceRetireRequest.count).to eq(1)
end
Expand Down