-
Notifications
You must be signed in to change notification settings - Fork 897
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
Fixing subservice task creation for service bundles #18283
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ def update_and_notify_parent(*args) | |
end | ||
|
||
def task_finished | ||
update_attributes(:status => status == 'Ok' ? 'Completed' : 'Failed') | ||
if status != 'Ok' | ||
update_attributes(:status => 'Error') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this already set to "Completed" before this method is called? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, we needed the completed gone, because it's not a valid state for the task. It should either be ok or error. |
||
end | ||
end | ||
|
||
def task_active | ||
|
@@ -26,7 +28,7 @@ def task_active | |
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}>") | ||
_log.info("- creating service subtasks for service task <#{self.class.name}:#{id}>, service <#{parent_svc.id}>") | ||
create_retire_subtasks(parent_svc, self) | ||
end | ||
|
||
|
@@ -42,22 +44,22 @@ def create_retire_subtasks(parent_service, parent_task) | |
# 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, parent_task) | ||
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.tap(&:deliver_to_automate) | ||
end.compact! | ||
end | ||
|
||
def create_task(svc_rsc, parent_service, nh, parent_task) | ||
(svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh).tap do |task| | ||
resource_type = svc_rsc.resource.type.presence || "Service" | ||
bdunne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(resource_type.demodulize + "RetireTask").constantize.new(nh).tap do |task| | ||
task.options.merge!( | ||
:src_id => svc_rsc.resource.id, | ||
:src_ids => [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.underscore.downcase + "_retire" | ||
task.request_type = resource_type.demodulize.underscore.downcase + "_retire" | ||
task.source = svc_rsc.resource | ||
parent_task.miq_request_tasks << task | ||
task.save! | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,23 +19,10 @@ | |
expect(service.service_resources.first.resource.retireable?).to eq(false) | ||
end | ||
|
||
context "service" do | ||
context "with type" do | ||
let(:service1) { FactoryBot.create(:service_ansible_tower, :type => ServiceAnsibleTower) } | ||
it "is retireable" do | ||
FactoryBot.create(:service_resource, :service => service, :resource => service1) | ||
it "service is retireable" do | ||
FactoryBot.create(:service_resource, :service => service, :resource => FactoryBot.create(:service_ansible_tower, :type => ServiceAnsibleTower)) | ||
|
||
expect(service.service_resources.first.resource.retireable?).to eq(true) | ||
end | ||
end | ||
|
||
context "without type" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this still need to be tested? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
it "is not retireable" do | ||
FactoryBot.create(:service_resource, :service => service, :resource => FactoryBot.create(:service)) | ||
|
||
expect(service.service_resources.first.resource.retireable?).to eq(false) | ||
end | ||
end | ||
expect(service.service_resources.first.resource.retireable?).to eq(true) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is now included from the CiFeatureMixin which always returns
true
. 👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rational for changing this check is that, while the blanket check for type being present has some logical issues since not all services have types but all are retireable, the part that's being omitted at the moment is subservices. Per #17317 (comment), I think checking to see if the service is a subservice first makes more sense.