-
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
Add retireable check to service ansible playbooks #18609
Add retireable check to service ansible playbooks #18609
Conversation
@miq-bot assign @gmcculloug |
@miq-bot add_reviewer @tinaafitz |
1594bed
to
0315267
Compare
app/models/service_retire_task.rb
Outdated
@@ -29,7 +29,7 @@ def after_request_task_create | |||
update_attributes(:description => get_description) | |||
parent_svc = Service.find_by(:id => options[:src_ids]) | |||
_log.info("- creating service subtasks for service task <#{self.class.name}:#{id}>, service <#{parent_svc.id}>") | |||
create_retire_subtasks(parent_svc, self) | |||
create_retire_subtasks(parent_svc, self) unless parent_svc.type == 'ServiceAnsiblePlaybook' && !parent_svc.retireable? |
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.
Two thoughts:
- Compare the class object instead of the class name string:
parent_svc.kind_of?(ServiceAnsiblePlaybook)
- Instead of using a complex
unless
statement, which we try to avoid, move this into a separate private methodretire_subtasks?
which can be tested independently.
Will make this line easy to read:
create_retire_subtasks(parent_svc, self) if retire_subtasks?
@@ -32,6 +33,14 @@ def execute(action) | |||
add_resource!(new_job, :name => action) | |||
end | |||
|
|||
def retireable? | |||
!retain_resources? |
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.
@tinaafitz Is this correct? The Service is considered non-retireable if we are retaining resources? I thought we would still run the playbook if it was configured and this feels like we would not do that.
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.
@gmcculloug The service_resources for ansible services are considered non-retireable if we are retaining resources. The service_retire_task has already been created, so it's only preventing the service_resources from potentially creating retire tasks.
bc9e62c
to
60eb777
Compare
97a7fdd
to
4037d54
Compare
@@ -32,6 +33,10 @@ def execute(action) | |||
add_resource!(new_job, :name => action) | |||
end | |||
|
|||
def retireable? | |||
!retain_resources_on_retirement? |
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.
So discussed more with @tinaafitz and this does not feel correct. If you ask the service instance if it can be retired the answer should not be solely used to drive if child resources are retired, it should be answering the question for it self. Another way of looking at it would be if the UI was using this method to determine if the service itself could be retired. I think we want the response to be true regardless of the child-items.
Seems like the retain_resources_on_retirement
is doing more what we want and this method is not needed.
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.
I was under the impression that at the end of the conversation I and you and Madhu had in the kitchen that the proposed solution then was to use this retireable? check from the CiFeatureMixin to determine whether the service was retireable. If we're not using this approach I think we should have the discussion that Jason kinda started on last week about how checking to see if something is retireable requires both a general check like those used by the SupportsFeatureMixin and something more specific because since this issue is related it'd be easier to have that discussion sooner.
@@ -68,12 +73,16 @@ def on_error(action) | |||
|
|||
private | |||
|
|||
def retain_resources_on_retirement? | |||
%w[no_without_playbook no_with_playbook].include?(options.fetch_path(:config_info, :retirement, :remove_resources)) |
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.
Realized I already commented on this line, but looking at the options it seems like it is just:
options.fetch_path(:config_info, :retirement, :remove_resources).to_s.starts_with("no_")
Not a required change, but seems simpler and maybe more future proof.
app/models/service_retire_task.rb
Outdated
@@ -68,6 +70,10 @@ def create_task(svc_rsc, parent_service, nh, parent_task) | |||
|
|||
private | |||
|
|||
def retire_subtasks?(parent_svc) | |||
parent_svc.kind_of?(ServiceAnsiblePlaybook) && !parent_svc.retireable? ? false : 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.
I think this method should call retain_resources_on_retirement?
based on comments about retireable?
. It will need to handle if the parent_service exposes this method.
b5599fa
to
2a39ffd
Compare
app/models/service_retire_task.rb
Outdated
@@ -68,6 +70,10 @@ def create_task(svc_rsc, parent_service, nh, parent_task) | |||
|
|||
private | |||
|
|||
def retain_ansible_playbook_subtasks?(parent_svc) | |||
parent_svc.kind_of?(ServiceAnsiblePlaybook) && parent_svc.retain_resources_on_retirement? |
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.
I suggest trying to make these method names more generic. Also the currently naming is misleading, you are not retaining subtasks, you are retaining resources of the service by skipping the subtasks that would retire them.
def create_subtasks?(parent_svc)
!parent_svc.try(:retain_resources_on_retirement?)
end
This makes the caller above easier to read as it would change to:
if create_subtasks?(parent_svc)
app/models/service_retire_task.rb
Outdated
@@ -28,8 +28,10 @@ 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 subtasks for service task <#{self.class.name}:#{id}>, service <#{parent_svc.id}>") | |||
create_retire_subtasks(parent_svc, self) | |||
unless retain_ansible_playbook_subtasks?(parent_svc) |
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.
With the suggested change to the "create_subtasks?" method this would be easier to read as:
if create_subtasks?(parent_svc)
2a39ffd
to
a309f31
Compare
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.
@tinaafitz @lfu Please review
describe '#retain_resources_on_retirement?' do | ||
context "no_with_playbook is false" do | ||
let(:remove_resources) { 'no_with_playbook' } | ||
let(:can_children_be_retired?) { 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 logic here seems not right.
describe '#retain_resources_on_retirement?' do
context "no_with_playbook" do
let(:remove_resources) { 'no_with_playbook' }
let(:can_children_be_retired?) { false }
it_behaves_like "#retain_resources_on_retirement"
service_options[:config_info][:retirement] = service_options[:config_info][:provision] | ||
service_options[:config_info][:retirement][:remove_resources] = remove_resources | ||
service.update_attributes(:options => service_options) | ||
expect(service.retain_resources_on_retirement?).to eq(can_children_be_retired?) |
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.
When resource is to be retained, then children can not be retired.
expect(service.retain_resources_on_retirement?).to eq(!can_children_be_retired?)
expect(ServiceRetireTask.count).to eq(1) | ||
expect(VmRetireTask.count).to eq(0) | ||
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.
Shared example can be used for above two cases.
expect(VmRetireTask.count).to eq(1) | ||
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.
Same here.
|
||
context "yes_without_playbook is true" do | ||
let(:remove_resources) { 'yes_without_playbook' } | ||
let(:can_children_be_retired?) { false } |
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.
Same here.
|
||
context "yes_with_playbook is true" do | ||
let(:remove_resources) { 'yes_with_playbook' } | ||
let(:can_children_be_retired?) { false } |
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.
Same here.
context "no_without_playbook is false" do | ||
let(:remove_resources) { 'no_without_playbook' } | ||
let(:can_children_be_retired?) { true } | ||
it_behaves_like "#retain_resources_on_retirement" |
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.
Same here.
a309f31
to
0cf67b4
Compare
Checked commit d-m-u@0cf67b4 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@lfu please re-review |
@d-m-u There is a conflict backporting this to File: app/models/service_ansible_playbook.rb + def manageiq_connection_env
{
++<<<<<<< HEAD
+ 'url' => api_url,
+ 'token' => api_token,
+ 'X_MIQ_Group' => evm_owner.current_group.description
+ }
+ end
+
+ def api_token
+ @api_token ||= Api::UserTokenService.new.generate_token(evm_owner.userid, 'api')
+ end
+
+ def api_url
+ @api_url ||= MiqRegion.my_region.remote_ws_url
++=======
+ 'service' => href_slug,
+ 'action' => action
+ }.merge(manageiq_env(evm_owner, miq_group, miq_request_task))
+ .merge(request_options_extra_vars)
++>>>>>>> ff41ba27ab... Merge pull request #18609 from d-m-u/adding_remove_resource_method_to_service_template_ansible_playbook |
sure @simaishi right away ma'am |
Backported to Hammer via #18620 |
We are currently creating the service retire tasks before we send them to automate, which means that if the parent service is an ansible playbook service with config options specifying the resources to not be retired, we will have already created tasks for the retirement of said resources, and will not honor the playbook config options hash. This cuts off the task creation for APS's early if the config option to not retire resources is present.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1692941