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

Refactor get_rec_cls to get proper record class for various items #6224

Merged
merged 4 commits into from
Nov 6, 2019

Conversation

hstastna
Copy link

@hstastna hstastna commented Sep 23, 2019

Issue: #5924

We want to get rid of going through so many cases in get_rec_cls which is not very efficient. This PR addresses the solution. I've created a new method record_class which returns VmOrTemplate by default. No need to define this method in each controller.
I've also added some more special cases in some controllers in record_class which were missing in the original get_rec_cls method.

Note:
The following controllers need just the default record_class method:

  • auth_key_pair_cloud
  • availability_zone
  • cloud_tenant
  • cloud_volume
  • ems_cloud
  • flavor
  • host_aggregate
  • vm_cloud
  • vm_infra
  • vm_or_template

Note2:
You will probably not be able to test some actions, scenarios because of various issues, for example:
#6338, #6309, #6241, ...


TODO:

  • make record_class methods private
  • call super in controllers instead of VmOrTemplate
  • remove unnecessary record_class (same as default) from some controllers
  • fix failing existing specs
  • check the remaining controllers
  • add new specs

@miq-bot miq-bot added the wip label Sep 23, 2019
@hstastna hstastna force-pushed the Refactor_get_rec_cls branch 8 times, most recently from b97d331 to 80d4920 Compare September 30, 2019 13:42
Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

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

I'd suggest you to define a record_class in CiProcessing that defaults to VmOrTemplate and just redefine it in each controller where it's needed. You can also call super to fall back to the default where is needed (see examples).

Also the old get_rec_cls can be completely replaced by this new record_class method.

Great job BTW 👍

app/controllers/ems_cluster_controller.rb Outdated Show resolved Hide resolved
app/controllers/resource_pool_controller.rb Outdated Show resolved Hide resolved
@hstastna hstastna force-pushed the Refactor_get_rec_cls branch 4 times, most recently from 0e966c1 to a1384e1 Compare October 15, 2019 09:10
@hstastna hstastna force-pushed the Refactor_get_rec_cls branch 8 times, most recently from 29744c1 to 294230b Compare October 22, 2019 08:21
@hstastna
Copy link
Author

@miq-bot add_label refactoring

@hstastna hstastna force-pushed the Refactor_get_rec_cls branch 3 times, most recently from 2ffdb7c to b3dff65 Compare October 24, 2019 09:44
@skateman
Copy link
Member

skateman commented Nov 4, 2019

@hstastna is this ready for review?

@hstastna
Copy link
Author

hstastna commented Nov 4, 2019

@skateman Yes, it is.

@skateman
Copy link
Member

skateman commented Nov 4, 2019

I'm good with the changes, but we need some more clickety-testing...

@hstastna
Copy link
Author

hstastna commented Nov 4, 2019

Maybe @h-kataria @himdel @ZitaNemeckova @mzazrivec ? Could you please test this? Or you can ping anyone else who you think he/she could help :) Thanks in advance.

@himdel
Copy link
Contributor

himdel commented Nov 5, 2019

So, from what I can tell, the refactoring part is great, matches the old state perfectly :) 👍

One thing I would consider changing: all those super calls don't really make sense here, not if the original explicitly had VmOrTemplate - don't write super when you really mean VmOrTemplate, this is just making the code harder to reason about.

If the original was %w[all_vms vms].include?(params[:display]) ? VmOrTemplate : Storage, the idea behind the logic was that for vms, return VmOrTemplate. That's clear and easy to reason about.

Now, the logic is if you get specifically a VM, do something random, that may still return
VmOrTemplate. That doesn't sound right :). (All of those will break if the logic of the root implementation gets more complex than return VmOrTemplate.)

EDIT: to be clear, I'm not objecting to condition ? MyClass : super, but I am objecting to is_this_a_vm? ? super : MyClass.


As for the second part, I am confused about the new additions (EmsInfraController, HostController, ResourcePoolController)? Are those fixing specific bugs? Are those just in case?

From what I can tell, the functional difference is essentially this:

diff --git a/app/controllers/application_controller/ci_processing.rb b/app/controllers/application_controller/ci_processing.rb
index 21d8771718..bbbc9512eb 100644
--- a/app/controllers/application_controller/ci_processing.rb
+++ b/app/controllers/application_controller/ci_processing.rb
@@ -267,6 +267,28 @@ module ApplicationController::CiProcessing
       %w[all_vms vms].include?(params[:display]) || params[:pressed].starts_with?('miq_template') ? VmOrTemplate : EmsCluster
     when "storage"
       %w[all_vms vms].include?(params[:display]) ? VmOrTemplate : Storage
+    when "ems_infra"
+      case params[:pressed]
+      when /^ems_cluster/
+        EmsCluster
+      when /^orchestration_stack/
+        OrchestrationStack
+      when /^storage/
+        Storage
+      else
+        VmOrTemplate
+      end
+    when "host"
+      case params[:display] || @display
+      when 'storages'
+        Storage
+      when 'vms', 'miq_templates'
+        VmOrTemplate
+      else
+        Host
+      end
+    when "resource_pool"
+      %w[all_vms vms].include?(params[:display]) ? VmOrTemplate : ResourcePool
     else
       VmOrTemplate
     end

EDIT: yes, those new additions are fixes for things that didn't work in those places, will test :)

@hstastna
Copy link
Author

hstastna commented Nov 5, 2019

For the first note, @skateman what do you think? I like Martin's suggestion that I should better use VmOrTemplate and not call super if I really mean VmOrTemplate.


For the second note, I was going through (hopefully) all the pages, controllers manually, clicking on the actions and checking how they work in real and which record class should be set. This is why you recognize some functional difference. And then, I've found that this PR helps to fix some existing issues, for example #6338 which makes sense regarding my new additions. So the new additions are intentional, not 'just in case' 😏 .

@skateman
Copy link
Member

skateman commented Nov 5, 2019

@hstastna I'm good with getting rid of the super.

@hstastna hstastna force-pushed the Refactor_get_rec_cls branch 2 times, most recently from 5ec04e3 to 6f73e89 Compare November 6, 2019 14:59
@hstastna
Copy link
Author

hstastna commented Nov 6, 2019

Just a note that allow_any_instance_of present in some specs was not added by me and improvements regarding this are not a subject of this PR.

@himdel I've changed super to VmOrTemplate in appropriate controllers, according to the suggestions, so I think this PR is ready (after it gets green).

@himdel
Copy link
Contributor

himdel commented Nov 6, 2019

I didn't see anything break in ems_infra, host or resource_pool 👍 (but, I don't know what exactly was broken there before)

Will merge when green, thanks :)

@himdel
Copy link
Contributor

himdel commented Nov 6, 2019

@hstastna can you rebase please? @fhlavac fixed that travis error in #5854 (merged now)

Hilda Stastna added 4 commits November 6, 2019 20:02
Issue: ManageIQ#5924

Get proper record class for items displayed through Storage Relationships,
also for items displayed through Cluster's Relationships, items in Services
Workloads, VMs, Instances, Images displayed through various controllers.
@miq-bot
Copy link
Member

miq-bot commented Nov 6, 2019

Some comments on commits hstastna/manageiq-ui-classic@5269ad8~...cf2f25b

spec/controllers/application_controller/ci_processing_spec.rb

  • ⚠️ - 213 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 273 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 360 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 369 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 431 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 510 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 570 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

@miq-bot
Copy link
Member

miq-bot commented Nov 6, 2019

Checked commits hstastna/manageiq-ui-classic@5269ad8~...cf2f25b with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
25 files checked, 0 offenses detected
Everything looks fine. ⭐

@himdel himdel merged commit 3b51971 into ManageIQ:master Nov 6, 2019
@himdel himdel added this to the Sprint 124 Ending Nov 11, 2019 milestone Nov 6, 2019
@himdel himdel self-assigned this Nov 6, 2019
h-kataria added a commit to h-kataria/manageiq-ui-classic that referenced this pull request Apr 16, 2020
on upstream `get_rec_cls` was replaced by using `record_class` in ManageIQ#6224
@himdel
Copy link
Contributor

himdel commented Aug 22, 2020

Backported to ivanchuk via #7241

@miq-bot add_label ivanchuk/backported

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.

4 participants