1.20.3: Problems creating Location after enabling Locations

Hi out there,

currently preparing for migration to 1.21. As Locations will be permanently enabled with 1.21 I thought it would be a good idea to enable and properly set them up before migrating. Organizations were enabled and in use before.

Problem:
After enabling locations in settings.yml and logging in to the Web UI I am required to create a location. When submitting the first page of the Wizard the page reloads and stays on Setp One. I cannot go any further.

Trying to do this with hammer i get an error message “Could not create the location: Provisioning templates is invalid”.

With Debug Logging enabled here’s the Log output when using the Web UI:

2019-09-12T17:24:17 [I|app|] Started POST "/locations" for X.X.X.,X at 2019-09-12 17:24:17 +0200
2019-09-12T17:24:17 [I|app|dd759] Processing by LocationsController#create as HTML
2019-09-12T17:24:17 [I|app|dd759]   Parameters: {"utf8"=>"✓", > "authenticity_token"=>"XXXXXXXXXXXXX", "location"=>{"name"=>"Test", "description"=>""}, "comm
it"=>"Submit"}
2019-09-12T17:24:17 [I|app|dd759] Current user set to stef (admin)
2019-09-12T17:24:17 [D|app|dd759] Current location set to none
2019-09-12T17:24:17 [D|app|dd759] Current organization set to TestLab 
2019-09-12T17:24:18 [I|aud|dd759] Location (12) create event on name Test
2019-09-12T17:24:18 [I|aud|dd759] Location (12) create event on ignore_types []
2019-09-12T17:24:18 [I|aud|dd759] Location (12) create event on ancestry
2019-09-12T17:24:18 [I|aud|dd759] Location (12) create event on description
2019-09-12T17:24:18 [E|app|dd759] Failed to save: Provisioning templates is invalid
2019-09-12T17:24:18 [I|app|dd759]   Rendering taxonomies/new.html.erb within layouts/application
2019-09-12T17:24:18 [I|app|dd759]   Rendered taxonomies/_step1.html.erb (6.9ms)
2019-09-12T17:24:18 [I|app|dd759]   Rendered taxonomies/new.html.erb within layouts/application (7.6ms)
2019-09-12T17:24:18 [I|app|dd759]   Rendered layouts/_application_content.html.erb (1.1ms)
2019-09-12T17:24:18 [I|app|dd759]   Rendering layouts/base.html.erb
2019-09-12T17:24:18 [I|app|dd759]   Rendered layouts/base.html.erb (19.5ms)
2019-09-12T17:24:18 [I|app|dd759] Completed 200 OK in 1138ms (Views: 27.4ms | ActiveRecord: 145.4ms)

And this is the output when using Hammer:

2019-09-12T17:28:29 [I|app|] Started POST "/api/locations" for X.X.X.X: at 2019-09-12 17:28:29 +0200
2019-09-12T17:28:29 [I|app|32843] Processing by Api::V2::LocationsController#create as JSON
2019-09-12T17:28:29 [I|app|32843]   Parameters: {"location"=>{"name"=>"Test"}, "apiv"=>"v2"}
2019-09-12T17:28:29 [D|app|32843] LDAP auth with user stef against LDAP-LDAP1
2019-09-12T17:28:30 [D|app|32843] Retrieved LDAP Attributes for stef: {:dn=>"XXXXXXX"}
2019-09-12T17:28:30 [D|app|32843] Authenticated user stef against LDAP-LDAP1 authentication source
2019-09-12T17:28:30 [D|app|32843] Current user set to foreman_admin (admin)
2019-09-12T17:28:30 [D|app|32843] Updating user stef attributes from auth source: [:dn]
2019-09-12T17:28:30 [I|app|32843] Skipping user group update for user stef as usergroup_sync is disabled
2019-09-12T17:28:30 [I|app|32843] Authorized user stef(stef)
2019-09-12T17:28:30 [I|app|32843] Current user set to stef (admin)
2019-09-12T17:28:30 [D|app|32843] Current location set to none
2019-09-12T17:28:30 [D|app|32843] Current organization set to none
2019-09-12T17:28:30 [D|app|32843] Current location set to none
2019-09-12T17:28:30 [D|app|32843] Current organization set to none
2019-09-12T17:28:30 [I|aud|32843] Location (13) create event on name Test
2019-09-12T17:28:30 [I|aud|32843] Location (13) create event on ignore_types []
2019-09-12T17:28:30 [I|aud|32843] Location (13) create event on ancestry
2019-09-12T17:28:30 [I|aud|32843] Location (13) create event on description
2019-09-12T17:28:30 [E|app|32843] Unprocessable entity Location (id: new):
 |   Provisioning templates is invalid
 |
2019-09-12T17:28:30 [I|app|32843]   Rendering api/v2/errors/unprocessable_entity.json.rabl within api/v2/layouts/error_layout
2019-09-12T17:28:30 [I|app|32843]   Rendered api/v2/errors/unprocessable_entity.json.rabl within api/v2/layouts/error_layout (0.8ms)
2019-09-12T17:28:30 [D|app|32843] Body: {
 |   "error": {"id":null,"errors":{"name":[],"provisioning_templates":["is invalid"]},"full_messages":["Provisioning templates is invalid"]}
 | }
 |
2019-09-12T17:28:30 [I|app|32843] Completed 422 Unprocessable Entity in 1108ms (Views: 1.6ms | ActiveRecord: 133.7ms)

Expected outcome:

Location gets created.

Foreman and Proxy versions:

Foreman: 1.20.3
Proxy: 1.20.3

Other relevant data:
Just for testing purposes, I created a snapshot (the server is a vm) and tried migrating to 1.21. db::seed failed with a message I have not at hand, but foreman started. After logging in, the situation is the same as with 1.20.3

Any help is appreciated :wink:

stef

This looks like one of your provisioning templates is invalid, and when trying to add the location to it the validation fails.

As a side note, you do not have to create a location before the upgrade, a default one will be created as part of the upgrade process and all existing resources will be added to it. If you could try upgrading again, perhaps the error message will give us another hint at what went wrong.

Hi Tomer,

so I upgraded to 1.21.3 again, here’s the output when I run

foreman-rake db:seed

Seeding /usr/share/foreman/db/seeds.d/020-permissions_list.rb
Seeding /usr/share/foreman/db/seeds.d/020-roles_list.rb
Seeding /usr/share/foreman/db/seeds.d/030-auth_sources.rb
Seeding /usr/share/foreman/db/seeds.d/030-permissions.rb
Seeding /usr/share/foreman/db/seeds.d/035-admin.rb
Seeding /usr/share/foreman/db/seeds.d/040-roles.rb
Seeding /usr/share/foreman/db/seeds.d/050-taxonomies.rb
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Provisioning templates is invalid
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/validations.rb:80:in `raise_validation_error'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/validations.rb:52:in `save!'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:315:in `block in save!'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:387:in `block in with_transaction_returning_status'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:252:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:212:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:385:in `with_transaction_returning_status'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:315:in `save!'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/suppressor.rb:48:in `save!'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:375:in `insert_record'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_association.rb:36:in `insert_record'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_through_association.rb:42:in `insert_record'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:438:in `block (2 levels) in concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:458:in `replace_on_target'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:282:in `add_to_target'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:436:in `block in concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:434:in `each'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:434:in `concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_association.rb:116:in `concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_through_association.rb:27:in `concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:119:in `block in concat'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:134:in `block in transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:252:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:212:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:133:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:119:in `concat'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_through_association.rb:21:in `concat'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:414:in `replace_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:250:in `block in replace'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:134:in `block in transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `block in transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:239:in `block in within_new_transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:236:in `within_new_transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:212:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:133:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:250:in `replace'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:41:in `writer'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/builder/association.rb:116:in `locations='
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:25:in `block (5 levels) in <top (required)>'
/opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/auditor.rb:336:in `without_auditing'
/opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/auditor.rb:105:in `without_auditing'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:24:in `block (4 levels) in <top (required)>'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/delegation.rb:41:in `each'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/delegation.rb:41:in `each'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:23:in `block (3 levels) in <top (required)>'
/opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/auditor.rb:336:in `without_auditing'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:8:in `block (2 levels) in <top (required)>'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:7:in `each'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:7:in `block in <top (required)>'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:100:in `as'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:106:in `as_anonymous_admin'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:6:in `<top (required)>'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `block in load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
/usr/share/foreman/db/seeds.rb:36:in `block (2 levels) in <top (required)>'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:100:in `as'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:106:in `as_anonymous_admin'
/usr/share/foreman/db/seeds.rb:35:in `block in <top (required)>'
/usr/share/foreman/db/seeds.rb:29:in `each'
/usr/share/foreman/db/seeds.rb:29:in `<top (required)>'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `block in load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/engine.rb:551:in `load_seed'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/tasks/database_tasks.rb:281:in `load_seed'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/railties/databases.rake:194:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)

and here’s

foreman-rake db:seed --trace

** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:abort_if_pending_migrations
Seeding /usr/share/foreman/db/seeds.d/020-permissions_list.rb
Seeding /usr/share/foreman/db/seeds.d/020-roles_list.rb
Seeding /usr/share/foreman/db/seeds.d/030-auth_sources.rb
Seeding /usr/share/foreman/db/seeds.d/030-permissions.rb
Seeding /usr/share/foreman/db/seeds.d/035-admin.rb
Seeding /usr/share/foreman/db/seeds.d/040-roles.rb
Seeding /usr/share/foreman/db/seeds.d/050-taxonomies.rb
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Provisioning templates is invalid
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/validations.rb:80:in `raise_validation_error'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/validations.rb:52:in `save!'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:315:in `block in save!'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:387:in `block in with_transaction_returning_status'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:252:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:212:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:385:in `with_transaction_returning_status'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:315:in `save!'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/suppressor.rb:48:in `save!'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:375:in `insert_record'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_association.rb:36:in `insert_record'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_through_association.rb:42:in `insert_record'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:438:in `block (2 levels) in concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:458:in `replace_on_target'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:282:in `add_to_target'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:436:in `block in concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:434:in `each'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:434:in `concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_association.rb:116:in `concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_through_association.rb:27:in `concat_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:119:in `block in concat'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:134:in `block in transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:252:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:212:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:133:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:119:in `concat'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/has_many_through_association.rb:21:in `concat'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:414:in `replace_records'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:250:in `block in replace'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:134:in `block in transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `block in transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:239:in `block in within_new_transaction'
/opt/rh/rh-ruby25/root/usr/share/ruby/monitor.rb:226:in `mon_synchronize'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:236:in `within_new_transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/transactions.rb:212:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:133:in `transaction'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:250:in `replace'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:41:in `writer'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/builder/association.rb:116:in `locations='
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:25:in `block (5 levels) in <top (required)>'
/opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/auditor.rb:336:in `without_auditing'
/opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/auditor.rb:105:in `without_auditing'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:24:in `block (4 levels) in <top (required)>'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/delegation.rb:41:in `each'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/delegation.rb:41:in `each'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:23:in `block (3 levels) in <top (required)>'
/opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/auditor.rb:336:in `without_auditing'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:8:in `block (2 levels) in <top (required)>'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:7:in `each'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:7:in `block in <top (required)>'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:100:in `as'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:106:in `as_anonymous_admin'
/usr/share/foreman/db/seeds.d/050-taxonomies.rb:6:in `<top (required)>'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `block in load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
/usr/share/foreman/db/seeds.rb:36:in `block (2 levels) in <top (required)>'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:100:in `as'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:106:in `as_anonymous_admin'
/usr/share/foreman/db/seeds.rb:35:in `block in <top (required)>'
/usr/share/foreman/db/seeds.rb:29:in `each'
/usr/share/foreman/db/seeds.rb:29:in `<top (required)>'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `block in load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/engine.rb:551:in `load_seed'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/tasks/database_tasks.rb:281:in `load_seed'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/railties/databases.rake:194:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:195:in `block in invoke_with_call_chain'
/opt/rh/rh-ruby25/root/usr/share/ruby/monitor.rb:226:in `mon_synchronize'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:188:in `invoke_with_call_chain'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:116:in `block in top_level'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:125:in `run_with_threads'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/opt/rh/rh-ruby25/root/usr/bin/rake:23:in `load'
/opt/rh/rh-ruby25/root/usr/bin/rake:23:in `<main>'
Tasks: TOP => db:seed

I also got the idea that something must be wrong with the templates, but what exactly is an invalid template? I looked for bogus characters and such stuff, but didn’t find anything …

Greetings, Stefan

can you add the following line to /usr/share/foreman/db/seeds.d/050-taxonomies.rb before line 25 (which is the one failing)

puts template.name

and rerun the db:seed?
This will at least indicate which is the problematic template (the last one printed before it fails).
I will work on a patch to make this code more defensive so it handles such failures beter.

i’ve opened a PR that should fix the issue, you can try to manually apply the patch to your instance and run the seed again:

Hi,

I have been able to apply your patch. Running db:seed again gives me a list of templates which are invalid. There were 13 invalid templates.
db:seed completes fine, however, when I start httpd and log in for the first time Foreman still wants me to create a first location, and I cannot save it (same behaviour as before). So I think I have to fix the templates before migrating.
6 of them were ‘standard’ templates, still locked, and as far as I can say they have never been touched. The other 7 were templates we have written ourselves. Those 7 are in use every day, can be rendered, modified, etc.
I don’t want to just delete them as it would require removing dependencies before … so what does it actually mean that a template is invalid? Any chance to get that fixed?

This sounds like somehow one of the default templates have become invalid on your server. There are multiple reasons that can cause a template to become invalid, such as duplicate name, missing content and more.
When creating a new location, all default templates are assigned to it - which would fail if one of them is invalid, causing the location creation itself to fail. Then when the seed tries to assign the rest of the templates to the location it failed to created, that step also fails.

You can try deleting the default templates and re-seeding them prior to the upgrade, if they are not in use. This is a potentially destructive step so make sure to back up the DB first!
To do this, run the following in foreman-rake console:

ProvisioningTemplate.where(:default => true).destroy_all

followed by rake db:seed.

if any of the default templates are in use, you will need to find the broken one and fix it - you can possibly identify it using the following code in the console:

ProvisioningTemplate.where(:default => true).each do |template|
  puts template.name
  template.save!
end

this will simply try to save each template and will fail once you get to the invalid one.

I’ve opened another PR to fix the issue with the default templates becoming invalid:

This should allow you to get the seed working properly even if any of the templates is invalid. (Would still be a good idea to identify which one failed, but this will unblock your upgrade)

Hi,

with the help of the 4 lines of code you have provided for the rake console I was able to identify what really caused the trouble: there were duplicates of two of the default templates: 7x ‘Discovery Debian kexec’ and 8x ‘Discovery RedHat kexec’. All but one of them were unlocked. I cannot say what or when they were created, but removing all of them execpt the locked one fixed my issues. After deleting I was able to enable Locations in 1.20 and create a first Location via the wizard. Also, without creating the Location I was able to migrate to 1.21.3 and got the default Location created during the migration.

I even made the step further to 1.22.1 without any issues, currently testing if everything works as before.

So this issue ist fixed for me, Big Thanks to you, Tomer :wink:

One thing left to say here is that the puts-line we added as a first shot to /usr/share/foreman/db/seeds.d/050-taxonomies.rb correctly showed 13 invalid templates, but the names it printed out were wrong.

so far … Stefan

1 Like

Thanks, glad to hear that the upgrade worked! Thanks to your feedback we’ll be releasing 1.21.4 shortly which includes these fixes.