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

Fixes #6159 - move image_id to be under the compute_attributes #404

Merged
merged 1 commit into from
May 20, 2019

Conversation

shiramax
Copy link
Contributor

No description provided.

@mbacovsky
Copy link
Member

[test hammer]

Copy link
Member

@mbacovsky mbacovsky left a 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)

def request_params
params = super
if option_image_id
HammerCLIForeman::Host.set_image_uuid(params,option_image_id)
Copy link
Member

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 

Copy link
Contributor Author

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?

@mbacovsky
Copy link
Member

@shiramax looks a way better now! I realized we have to move all the code from host.rb to the CommonUpdateOptions module we break the existing request_params otherwise. As a bonus we get more DRY code and set_image_uuid won't be misplaced.

get_image_id should be better named get_image_uuid and while it is not exactly a help util we should rename the module to just utils to cover both methods purpose.

@shiramax shiramax force-pushed the 6159 branch 3 times, most recently from fcf26fc to 6e180c3 Compare April 14, 2019 13:57
@shiramax
Copy link
Contributor Author

thanks @mbacovsky, please review again

Copy link
Member

@mbacovsky mbacovsky left a 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)
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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"]
Copy link
Member

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"]
Copy link
Member

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

@shiramax
Copy link
Contributor Author

shiramax commented May 2, 2019

thanks @mbacovsky ,
please review again.

Copy link
Member

@mbacovsky mbacovsky left a 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. 🎆

@mbacovsky mbacovsky merged commit ca785b3 into theforeman:master May 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants