-
Notifications
You must be signed in to change notification settings - Fork 981
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
Fixes #37143 - Register plugin's template dirs for db:seed #10038
Fixes #37143 - Register plugin's template dirs for db:seed #10038
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For plugin usage, see https://github.com/theforeman/foreman_ansible/pull/692/files
e63255f
to
9a16453
Compare
Wrong link? :) |
9a16453
to
53ac836
Compare
53ac836
to
161f52f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative thought: would it make sense to adopt a convention? Convention over configuration is a common design principle in Rails.
In our case it would mean that for every plugin we would agree on a directory path and if that path exists, Foreman loads it.
Also, after thinking why we didn't have this earlier, we did, but just in a different way: https://github.com/theforeman/foreman_openscap/blob/master/db/seeds.d/75-job_templates.rb. Does it mean this PR should unify the way the templates are being seeded? If so, wouldn't it conflict with the current way? I mean, it would mean some plugins will try to seed templates twice... |
That has a condition, but Foreman has a mechanism to depend on plugins. We would need to migrate the plugins to adopt that if needed. And more realistically, REX should provide a seed that checks all job templates. That may be more complex, but not impossible.
I like that idea. Perhaps we can deal with it by calling Though one possible obvious way is to create a new directory. I've always thought |
I like it and agree. This PR would require changes in the plugins anyway, so let's go with the convention way.
Yes, that's the goal. I will update the code to follow a convention that all plugins must have templates in the |
I'd give my vote for that. Even though I'm quite used to look for the templates in |
161f52f
to
082bc3e
Compare
082bc3e
to
c14ffc9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test failures look related.
c14ffc9
to
7c9137e
Compare
Foreman watch templates in `:plugin/app/templates/:kind` directories. Other directories can be registered with `:register_template_dirs` method.
7c9137e
to
e530f45
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested, but LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just tested it by adding a new template to the default path (app/templates) of a plugin and the template didn't seed automatically. I think the new paths don't get involved into seeding at all. It seems seeding is done by https://github.com/theforeman/foreman/blob/develop/app/services/foreman_seeder.rb#L37 which uses seed directories (https://github.com/theforeman/foreman/blob/develop/app/services/foreman_seeder.rb#L14) in which there is a file running a seed when loaded (https://github.com/theforeman/foreman/blob/develop/db/seeds.d/090-report_templates.rb#L3). Each template kind has its own file being loaded separately, these "mini-seeders" use SeedHelper.*_templates
helpers explicitly. That's why it works now, but doesn't work with the new approach.
The fix is probably lying in adjustment of https://github.com/theforeman/foreman/blob/develop/app/services/foreman_seeder.rb#L14-L15.
Please, correct me if it works. Maybe I missed something...
@stejskalleos Is there another PR replacing this? |
No description provided.