Project

General

Profile

Bug #16821

Updated by Dominic Cleal over 7 years ago

All of the plugins that use permissions are now failing. AccessPermissionsTest in core attempts to look for a Permission for the plugins' routes but it never succeeds.  

 Here's why: 

 During plugin initialization the engine calls 'permission' to register permissions in the db: https://github.com/theforeman/foreman_discovery/blob/develop/lib/foreman_discovery/engine.rb#L49 
 'permission' in core will not run because there are pending migrations: https://github.com/theforeman/foreman/blob/develop/app/services/foreman/plugin.rb#L219 

 The test checks in the database for those permissions, so it fails. It used to work before #16557 because the 'test:lib' task ran after 'test:unit', and on the 2nd Rails initialization, there were no 'pending_migrations' so permissions from plugins were added just fine. 

 A few possible solutions: 

   
   * Modify the task in foreman-infra so that it runs 'RAILS_ENV=test rake db:migrate' prior to running tests. Currently Foreman kind of does this in the background via this setting (https://github.com/theforeman/foreman/blob/develop/config/environments/test.rb#L59) but it happens after plugins initialization, so during the 'permission' calls there are still pending migrations. 
   * Call ActiveRecord::Migration.maintain_test_schema! at some point before plugin initialization 
   * Modify the code so that permissions can be added even if there are pending_migrations (bad idea as the table may not exist) 
   * Add plugin permissions via fixtures (we'd have to do this in all plugins now, and adding fixtures in plugins is annoying)

Back