Foreman 1.24.3 -> 3.0 Upgrade Rake Failures

Problem:
When upgrading - the Rake Tasks fail - specifically:

Rubocop not loaded.
Apipie cache enabled but not present yet. Run apipie:cache rake task to speed up API calls.
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Notice: /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns:
undefined method `operatingsystems' for nil:NilClass
/usr/share/foreman/db/migrate/20210115124508_template_kind_registration.rb:26:in `block in up'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/relation/delegation.rb:87:in `each'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/relation/delegation.rb:87:in `each'
/usr/share/foreman/db/migrate/20210115124508_template_kind_registration.rb:25:in `up'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/migration.rb:831:in `exec_migration'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/migration.rb:812:in `block (2 levels) in migrate'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/migration.rb:811:in `block in migrate'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:471:in `with_connection'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/migration.rb:810:in `migrate'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/migration.rb:1002:in `migrate'
/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/migration.rb:1310:in `block in execute_migration_in_transaction

’
Expected outcome:
It Succeeds

Foreman and Proxy versions:
Foreman 3.0
Foreman and Proxy plugin versions:
Foreman 3.0
Distribution and version:
Foreman 3.0
Other relevant data:

We believe we have the issue traced back to this Bug/PR: https://projects.theforeman.org/issues/31663
This Commit: https://github.com/theforeman/foreman/pull/8256
This Line: https://github.com/theforeman/foreman/blob/3.0.0/db/migrate/20210115124508_template_kind_registration.rb#L26

Logically - it looks like in 1.24 neither ā€˜Linux registration default’ or ā€˜default_host_init_config_template’ exist yet. Following the logic up to line 26, it essentially ā€œskipsā€ most of it - then whines because at line 26 it’s nil. I’m unsure if a seed task would/should ā€œcreateā€ these - i can’t find any other references in the codebase as to how they get created initially, either in seeds, or migrations. However - i cannot run a ā€œseedā€ until the migration completes either :-X

in our lab we were able to ā€œwork aroundā€ it by using the ruby console to create the missing ā€œoldā€ value manually - after which it ā€œworkedā€ in that it completed successfully without erroring. Still working out whether this is ā€œokā€ or if it just missed something important.

Our error seems somewhat similar to the comment by ā€œaresā€ on the PR above: https://github.com/theforeman/foreman/pull/8256#issuecomment-787467165

At the end of the day - we are skipping several major versions, but i believe the migrations are supposed to be fully atomic, and it seems like they aren’t quite for this setting migration at least?

upgrade path for foreman is version x => x+1, maximum x=>x+2 , that is to say :
1.24 => 2.0 => 2.1 => 2.2 => 2.3 => 2.4 => 2.5 => 3.0
or
1.24 => 2.1 => 2.3 => 2.5 => 3

2 Likes

It is highly recommended to upgrade Foreman one version at time, as @bbarret is mentioning above.

We do not test migrations across all versions, that would be impossible to test with all the data and variations, we just test migrations from previous version to the new one.

1 Like