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

[WIP] fix association between EMS and ConfigurationSystem #16798

Closed
wants to merge 2 commits into from

Conversation

jameswnl
Copy link
Contributor

The association is wrong and should be all set in their own base classes.

Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

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

This change is good, but are you going to move the rest of the relations as well? I would have expected that in the same PR.

@jameswnl
Copy link
Contributor Author

@bdunne yes, that's what I am looking, seems like all the following,

  has_many :configuration_profiles,       :dependent => :destroy, :foreign_key => "manager_id"
  has_many :configuration_scripts,        :dependent => :destroy, :foreign_key => "manager_id"
  has_many :credentials,                  :class_name => "ManageIQ::Providers::AutomationManager::Authentication",
           :as => :resource, :dependent => :destroy
  has_many :inventory_groups,             :dependent => :destroy, :foreign_key => "ems_id", :inverse_of => :manager
  has_many :inventory_root_groups,        :dependent => :destroy, :foreign_key => "ems_id", :inverse_of => :manager
  has_many :configuration_script_sources, :dependent => :destroy, :foreign_key => "manager_id"
  has_many :configuration_script_payloads, :through => :configuration_script_sources

@miq-bot
Copy link
Member

miq-bot commented Jan 11, 2018

Checked commits jameswnl/manageiq@7207258~...832f547 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 5 offenses detected

app/models/ext_management_system.rb

@@ -29,6 +29,11 @@ def self.supported_types_and_descriptions_hash

belongs_to :provider
has_many :child_managers, :class_name => 'ExtManagementSystem', :foreign_key => 'parent_ems_id'
has_many :configured_systems, :dependent => :destroy, :foreign_key => "manager_id"
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it was on purpose, that the relations were only on automation_manager, we do the same for cloud_manager, etc.

I think the base of you failing specs is that the mock data are not valid. Each model has to have a correctly filled STI type, like it always has when it comes from a refresh.

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, true that the failing specs can be fixed by using the corresponding factory for automation_manager.

But what I have question about is that, why on one side we define the relationship in base class ExtManagementSystem and the other side in the subclass AutomationManager? Is this a proper practice in rails?

The other point is that: If the concept of a EMS has many ConfiguredSystem is valid at base class level, we should be able to test it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm so I think the idea was to have manager specific relations only under the specific manager, e.g. cloud manager https://github.com/Ladas/manageiq/blob/be7d05ca1089fa0c06802c2bfa666d5b9e10f455/app/models/manageiq/providers/cloud_manager.rb#L17

Then the relations would not work, unless the proper STI types are set, so all specs have to set them right.

But I've seen that e.g. if relation is shared by more types of managers, it goes to ext_management_system.rb. Which is your case, so this should be acceptable.

Or e.g. for complex virtual attributes, it easier to have the relation on base class, otherwise it might give unexpected results.

@chrisarcand
Copy link
Member

Is this still valid? @jameswnl @agrare

@agrare
Copy link
Member

agrare commented Mar 22, 2018

I think the consensus is that this is not needed in the base model since configured_system makes no sense for infra/cloud/physical/network/etc... managers.

@agrare agrare closed this Mar 22, 2018
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.

7 participants