-
Notifications
You must be signed in to change notification settings - Fork 898
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
ServiceTemplate update_catalog_item #13811
ServiceTemplate update_catalog_item #13811
Conversation
app/models/service_template.rb
Outdated
@@ -74,6 +74,25 @@ def self.create_catalog_item(options, auth_user) | |||
end | |||
end | |||
|
|||
def self.update_catalog_item(catalog_item, options, auth_user) |
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.
It should NOT be a class method.
This pull request is not mergeable. Please rebase and repush. |
@miq-bot remove_label wip |
This pull request is not mergeable. Please rebase and repush. |
ping |
app/models/service_template.rb
Outdated
def update_resource_actions(ae_endpoints) | ||
resource_action_options.each do |action| | ||
# If the action exists in updated parameters | ||
if ae_endpoints[action[:param_key]] |
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.
You only need to find the existing resource_action once before the if/else clause.
app/models/service_template.rb
Outdated
def self.create_from_options(options) | ||
create(options.except(:config_info).merge(:options => { :config_info => options[:config_info] })) | ||
def update_from_options(options) | ||
update_attributes!(options.except(:config_info).merge!(:options => { :config_info => options[:config_info] })) |
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.
should not need !
for merge
thought it may not matter here.
@@ -57,6 +57,29 @@ def self.validate_config_info(options) | |||
|
|||
private | |||
|
|||
def update_service_resources(config_info, _auth_user = nil) | |||
if config_info[:template_id] && config_info[:template_id] != orchestration_template.id |
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.
orchestration_template.try(:id)
, same for other similar cases.
|
||
def validate_update_config_info(options) | ||
super | ||
config_info = options[:config_info] |
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.
code reuse - self.class.validate_config_info(options)
, same for the other class.
it 'creates and returns an ansible tower catalog item' do | ||
service_template = ServiceTemplateAnsibleTower.create_catalog_item(catalog_item_options) | ||
service_template.reload | ||
context '.create_catalog_item' do |
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.
Although context and describe seem interchangeable, my understanding the typical use is
describe a method
context a condition
app/models/service_template.rb
Outdated
if ae_endpoints[action[:param_key]] | ||
# And the resource action exists on the template already, update it | ||
if resource_action | ||
resource_actions.find_by(:action => action[:name]).update_attributes!(ae_endpoints[action[:param_key]]) |
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.
resource_action.update_attributes!
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.
we can extract ae_endpoints[action[:param_key]]
into a local variable since it is used three times
app/models/service_template.rb
Outdated
options[:config_info] | ||
end | ||
|
||
def resource_action_options |
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.
We can start to use the constants defined in ResourceAction
for Provision, Reconfigure, and 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.
We use the word options every where. Can we come up a better name for this method? Something like resource_action_list
. Naming is hard :(
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.
@bzwei I think naming is my least favorite part of writing code 😆 I like resource_action_list
- will do!
|
||
private | ||
|
||
def update_service_resources(config_info, _auth_user = nil) | ||
if config_info[:configuration_script_id] && config_info[:configuration_script_id] != job_template.id |
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.
job_template.try(:id)
app/models/service_template.rb
Outdated
if resource_params | ||
# And the resource action exists on the template already, update it | ||
if resource_action | ||
resource_actions.find_by(:action => action[:name]).update_attributes!(resource_params) |
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.
resource_action.update_attributes!
app/models/service_template.rb
Outdated
if resource_params | ||
# And the resource action exists on the template already, update it | ||
if resource_action | ||
resource_action.update_attributes!(resource_params) |
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.
We should slice selective attributes known to ResourceAction
just like how to create resource actions.
This pull request is not mergeable. Please rebase and repush. |
just remove the existing request and make a new one
👍 Looks good to me |
app/models/service_template.rb
Outdated
@@ -416,4 +473,8 @@ def resource_actions_info | |||
end | |||
config_info | |||
end | |||
|
|||
def resource_action_attrs |
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.
We need a better name here, this name is confusing/misleading. Also, I do not see why this is not just a constant instead of a method.
Maybe: RESOURCE_ACTION_UPDATE_ATTRS
Open to other suggestions.
add .try(:destroy) make resource action attrs into a constant
Checked commits jntullo/manageiq@797e93d~...4a3301a with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
WIP PR for updating of a catalog item. Format for update will be the same as creating one, ie:
@miq-bot add_label wip, enhancement, services