Description of problem: Red Hat Satellite 6.4 upgrade fails with error Validation failed: Name has already been taken at db:migrate stage. ~~~~~ [DEBUG 2018-11-16T14:30:24 main] ActiveRecord::RecordInvalid: Validation failed: Name has already been taken [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/validations.rb:78:in `raise_validation_error' [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/validations.rb:50:in `save!' [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/attribute_methods/dirty.rb:43:in `save!' [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/transactions.rb:313:in `block in save!' [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/transactions.rb:384:in `block in with_transaction_returning_status' [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:233:in `transaction' [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/transactions.rb:210:in `transaction' [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/transactions.rb:381:in `with_transaction_returning_status' [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/transactions.rb:313:in `save!' [DEBUG 2018-11-16T14:30:24 main] /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.6/lib/active_record/suppressor.rb:46:in `save!' [DEBUG 2018-11-16T14:30:24 main] /usr/share/foreman/app/models/role.rb:207:in `add_permissions!' [DEBUG 2018-11-16T14:30:24 main] /usr/share/foreman/app/services/foreman/plugin/role_lock.rb:45:in `block in update_plugin_role_permissions' [DEBUG 2018-11-16T14:30:24 main] /usr/share/foreman/app/models/role.rb:85:in `ignore_locking' ~~~~~ Version-Release number of selected component (if applicable): Red Hat Satellite 6.4 Steps to Reproduce: Run the upgrade on Red Hat Satellite 6.3.5 -> 6.4 # yum update # foreman-maintain upgrade run --target-version 6.4 --whitelist="disk-performance" Actual results: - The upgrade fails with the error. Expected results: - The upgrade should be completed. Additional info: Looks like an issue with the defaults "Roles" present in the satellite server.
Could we get the full log or output for "foreman-rake db:migrate" please? Since not everyone hit this issue, the reproducer or DB export would also help.
Pending workaround: Step 1: Find out the duplicate roles using foreman-rake Role.select("COUNT(name) as total, name") .group(:name).having("COUNT(name) > 1").order(:name).map{|p| {p.name => p.total} } => [{"Discovery Manager"=>2}] Step 2: Rename the duplicate Record cat <<FIX | foreman-rake console role_name = 'Discovery Manager' r = Role.find_by_name(role_name) r.builtin = 2 r.name = 'Duplicate ' + role_name r.save!(validate: false) FIX Try to upgrade the Satellite
The commands were a little confusing for me because of the formatting. This is what I ran that worked for me for discovering the duplicate roles: > printf 'Role.select("COUNT(name) as total, name").group(:name).having("COUNT(name) > 1").order(:name).map{|p| {p.name => p.total} }\n' | foreman-rake console From that, I got: > => [{"Discovery Manager"=>3}, {"Remote Execution Manager"=>2}, {"Remote Execution User"=>2}] I then ran these series of commands to rename the duplicates: > cat <<FIX | foreman-rake console > role_name = 'Discovery Manager' > r = Role.find_by_name(role_name) > r.builtin = 2 > r.name = 'Duplicate 1' + role_name > r.save!(validate: false) > FIX > > cat <<FIX | foreman-rake console > role_name = 'Discovery Manager' > r = Role.find_by_name(role_name) > r.builtin = 2 > r.name = 'Duplicate 2' + role_name > r.save!(validate: false) > FIX > > cat <<FIX | foreman-rake console > role_name = 'Remote Execution Manager' > r = Role.find_by_name(role_name) > r.builtin = 2 > r.name = 'Duplicate ' + role_name > r.save!(validate: false) > FIX > > cat <<FIX | foreman-rake console > role_name = 'Remote Execution User' > r = Role.find_by_name(role_name) > r.builtin = 2 > r.name = 'Duplicate ' + role_name > r.save!(validate: false) > FIX I'm taking another shot at my upgrade, now.
That did the trick for me.
I've hit the same issue with my Satellite upgrade from 6.4 to 6.5. Run the steps mentioned in #12, which progressed it, but now getting: Caused by: ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "katello_contents" violates foreign key constraint "katello_produ ct_content_content_id_fk" on table "katello_product_contents" DETAIL: Key (id)=(2636) is still referenced from table "katello_product_contents". : DELETE FROM "katello_contents" WHERE "katello_contents"."id" = $1 Steps: 1. foreman-maintain upgrade run 2. upgrade broke, run the steps from #12 3. foreman-maintain upgrade run --target-version 6.5 --whitelist="disk-performance,hammer-setup,hammer-ping" ( Need to now skip the hammer steps because everything is broken ) 4. Breaks with the foreign key constraint error above. The services seem to be running with katello-service status, but the webui has the old: Service unavailable ERF64-6496 [Foreman::MaintenanceException]: There are migrations pending in the system. This is my home satellite server. So I'm happy to experiment with anything you want, or provide any info if you feel this is relevant to the same issue.
Mine might actually be this: https://access.redhat.com/solutions/4156421 I didn't check if there was a new 6.4.z available before I did --target-version 6.5. We can ignore my issue, it's probably not related to the original failure.
Created redmine issue https://projects.theforeman.org/issues/27247 from this bug
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2019:3172