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

BZ #20538 - add compute profile commands #366

Closed
wants to merge 1 commit into from

Conversation

shiramax
Copy link
Contributor

No description provided.

@shiramax shiramax changed the title 20538 WIP #20538 - add compute profile commands Apr 15, 2018
@shiramax shiramax force-pushed the 20538 branch 2 times, most recently from 3128983 to 2ed61ba Compare April 15, 2018 13:59
@shiramax shiramax changed the title WIP #20538 - add compute profile commands BZ #20538 - add compute profile commands Apr 29, 2018
@shiramax
Copy link
Contributor Author

needs to merge :
theforeman/hammer-cli#274

@shiramax
Copy link
Contributor Author

@mbacovsky please review :)

Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

I found some minor issues. I think it's good to have them fixed anyway.

params = {}
params['compute_attribute'] = {}
profile = HammerCLIForeman.record_to_common_format(
HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, {'id' => options['option_compute_profile_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 important, but still: Redundant curly braces around a hash parameter

profile = HammerCLIForeman.record_to_common_format(
HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, {'id' => options['option_compute_profile_id'] })
)
HammerCLIForeman.foreman_resource(:compute_resources).call(:show, {'id' => options['option_compute_resource_id'] })
Copy link
Member

Choose a reason for hiding this comment

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

ditto curly braces

HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, {'id' => options['option_compute_profile_id'] })
)
HammerCLIForeman.foreman_resource(:compute_resources).call(:show, {'id' => options['option_compute_resource_id'] })
params['compute_attribute'] = profile['compute_attributes'].select{ |hash| hash['compute_resource_id']== options['option_compute_resource_id']}[0] || {}
Copy link
Member

Choose a reason for hiding this comment

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

again, not important, but some spaces are missing .select{ and hash['compute_resource_id']==

end

class CreateCommand < HammerCLIForeman::CreateCommand
success_message _('Compute profile created')
Copy link
Member

Choose a reason for hiding this comment

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

Almost all success messages should end with '.' at the end. You might use the test from this PR to check yourself.

validate_options do
any(:option_name,:option_id).required
end
build_options :without => :name
Copy link
Member

Choose a reason for hiding this comment

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

Most likely I'm mistaken, but doesn't seem it does anything.

build_options :without => :id
end

class AddInterface < HammerCLIForeman::UpdateCommand
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it should inherit CreateCommand instead of UpdateCommand?

Also it doesn't seem to work. I tried hammer compute-profile add-interface --compute-resorce tstracho-laptop --compute-profile 1-Small --set-values type=network,bridge=br1 and got Could not create interface: Error: undefined method `[]' for nil:NilClass. Does it work for you?

Copy link
Contributor Author

@shiramax shiramax Jul 4, 2018

Choose a reason for hiding this comment

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

bridge is not allowed attribute for any of the compute resources
check hammer compute-profile add-interface --help
and I can't reproduce this error at all.. are the compute profile and compute resource name exists?
what is the compute resource your testing on? ovirt?

Copy link
Member

Choose a reason for hiding this comment

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

I think UpdateCommand is correct as we add interface attrs by modifying existing compute_attribute. I was not able to reproduce the error. However it is a bit unclear what is the relation - can each compute profile have only one compute attribute per compute resource?

@shiramax I think it would be worth a comment in the code explaining why we use the Update predecessor. We will have to care about the --name and --new-name parameters. Option builder removed the --id but those left. Let me know if you don't find out how to remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the relation - can each compute profile have only one compute attribute per compute resource?
^^ you can have only one compute attribute, but inside the compute attribute you can have multiple volumens and interfaces.

build_options :without => :id
end

class RemoveInterface < HammerCLIForeman::UpdateCommand
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it should inherit DeleteCommand instead of UpdateCommand?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the UpdateCommand is needed in this case because the remove is done by updating the resource.

Copy link
Member

Choose a reason for hiding this comment

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

@shiramax Could you add a explanation to the code and remove the --name options?

build_options :without => :id
end

class RemoveVolume < HammerCLIForeman::UpdateCommand
Copy link
Member

Choose a reason for hiding this comment

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

same I mentioned above

class RemoveInterface < HammerCLIForeman::UpdateCommand
command_name _('remove-interface')
resource :compute_attributes
desc _('Update compute profile interface')
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it should say "Remove compute ..."?

class RemoveVolume < HammerCLIForeman::UpdateCommand
command_name _('remove-volume')
resource :compute_attributes
desc _('Update compute profile volume')
Copy link
Member

Choose a reason for hiding this comment

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

same I mentioned above

@shiramax
Copy link
Contributor Author

@ofedoren thanks! I fixed all the comments :)

@ofedoren
Copy link
Member

ofedoren commented Jul 4, 2018

@shiramax great, thank you!

But still I get

Could not create interface:
  Error: undefined method `[]' for nil:NilClass

while trying

hammer compute-profile add-interface --compute-resource-id 3 --compute-profile-id 1 --set-values type=network,bridge=br1

Is it only me?

resource :compute_attributes
desc _('Add volume for Compute Profile')

option '--set-values', 'VOLUME', _('Volume parameters, should be comma separated list of values.'),
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for bothering you with this again, but there is a convention, that says option descriptions should not end with a dot. Simply remove '.' at the end of option description.

resource :compute_attributes
desc _('Update compute profile volume')

option '--set-values', 'VOLUME', _('Volume parameters, should be comma separated list of values.'),
Copy link
Member

Choose a reason for hiding this comment

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

ditto "dot at the end"

command_name _('remove-volume')
resource :compute_attributes
desc _('Remove compute profile volume')
option '--volume-id', 'VOLUME_ID', _('Volume id.'),
Copy link
Member

Choose a reason for hiding this comment

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

ditto "dot at the end"


desc _('Update compute profile interface')

option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values.'),
Copy link
Member

Choose a reason for hiding this comment

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

ditto "dot at the end"

option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values.'),
:required => true,
:format => HammerCLI::Options::Normalizers::KeyValueList.new
option '--interface-id', 'INTERFACE_ID', _('Interface id.'),
Copy link
Member

Choose a reason for hiding this comment

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

ditto "dot at the end"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't really understand where to put the dot here

command_name _('add-interface')
resource :compute_attributes
desc _('Add interface for Compute Profile')
option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values.'),
Copy link
Member

Choose a reason for hiding this comment

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

ditto "dot at the end"


option '--compute-attributes', 'COMPUTE_ATTRS', _('Compute resource attributes.'),
:format => HammerCLI::Options::Normalizers::KeyValueList.new
option '--interface', 'INTERFACE', _('interface parameters, should be comma separated list of values.'),
Copy link
Member

Choose a reason for hiding this comment

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

ditto "dot at the end"

:format => HammerCLI::Options::Normalizers::KeyValueList.new
option '--interface', 'INTERFACE', _('interface parameters, should be comma separated list of values.'),
:format => HammerCLI::Options::Normalizers::KeyValueList.new
option '--volume', 'VOLUME', _('Volume parameters, should be comma separated list of values.'),
Copy link
Member

Choose a reason for hiding this comment

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

ditto "dot at the end"

command_name _('update-attributes')
resource :compute_attributes

option '--compute-attributes', 'COMPUTE_ATTRS', _('Compute resource attributes, should be comma separated list of values.'),
Copy link
Member

Choose a reason for hiding this comment

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

ditto "dot at the end"

:format => HammerCLI::Options::Normalizers::KeyValueList.new
option '--interface-id', 'INTERFACE_ID', _('Interface id'),
:format => HammerCLI::Options::Normalizers::Number.new
option '--volume', 'VOLUME', _('Volume parameters, should be comma separated list of values.'),
Copy link
Member

Choose a reason for hiding this comment

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

ditto "dot at the end" and 2 above

@ofedoren
Copy link
Member

ofedoren commented Jul 4, 2018

@shiramax I apologize for any misunderstanding, everything is fine now :) Thanks!

@iNecas
Copy link
Member

iNecas commented Jul 31, 2018

@mbacovsky mind finishing the review?

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 extensive work! I've put my comments inline. For the first round I focused on the commands and structure of the code. Overall it looks very good. It passed some basic testing with exception for the translated commands and extra `--name' options.

I still need to go through the tests and help extensions withregard on the other help related work. Will update.

end

class SetAttributes < HammerCLIForeman::CreateCommand
command_name _('set-attributes')
Copy link
Member

Choose a reason for hiding this comment

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

Do not mark commands for translations

HammerCLIForeman::References.taxonomies(self)
HammerCLIForeman::References.timestamps(self)

collection :compute_attributes, 'Compute attributes' do
Copy link
Member

Choose a reason for hiding this comment

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

Compute attributes needs translation

success_message _('Compute profile created.')
failure_message _('Could not create a compute profile')

validate_options do
Copy link
Member

Choose a reason for hiding this comment

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

The name is required by API no need for the validator.

profile = HammerCLIForeman.record_to_common_format(
HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, 'id' => options['option_compute_profile_id'] )
)
HammerCLIForeman.foreman_resource(:compute_resources).call(:show, 'id' => options['option_compute_resource_id'] )
Copy link
Member

Choose a reason for hiding this comment

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

Is this value used anywhere?

Copy link
Member

Choose a reason for hiding this comment

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

Do we need this call in here?

end

def request_params
params = {}
Copy link
Member

Choose a reason for hiding this comment

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

if you use params = super here you don't have to care about compute attribute and compute profile name resolution later in this method

build_options :without => :id
end

class AddInterface < HammerCLIForeman::UpdateCommand
Copy link
Member

Choose a reason for hiding this comment

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

I think UpdateCommand is correct as we add interface attrs by modifying existing compute_attribute. I was not able to reproduce the error. However it is a bit unclear what is the relation - can each compute profile have only one compute attribute per compute resource?

@shiramax I think it would be worth a comment in the code explaining why we use the Update predecessor. We will have to care about the --name and --new-name parameters. Option builder removed the --id but those left. Let me know if you don't find out how to remove it.

end

class UpdateInterface < HammerCLIForeman::UpdateCommand
command_name _('update-interface')
Copy link
Member

Choose a reason for hiding this comment

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

There are --name and --new-name options left in the command.

build_options :without => :id
end

class RemoveInterface < HammerCLIForeman::UpdateCommand
Copy link
Member

Choose a reason for hiding this comment

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

@shiramax Could you add a explanation to the code and remove the --name options?

end

class AddVolume < HammerCLIForeman::UpdateCommand
command_name _('add-volume')
Copy link
Member

Choose a reason for hiding this comment

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

Same as for the commands above

build_options :without => :id
end

class UpdateVolume < HammerCLIForeman::UpdateCommand
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

@shiramax
Copy link
Contributor Author

@mbacovsky could you please remind me in which file I can configure the help to show the translation?
thanks.

@mbacovsky
Copy link
Member

@shiramax you need to set this option https://github.com/theforeman/hammer-cli/blob/master/config/cli_config.template.yml#L10. It is most likely in ~/.hammer/cli_config.yml

end

class DeleteCommand < HammerCLIForeman::DeleteCommand
success_message 'Compute profile deleted.'
Copy link
Member

Choose a reason for hiding this comment

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

Translation marker is missing


class DeleteCommand < HammerCLIForeman::DeleteCommand
success_message 'Compute profile deleted.'
failure_message 'Could not delete the Compute profile'
Copy link
Member

Choose a reason for hiding this comment

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

Translation marker is missing


option '--compute-attributes', 'COMPUTE_ATTRS', _('Compute resource attributes'),
:format => HammerCLI::Options::Normalizers::KeyValueList.new
option '--interface', 'INTERFACE', _('interface parameters, should be comma separated list of values'),
Copy link
Member

Choose a reason for hiding this comment

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

Capitalize "Interface"

command_name 'add-interface'
resource :compute_attributes
desc _('Add interface for Compute Profile.')
option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values'),
Copy link
Member

Choose a reason for hiding this comment

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

underscore missing in 'SET_VALUES'


desc _('Update compute profile interface.')

option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values'),
Copy link
Member

Choose a reason for hiding this comment

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

Underscore is missing in 'SET_VALUES"

end
end

def validate_options
Copy link
Member

Choose a reason for hiding this comment

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

Validators are preferred in a block:

      validate_options do
        any(:option_compute_profile_id, :option_compute_profile_name ).required
        any(:option_compute_resource_id, :option_compute_resource_name).required
      end

end

def validate_options
super
Copy link
Member

Choose a reason for hiding this comment

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

We prefer validators in a block (see comment above).

super
validator.any(:option_compute_profile_id, :option_compute_profile_name ).required
validator.any(:option_compute_resource_id, :option_compute_resource_name).required
validator.any(:option_interface, :option_volume, :option_compute_attributes).required
Copy link
Member

Choose a reason for hiding this comment

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

How do I identify what compute attribute I'm going to update? I'd expect --compute-attribute or --compute-attribute-id.
Is compute-attribute-name unique or do we need to add also compute profile or compute resource to search for the compute attribute by name? If so It should be required only when there is compute attribute name given.

Copy link
Member

Choose a reason for hiding this comment

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

Or is it that (compute profile, compute resource) has at most one compute attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

compute attribute is a combination of compute profile and compute resource. It doesn't have a name


# Using the Update command because adding a new interface is done by modifying existing compute_attribute
class AddInterface < HammerCLIForeman::UpdateCommand
command_name 'add-interface'
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference between compute-profile update-attributes --volume <attrs> and compute-profile update-volume --set-values <attrs>?
If it is the same functionality isn't it confusing for the user to have two similar ways how to achieve the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I I remember correctly when designing the commands, we talked about it.
the update attributes will let the user update in one command interface & volume & other attributes.
update-volume is easier if the user wants to update the volume.

I agree it might be confusing, what do you think is the best approach here?

@mbacovsky
Copy link
Member

@shiramax, thanks for fixing the issues mentioned in my comments!

I finally did another round of review and found out the UX a bit unclear. The most prominent thing is that it is not clear to me what is the difference between compute-profile update-attributes --volume <attrs> and compute-profile update-volume --set-values <attrs>. Do we need both?

Another thing are the parameters used to address the compute attributes. What I'm concerned about is I didn't found 'compute attributes' mentioned in the UI (besides the URLs). In the UI we present the compute profile as a set of compute profiles with same name for different resources. Do you think it would make sense to mimic this in the CLI somehow? Was the UX design discussed before?

@mbacovsky
Copy link
Member

Would you mind and rebase this PR? Also it seems the validations will be easier to do once I merge theforeman/hammer-cli#242 so it can wait till the merge happens and the UX is resolved.

@shiramax
Copy link
Contributor Author

@mbacovsky ,
You are right, I thought about it too..The compute attributes are not presented in the UI, except in the URLs.
As you said, In the UI the compute profile is presented as a set of compute profiles with the same name for different resources, This behavior is more confusing to me.
And In the Cli the approach is to use compute attributes, and this is much more make sense to me.

please tell me what do you think, thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants