-
Notifications
You must be signed in to change notification settings - Fork 98
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
Fixes #6159 - move image_id to be under the compute_attributes #404
Conversation
[test hammer] |
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.
@shiramax thanks for this addition. Works fine but this PR needs rebase and also some tests. I'd also like to discuss my concerns about the helper method in Host command (See inline please)
lib/hammer_cli_foreman/host.rb
Outdated
def request_params | ||
params = super | ||
if option_image_id | ||
HammerCLIForeman::Host.set_image_uuid(params,option_image_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.
If we split (Single Responsibility) the set_image_uuid
we could move getting the image to ComputeResource which would be more expected place for the code. I also don't think HammerCLIForeman::Host super-command is a good place for storing helper methods for individual subcommands. I'd keep the assignment in the Update/Create commands. If you'd need to make it more DRY it would be better to create a module with the helper method that is included in the subcommands.
compute_resource_id = params['host']['compute_resource_id']
image_uuid = HammerCLIForeman::ComputeResource::Utils.image_uuid(compute_resource_id, options['option_image_id'])
params['host']['compute_attributes']['image_id'] = image uuid
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 could move getting the image to ComputeResource - which file?
dd1f86c
to
0fec4b4
Compare
@shiramax looks a way better now! I realized we have to move all the code from host.rb to the
|
fcf26fc
to
6e180c3
Compare
thanks @mbacovsky, please review again |
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.
@shiramax, thanks for moving the logic to proper place. I realized some more problems please see inline.
@@ -50,9 +50,15 @@ def self.ask_password | |||
HammerCLI.interactive_output.ask(prompt) { |q| q.echo = false } | |||
end | |||
|
|||
def self.set_image_uuid(params, image_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.
A couple of concerns here:
- it is not called from outside of the module so there is no reason to make it an instance method - no
self.
- no reason to make it public (move it to the private section below)
- it breaks single responsibility principle - it should just get the image_id, setting the params is out of scope of this method (see how other methods here e.g.
subnet_id
are used) - it does not work when --compute-resource-id is not given. I'm not sure what is the plan here. I as an user would expect hammer to try to load existing cr-id from the server on update raise an usage error otherwise.
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.
How can I load cr-id from the server? You can have multiple compute resource on the servers
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 would be just for a case of an update of an existing host. We could try to load the host and check if the CR is set there. If not we should rise usage/validation error or similar
@@ -69,6 +75,7 @@ def request_params | |||
params['host']['build'] = true if option_build.nil? | |||
params['host']['managed'] = true if option_managed.nil? | |||
params['host']['enabled'] = true if option_enabled.nil? | |||
HammerCLIForeman::Hosts::CommonUpdateOptions::set_image_uuid(params, options["option_image_id"]) if options["option_image_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.
When image_uuid
is an instance method you don't have to scope it. I'd expect something like:
params['host']['compute_attributes']['image_id'] = image_uuid(params['host']['compute_resource_id'], options["option_image_id"]) if options["option_image_id"]
Please note that you completely rewrite params['host']['compute_attributes'] a couple of lines below. Was this ever tested?
@@ -78,6 +85,7 @@ def request_params | |||
if action == :update | |||
params['host']['compute_attributes']['volumes_attributes'] = nested_attributes(option_volume_list) unless option_volume_list.empty? | |||
params['host']['interfaces_attributes'] = interfaces_attributes unless option_interface_list.empty? | |||
HammerCLIForeman::Hosts::CommonUpdateOptions::set_image_uuid(params, options["option_image_id"]) if options["option_image_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.
Not sure if this is the best place but we should load cr_id somewhere. How about?
options["option_image_id"]
compute_resource_id = params['host']['compute_resource_id'] || load_compute_resource(options["option_id"]) || <rise some error>
params['host']['compute_attributes']['image_id'] = image_uuid(compute_resource_id, options["option_image_id"])
end
thanks @mbacovsky , |
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.
👍 Thanks @shiramax for the updates and all the effort on this. It works well for me now and the code looks clean. 🎆
No description provided.