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 #3969 - Add template combinations commands #378

Merged
merged 1 commit into from Aug 20, 2018

Conversation

shiramax
Copy link
Contributor

No description provided.

@theforeman-bot
Copy link
Member

@shiramax, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:

If changing the ticket number used, remember to update the PR title and the commit message (using git commit --amend).


This message was auto-generated by Foreman's prprocessor

@shiramax shiramax changed the title Fixes #6969 - Add template combinations commands Fixes #3969 - Add template combinations commands Jul 30, 2018
Copy link
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output fields need to have human-readable descriptions

class InfoCombination < HammerCLIForeman::InfoCommand
output do
field :id, _('Id')
field :provisioning_template_id, _('provisioning_template_id')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The descriptions should be human readable and properly capitalized so _('Provisioning template ID')

@shiramax
Copy link
Contributor Author

Thanks, @adamruzicka , I Fixed all the descriptions.

Copy link
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some nitpicks inline, otherwise looks good

command_name 'combinations'
desc _("Manage template combinations")


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two empty lines

params = super
params["template_combination"] = {}
params["template_combination"]["hostgroup_id"] = params["hostgroup_id"].to_s
params["template_combination"]["environment_id"] = params["environment_id"].to_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could most likely be shortened to

def request_params
  combination_params = { 'hostgroup_id' => params['hostgroup_id'].to_s,
                         'environment_id' => params['environment_id'].to_s }
  super.merge('template_combination' => combination_params)
end

field :environment_id, _('Environment ID')
field :environment_name, _('Environment name')
field :config_template_id, _('Config_template ID')
field :config_template_name, _('Config_template name')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still underscores in the descriptions.

@shiramax
Copy link
Contributor Author

tThanks @adamruzicka, could you please review again?

Copy link
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one nitpick inline, otherwise it looks good to me and works as expected.

I'd still like to hear opinions from our hammer gurus. @tstrachota, @mbacovsky could you take a look?

end

build_options
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should probably be one empty line between the classes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :) thanks!

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 adding this long-time missing command 🍨. Overall it looks very good. I've suggested a few optimizations inline.

There are some options to the commands that I'd prefer be hidden in the help:

$  hammer template combinations list -h                       
Usage:
    hammer template combinations list [OPTIONS]

Options:
 --config-template CONFIG_TEMPLATE_NAME              Name to search by
 --config-template-id CONFIG_TEMPLATE_ID              
 --environment ENVIRONMENT_NAME                      Environment name
 --environment-id ENVIRONMENT_ID                      
 --hostgroup HOSTGROUP_NAME                          Hostgroup name
 --hostgroup-id HOSTGROUP_ID                          
 --hostgroup-title HOSTGROUP_TITLE                   Hostgroup title
 --location LOCATION_NAME                            Location name
 --location-id LOCATION_ID                            
 --location-title LOCATION_TITLE                     Location title
 --organization ORGANIZATION_NAME                    Organization name
 --organization-id ORGANIZATION_ID                   Organization ID
 --organization-title ORGANIZATION_TITLE             Organization title
 --provisioning-template PROVISIONING_TEMPLATE_NAME  Name to search by
 --provisioning-template-id PROVISIONING_TEMPLATE_ID  
 -h, --help                                          Print help

The --config-templates* should not be shown neither here nor in the other commands. In the list command the --hostgroup* and --environment* do not have any impact on the result so it would be better to remove them.

I'm not sure what was our conclusion on extending template info with combinations data. The data are already returned by the server and extending the output should be an easy and useful addition. Do you intend to add it? If so I leave it up to you if you want to include it in here or in separate PR. Let me know otherwise as we should create a new issue to track it.

Let me know if I can help.

@@ -194,6 +194,10 @@ def method_options_for_params(params, include_nil = true)
build_options
end

lazy_subcommand('combinations', _("Manage template combinations"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a resource with subcommands we usually use name in singular - combination.

field :hostgroup_name, _('Hostgroup name')
field :environment_id, _('Environment ID')
field :environment_name, _('Environment name')
field :config_template_id, _('Config template ID')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no config templates mentioned anywhere as it is deprecated in core. This is new command so we don't want to expose it

field :id, _('ID')
field :provisioning_template_id, _('Provisioning template ID')
field :provisioning_template_name, _('Provisioning template name')
field :hostgroup_id, _('Hostgroup ID')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field nil, _("Hostgroup"), Fields::SingleReference, :key => :hostgroup

should replace the two hosthgroup fields.
You can use same approach for env and template. It is less code with better control over the output.

end

class InfoCombination < HammerCLIForeman::InfoCommand
output do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use

output ListCommand.output_definition do

to re-use and extend output definition form Index and make it more DRY

end
autoload_subcommands
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually require a new line at the end. Some good reasons can be found e.g. https://unix.stackexchange.com/questions/18743/whats-the-point-in-adding-a-new-line-to-the-end-of-a-file. You may want to consider tuning your editor to do it for you automatically.

@shiramax
Copy link
Contributor Author

shiramax commented Aug 6, 2018

Thanks @mbacovsky !
could you please review again?

collection :template_combinations, 'Template Combinations' do
field :id, _('ID')
field :provisioning_template_id, _('Provisioning template ID')
field :provisioning_template_name, _('Provisioning template name')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:provisioning_template* could be excluded as it is always same as the template. Also we usually do not include the other ids here so that the output is not too long.

@mbacovsky
Copy link
Member

@shiramax, thanks for the update and extending the info! I have just one inline comment and one thing that I overlooked last time:

hammer template combination update -h
...
 --name NAME                                         >Name to search by<
 --new-name NEW_NAME      
...

The combinations do not have name so we should not offer the related options. This could be fixed in IdResolver.

@mbacovsky
Copy link
Member

One more thing, I'm missing the template combination delete command.

it 'should create new combination' do
params = ['create','--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
expected_result = success_result("Template combination created.\n")
api_expects(:template_combinations, :create, 'Create Compute template combination') do |params|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template combination

it 'should update combination' do
params = ['update','--id=3','--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
expected_result = success_result("Template combination updated.\n")
api_expects(:template_combinations, :update, 'Update Compute template combination') do |params|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dtto

@mbacovsky
Copy link
Member

👍 Thanks @shiramax, well done!

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