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

Target for mass VM transformation dialog #3073

Merged
merged 1 commit into from Dec 21, 2017

Conversation

smelamud
Copy link
Contributor

@smelamud smelamud commented Dec 14, 2017

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))

@smelamud
Copy link
Contributor Author

@miq-bot assign himdel

@smelamud
Copy link
Contributor Author

@miq-bot add_labels gaprindashvili/yes

@oourfali
Copy link

@himdel @martinpovolny we'll appreciate a fast review, as this is a blocker.
Thanks!

@@ -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,
Copy link
Contributor

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

is wrong without the context. It gives arbitrary vm object for which there is a different BZ open.

Copy link
Contributor Author

@smelamud smelamud Dec 17, 2017

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')
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@smelamud smelamud force-pushed the mass-transform-target branch 3 times, most recently from 780376a to 88af980 Compare December 18, 2017 22:49
@smelamud
Copy link
Contributor Author

@mkanoor Addressed all you comments, can you please to look on it again?

@mkanoor
Copy link
Contributor

mkanoor commented Dec 19, 2017

Looks good. @himdel @martinpovolny please review

@martinpovolny
Copy link

Looks good to me. But I cannot test it right now.

@martinpovolny
Copy link

@smelamud, @oourfali : can someone from your team confirm that it works correctly in the UI?

If not, I can try to test this tomorrow.

:target_kls => Provider.name
)
else
provider = ExtManagementSystem.find_by(:type => 'ManageIQ::Providers::Redhat::InfraManager')
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@smelamud
Copy link
Contributor Author

@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')
Copy link
Contributor

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)
Copy link
Contributor

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')
Copy link
Contributor

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
@smelamud
Copy link
Contributor Author

@mkanoor Done.

@miq-bot
Copy link
Member

miq-bot commented Dec 19, 2017

Checked commit smelamud@dbfc5ba with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
8 files checked, 0 offenses detected
Everything looks fine. 🍪

@mkanoor
Copy link
Contributor

mkanoor commented Dec 20, 2017

@smelamud 👍

:target_kls => Provider.name
)
else
provider = ExtManagementSystem.find_by!(:type => 'ManageIQ::Providers::Redhat::InfraManager')
Copy link
Contributor

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?

Copy link
Contributor

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
Copy link
Contributor

@himdel himdel Dec 20, 2017

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.

Copy link
Contributor Author

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

for the same parameter.

Copy link
Contributor

@himdel himdel Dec 20, 2017

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) :).)

@smelamud
Copy link
Contributor Author

@martinpovolny Did you have a chance to test?

@martinpovolny martinpovolny merged commit f8417f4 into ManageIQ:master Dec 21, 2017
@martinpovolny martinpovolny added this to the Sprint 76 Ending Jan 1, 2018 milestone Dec 21, 2017
simaishi pushed a commit that referenced this pull request Jan 3, 2018
@simaishi
Copy link
Contributor

simaishi commented Jan 3, 2018

Gaprindashvili backport details:

$ git log -1
commit 9363d336270329000a95cfcf6973d89897ed437f
Author: Martin Povolny <mpovolny@redhat.com>
Date:   Thu Dec 21 12:01:54 2017 +0100

    Merge pull request #3073 from smelamud/mass-transform-target
    
    Target for mass VM transformation dialog
    (cherry picked from commit f8417f4e2ea01eca8d6b9e2935f023a810b21c56)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1530772
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1530773

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.

None yet

8 participants