Foreman 1.24.3 -> 3.0 Upgrade Rake Failures

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- `each'
/usr/share/gems/gems/activerecord- `each'
/usr/share/foreman/db/migrate/20210115124508_template_kind_registration.rb:25:in `up'
/usr/share/gems/gems/activerecord- `exec_migration'
/usr/share/gems/gems/activerecord- `block (2 levels) in migrate'
/usr/share/gems/gems/activerecord- `block in migrate'
/usr/share/gems/gems/activerecord- `with_connection'
/usr/share/gems/gems/activerecord- `migrate'
/usr/share/gems/gems/activerecord- `migrate'
/usr/share/gems/gems/activerecord- `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:
This Commit:
This Line:

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:

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
1.24 => 2.1 => 2.3 => 2.5 => 3


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