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

Make MiqProductFeature seeding pluggable #18806

Merged
merged 2 commits into from May 24, 2019

Conversation

Fryguy
Copy link
Member

@Fryguy Fryguy commented May 23, 2019

@jrafanie Please review.

I want to run through other repo tests before merge, just to be sure this doesn't break anything.

  • manageiq-ui-classic
  • manageiq-api

@Fryguy Fryguy force-pushed the product_feature_seed_plugins branch from 432651a to ed02420 Compare May 23, 2019 20:03
@miq-bot
Copy link
Member

miq-bot commented May 23, 2019

Checked commits Fryguy/manageiq@cb61dd4~...ed02420 with ruby 2.3.3, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
6 files checked, 2 offenses detected

spec/models/miq_product_feature_spec.rb

@Fryguy
Copy link
Member Author

Fryguy commented May 24, 2019

cc @martinpovolny

@Fryguy
Copy link
Member Author

Fryguy commented May 24, 2019

Note that I created a Seeding module in the PR, but didn't move much into it yet...I plan to do a larger refactoring to move that and improve the performance, but wanted to unstick any other PRs waiting on this feature first.

end

def seed_core_files
Dir.glob("#{FIXTURE_PATH}/*.y{,a}ml").sort
Copy link
Member

Choose a reason for hiding this comment

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

I appreciate the sort on Dir.glob ❤️

Copy link
Member Author

Choose a reason for hiding this comment

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

I basically always sort that method now, because of its unpredictability... I'm almost tempted to create a more_core_extensions method that enforces it :)

Dir.glob(path.join("*.yml")).each do |fixture|
seed_from_hash(YAML.load_file(fixture), seen, root_feature)
other_files.each do |file|
seed_from_array(YAML.load_file(file), seen, root_feature)
Copy link
Member

Choose a reason for hiding this comment

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

Let me say this to make sure I understand.

  1. seed_from_hash is used for the core product features where the "everything" identifier is the root feature and all children fall under it

  2. seed_from_array is for seeding an array of features all at the same level: direct children of the root "everything" feature. Each can have their own trees of features but they all get the "everything" feature as the root.

Copy link
Member Author

@Fryguy Fryguy May 24, 2019

Choose a reason for hiding this comment

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

Kind of? Yes. I didn't want to add the seed_from_array, but plugins can bring an array of features, so it made sense to abstract walking an array of hashes.

@@ -18,8 +20,6 @@ class MiqProductFeature < ApplicationRecord
validates_presence_of :identifier
validates_uniqueness_of :identifier

FIXTURE_PATH = Rails.root.join(*["db", "fixtures", table_name])
Copy link
Member

Choose a reason for hiding this comment

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

haha, I didn't see this until now... I guess we were really worried about hardcoding "miq_product_features"... I can't believe I didn't see table_name before...


module ClassMethods
def seed_files
return seed_root_filename, seed_core_files + seed_plugin_files
Copy link
Member

@jrafanie jrafanie May 24, 2019

Choose a reason for hiding this comment

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

@Fryguy If I'm reading correctly, this doesn't break the UI plugin work by @martinpovolny because they should still be picked up in seed_core_file, right? Note, I'm not sure if we still need it but I'm making sure that I understand it. It looks to be still intact.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, this keeps @martinpovolny 's original "directory of feature yamls" in core, however that's not being used anywhere, so while we have it we may want to consider dropping it. On the plugin side though it could be useful to have separate yamls per feature in a dir, so I basically made plugins work like core.

Choose a reason for hiding this comment

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

have it we may want to consider dropping it

Yes, I'd like to see it dropped. Also it does not support any nesting if I remember correctly.

Someone might me using it: https://documentation.commvault.com/commvault/v11_adminconsole/article?p=87519.htm and they should be provided with a way to migrate.

What we need with this new way is documentation.

@jrafanie
Copy link
Member

LGTM so far

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.

👍 LGTM


module ClassMethods
def seed_files
return seed_root_filename, seed_core_files + seed_plugin_files
Copy link
Member

Choose a reason for hiding this comment

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

As discussed, this return value feels strange to me, but I understand why it's done this way. Maybe in a future PR we can pull the everything feature out of the root file and remove the special handling of that file.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like this idea, and definitely think we should do it in a followup.

@Fryguy
Copy link
Member Author

Fryguy commented May 24, 2019

@jrafanie I just realized this might not play nice with i18n of features, due to https://github.com/ManageIQ/manageiq/blob/master/config/locale_task_config.yaml#L3-L5

However, I'd like to work on that in a follow up. cc @mzazrivec

@bdunne bdunne mentioned this pull request May 24, 2019
@Fryguy
Copy link
Member Author

Fryguy commented May 24, 2019

@jrafanie This is good to go

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

5 participants