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

Setting PhysicalSwitch as its base model #17431

Closed
wants to merge 1 commit into from

Conversation

EsdrasVP
Copy link
Member

@EsdrasVP EsdrasVP commented May 17, 2018

This PR is able to:

  • Set PhysicalSwitch as its base model to avoid problems when Physical Infra Provider calls it

The problems:

When trying to list the Physical Switches from a Physical Infra Provider (/ems_physical_infra/:id?display=physical_switches)
physical_swiches_listing_02

An error is returned
physical_switches_listing_03

This happens because the application controller from the UI calls paged_view_search, which is a method from Search class inside ManageIQ core that, internally, uses the base model for the class passed. The result is that, instead of "PhysicalSwitch", its parent "Switch" is called, and the Physical Infra Provider deals with PhysicalSwitch, not Switch.

And while accessing a Physical Switch in its summary page (/physical_switch/:id), the QuadIcon doesn't show all quadrants, instead, it is a single icon
physical_switches_listing_04

This also happens because, in quadicon helper, a call is made for the class's base model. Currently this is solved using "demodulize" in the class, but this could affect other classes, and could induce an error to happen.

Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

Not sure exactly what the issue is but I don't think this is the right approach

@EsdrasVP EsdrasVP changed the title Setting the same table for Switches and PhysicalSwitches Setting PhysicalSwitches as its base model May 18, 2018
@EsdrasVP EsdrasVP changed the title Setting PhysicalSwitches as its base model Setting PhysicalSwitch as its base model May 18, 2018
@EsdrasVP
Copy link
Member Author

@agrare Just changed the approach to a more used in ManageIQ. This solves the problem and reduces the error probability.

@agrare
Copy link
Member

agrare commented May 18, 2018

@EsdrasVP can you post the exact issue that you're seeing with screenshots or error backtraces? I'm still not sure what you're trying to fix.

@EsdrasVP
Copy link
Member Author

@agrare I put some screenshots to explain better the problem.

@miq-bot
Copy link
Member

miq-bot commented May 22, 2018

This pull request is not mergeable. Please rebase and repush.

@miq-bot
Copy link
Member

miq-bot commented May 23, 2018

Checked commit EsdrasVP@b9181ec with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 👍

@agrare
Copy link
Member

agrare commented May 23, 2018

@himdel can you help out with how this is usually handled at the UI level? I don't think hacking the base_model is correct but I'm not sure what is typically done in the UI to handle associations that aren't on the base class (which we do a lot of btw).

@saulotoledo
Copy link
Member

Hi @agrare and @himdel, @skateman just opened a PR at ManageIQ/manageiq-ui-classic#3980 to fix an issue caused by the demodulize changes. I think that can help in the current discussion. I've added some comments for it.

@skateman
Copy link
Member

skateman commented May 23, 2018

@agrare I have a feeling that this is against the logic of the base_model method...

@agrare
Copy link
Member

agrare commented May 23, 2018

I'm going to send this one over to @Fryguy

@EsdrasVP
Copy link
Member Author

@Fryguy @agrare @skateman @saulotoledo I think we're trying to acomplish things that don't fit together. The way I see, we have this options here:

  • We keep the relationship between Switch and PhysicalSwitch and redefine PhysicalSwitch base model (The current solution)
  • We keep the relationship between Switch and PhyiscalSwitch and refactor the pieces of code where base model is called to avoid this kind of problem (this is a major change)
  • We remove the relationship between Switch and PhysicalSwitch and keep them sharing the same table (this is even worst than the current solution)
  • We remove the relationship between Switch and PhysicalSwitch and create an physical interface for all physical infra, making PhysicalSwitch inherit from it (this is another major change)

What do you think of these? Is there something that I'm letting unnoticed?

@skateman
Copy link
Member

Hm, we're trying to solve a purely UI issue in the model...this is wrong. Let's take this discussion back to the UI, we have decorators there for this purrpose (pun intended). Anyway we would need to rename the quadicon settings keys so the case statement can be deleted. I will come up with something, just need some time for that. Until then here's quick ui-only fix: ManageIQ/manageiq-ui-classic#3980

@EsdrasVP
Copy link
Member Author

@skateman This would solve quadicon, however the physical switch listing would continue to fail, because even though that's a problem happening in the UI, the method used by it is from ManageIQ core (more precisely in manageiq/app/models/miq_report/search.rb).

@skateman
Copy link
Member

@EsdrasVP ok, what's the problem there and how it can be solved without changing the base_model?

@EsdrasVP
Copy link
Member Author

@skateman The method itself is not the problem. The problem is that the UI application controller calls get_view > paged_view_search > get_parent_targets. Since we are trying to obtain Physical Switches from a Physical Infra Provider, this method causes the listing to fail because it replaces PhysicalSwitch by its base model Switch. So an error occur because Physical Infra Provider doesn't have switches, it has physical switches.

@agrare
Copy link
Member

agrare commented May 24, 2018

@EsdrasVP is the problem really just the association name? Could we change or alias https://github.com/ManageIQ/manageiq/blob/master/app/models/manageiq/providers/physical_infra_manager.rb#L8 ?

@EsdrasVP
Copy link
Member Author

@agrare It's not only the association name. We could make it work if we change Physical Infra Manager to contain Switches and set its class_name as "PhysicalSwitch". But in order for that to work we have to replace :physical_switches by :switches in any call, and this affects model, parser and the save on inventory. And the bigger problem would be save the inventory, because after parsing all switch data a call will be made for a method in save_inventory_physical_infra.rb that binds its name to the passed model (in this case "switches"). The thing is that there is already a method to save inventory for switches in save_inventory_infra.rb. Doing this, we force the Ruby to break because it doesn't distinguish two methods with the same name by arguments number. So VMware, for instance, would break in this scenario. I think this solution would cause an even bigger mess.

@EsdrasVP
Copy link
Member Author

EsdrasVP commented Jun 4, 2018

I'm closing this PR since this was solved in ManageIQ/manageiq-ui-classic#3954.

@EsdrasVP EsdrasVP closed this Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants