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
Conversation
@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 This message was auto-generated by Foreman's prprocessor |
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 output fields need to have human-readable descriptions
class InfoCombination < HammerCLIForeman::InfoCommand | ||
output do | ||
field :id, _('Id') | ||
field :provisioning_template_id, _('provisioning_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.
The descriptions should be human readable and properly capitalized so _('Provisioning template ID')
Thanks, @adamruzicka , I Fixed all the descriptions. |
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.
Left some nitpicks inline, otherwise looks good
command_name 'combinations' | ||
desc _("Manage template combinations") | ||
|
||
|
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 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 |
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.
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') |
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.
There are still underscores in the descriptions.
tThanks @adamruzicka, could you 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.
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 |
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.
There should probably be one empty line between the classes
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.
done :) thanks!
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 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.
lib/hammer_cli_foreman/template.rb
Outdated
@@ -194,6 +194,10 @@ def method_options_for_params(params, include_nil = true) | |||
build_options | |||
end | |||
|
|||
lazy_subcommand('combinations', _("Manage template combinations"), |
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.
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') |
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.
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') |
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.
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 |
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 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 |
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 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.
Thanks @mbacovsky ! |
lib/hammer_cli_foreman/template.rb
Outdated
collection :template_combinations, 'Template Combinations' do | ||
field :id, _('ID') | ||
field :provisioning_template_id, _('Provisioning template ID') | ||
field :provisioning_template_name, _('Provisioning template name') |
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.
: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.
@shiramax, thanks for the update and extending the info! I have just one inline comment and one thing that I overlooked last time:
The combinations do not have name so we should not offer the related options. This could be fixed in IdResolver. |
One more thing, I'm missing the |
test/functional/template_test.rb
Outdated
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| |
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.
template combination
test/functional/template_test.rb
Outdated
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| |
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.
dtto
8286ec2
to
6d29da5
Compare
👍 Thanks @shiramax, well done! |
No description provided.