Bug 1651389 - Red Hat Satellite 6.4 upgrade fails with error Validation failed: Name has already been taken at db:migrate stage
Summary: Red Hat Satellite 6.4 upgrade fails with error Validation failed: Name has al...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Users & Roles
Version: 6.4.0
Hardware: All
OS: All
unspecified
high
Target Milestone: 6.6.0
Assignee: Kavita
QA Contact: Radovan Drazny
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-11-19 21:41 UTC by Rajan Gupta
Modified: 2020-09-20 13:13 UTC (History)
24 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-10-22 12:46:44 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Foreman Issue Tracker 27247 Normal Resolved Red Hat Satellite 6.4 upgrade fails with error Validation failed: Name has already been taken at db:migrate stage 2020-11-25 02:35:28 UTC
Red Hat Knowledge Base (Solution) 3998941 Upgrade None Red Hat Satellite upgrade to v.6.4 fails with Validation failed: Name has already been taken at db:migrate stage 2019-03-20 15:12:35 UTC
Red Hat Product Errata RHSA-2019:3172 None None None 2019-10-22 12:47:07 UTC

Description Rajan Gupta 2018-11-19 21:41:05 UTC
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.

Comment 2 Marek Hulan 2018-11-30 16:46:57 UTC
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.

Comment 12 Mike McCune 2019-05-14 19:32:47 UTC
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

Comment 13 Jameson 2019-05-16 14:20:47 UTC
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.

Comment 14 Jameson 2019-05-16 15:03:36 UTC
That did the trick for me.

Comment 16 Brendan Shephard 2019-06-08 06:40:02 UTC
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.

Comment 17 Brendan Shephard 2019-06-08 06:48:31 UTC
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.

Comment 20 Marek Hulan 2019-07-08 13:12:52 UTC
Created redmine issue https://projects.theforeman.org/issues/27247 from this bug

Comment 29 errata-xmlrpc 2019-10-22 12:46:44 UTC
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


Note You need to log in before you can comment on or make changes to this bug.