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
Target for mass VM transformation dialog #3073
Conversation
@miq-bot assign himdel |
@miq-bot add_labels gaprindashvili/yes |
@himdel @martinpovolny we'll appreciate a fast review, as this is a blocker. |
@@ -17,7 +17,8 @@ def vm_transform | |||
@right_cell_text = _("Transform VMs to RHV") | |||
simple_dialog_initialize( | |||
dialog.resource_actions.first, | |||
:header => @right_cell_text | |||
:header => @right_cell_text, |
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.
@smelamud This doesn't look right.
First of this is a Provider Action not a VM action. When the UI calls the controller with no vms selected the URL looks like
http://localhost:3000/ems_infra/10000000000001?display=vms
We get the params as <ActionController::Parameters {"pressed"=>"vm_transform", "controller"=>"ems_infra", "action"=>"button", "id"=>"10000000000001"} permitted: false>
So without the context vm or provider we can't be calling vm_transform and expecting that the ID is the ID of a VM when in reality it is the ID of the provider.
I would think we should have 2 separate actions
vm_transform which works with a single/multiple vm's, the target would be the vm object
mass_transform which applies to all tagged VMs in the provider, the target object here is the provider which the controller is passing it in.
So the target needs to be set appropriately based on the context.
Currently this line
if params.key?(: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.
@mkanoor If mass_transform
is a provider action, what module/class I need to put it into?
@@ -17,7 +17,8 @@ def vm_transform | |||
@right_cell_text = _("Transform VMs to RHV") | |||
simple_dialog_initialize( | |||
dialog.resource_actions.first, | |||
:header => @right_cell_text | |||
:header => @right_cell_text, | |||
:target => ExtManagementSystem.find_by(:type => 'ManageIQ::Providers::Redhat::InfraManager') |
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.
@smelamud
If you use the different URL's you should be able to ExtManagementSystem.find_by(:id => ....)
Since you get passed the id just like when you do a single VM.
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.
@mkanoor What about Compute > Infrastructure > Virtual Machines? If the mass transform button is clicked there, what it receives? There is neither provider nor VM selected.
780376a
to
88af980
Compare
@mkanoor Addressed all you comments, can you please to look on it again? |
Looks good. @himdel @martinpovolny please review |
Looks good to me. But I cannot test it right now. |
:target_kls => Provider.name | ||
) | ||
else | ||
provider = ExtManagementSystem.find_by(:type => 'ManageIQ::Providers::Redhat::InfraManager') |
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.
Multiple Redhat providers can be added. The best is to expect provider id always passed in. You can hide the provider selection field (but with an id assigned) in the dialog if there is only one provider available.
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.
@bzwei Hiding/showing of provider field is possible, but it is out of scope of this patch. In this patch I only add a proper target for the dialog to prevent the error.
When the mass transform button is clicked in 'Compute > Infrastructure > Virtual Machines' page, there is no id
passed. So I cannot expect that provider id is always passed in.
It doesn't matter if there are many Redhat providers added. The provider object here is needed only as a placeholder to be used as dialog target. find_by
will return one of the providers and it is enough for this purpose.
@martinpovolny When testing, please note that ManageIQ/manageiq#16686 must be applied as well. |
module ProviderActions | ||
module MassTransform | ||
def vm_transform_mass | ||
dialog = Dialog.find_by(:label => 'Transform VM') |
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.
@smelamud Should this be find_by! so that it raises an error if the Dialog is not found.
dialog = Dialog.find_by(:label => 'Transform VM') | ||
@right_cell_text = _("Transform VMs to RHV") | ||
if params.key?(:id) | ||
provider = ExtManagementSystem.find_by(:id => params[:id].to_i) |
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.
@smelamud Should this be find_by!
:target_kls => Provider.name | ||
) | ||
else | ||
provider = ExtManagementSystem.find_by(:type => 'ManageIQ::Providers::Redhat::InfraManager') |
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.
@smelamud This should also be find_by!
Created a separate vm_transform_mass action to handle VM Transform button clicks in on Providers page and on Compute > Infrastructure > Virtual Machines page. This action interprets the ID passed to it as provider ID, while regular vm_transform action interprets it as VM ID. If provider ID is not passed, the Redhat provider EMS object is used as target. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1514939 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1516497
88af980
to
dbfc5ba
Compare
@mkanoor Done. |
Checked commit smelamud@dbfc5ba with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0 |
:target_kls => Provider.name | ||
) | ||
else | ||
provider = ExtManagementSystem.find_by!(:type => 'ManageIQ::Providers::Redhat::InfraManager') |
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 bit surprises me, this is equivalent to provider = ManageIQ::Providers::Redhat::InfraManager.first
, right? Meaning "I don't know which RHV this is, so just pick a random one".
Shouldn't we always know the provider?
Or do we really not care about the instance, only the type?
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.
.. never mind, already answered in #3073 (comment)
dialog.resource_actions.first, | ||
:header => @right_cell_text, | ||
:target_id => provider.id, | ||
:target_kls => Provider.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.
should this have been provider.class.name
? If not, maybe use :target_kls => "Provider",
instead.
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.
@himdel I see that Vm.name
is used here
:target_kls => Vm.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.
OK, if this was intentional, no problem there .. just making sure :)
(On the one hand, Provider.name
sounds like a relatively magical way of saying "Provider"
.. but then on the other, with the string, we wouldn't get a nice exception if Provider
ever gets renamed, so.. (shrug) :).)
@martinpovolny Did you have a chance to test? |
Target for mass VM transformation dialog (cherry picked from commit f8417f4) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1530772 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1530773
Gaprindashvili backport details:
|
Created a separate vm_transform_mass action to handle VM Transform
button clicks in on Providers page and on Compute > Infrastructure >
Virtual Machines page. This action interprets the ID passed to it as
provider ID, while regular vm_transform action interprets it as VM ID.
If provider ID is not passed, the Redhat provider EMS object is used as
target.
Depends on ManageIQ/manageiq#16686
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1514939
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1516497
(See also @mkanoor comments here: ManageIQ/manageiq#16584 (review))