Project

General

Profile

Bug #32657

Upgrade fails with error Validation failed: Name has already been taken at db:seed stage

Added by Tomer Brisker 4 months ago. Updated 4 months ago.

Status:
Closed
Priority:
High
Assignee:
Category:
Templates
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1954021

Description of problem:

Red Hat Satellite 6.8 minor upgrade fails with error Validation failed: Name has already been taken at db:migrate state

Version-Release number of selected component (if applicable):

6.8.z

Steps to Reproduce:

=> Execute the command to do a minor update

  1. satellite-maintain upgrade run --target-version 6.8.z

Actual results:

=> The satellite installer fails with the below error:-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-04-27 00:15:44 [ERROR ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:seed]/Exec[foreman-rake-db:seed]: Failed to call refresh: '/usr/sbin/foreman-rake db:seed' returned 1 instead of one of [0]
2021-04-27 00:15:44 [ERROR ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:seed]/Exec[foreman-rake-db:seed]: '/usr/sbin/foreman-rake db:seed' returned 1 instead of one of [0]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected results:

The upgrade should be completed.

Additional info:

The issue seems to be with duplicate templete.

Workaround to fix the issue:- ============================
=> Execute the query to list the templates:-

  1. su - postgres -c "echo \"SELECT a.* FROM templates a JOIN (SELECT name, COUNT() FROM templates GROUP BY name HAVING count() > 1 ) b ON a.name = b.name ORDER BY a.name;\" | psql foreman"

=> Identify the duplicate template:-

  1. awk F\| '{print $1, $2, $8, $11, $6}' '/home/sadas/Downloads/foreman.txt' | grep "\S"
    id name locked type created_at
    ----
    ---------------------------------------------------------------------------------+
    297 Host - Last Checkin t ReportTemplate 2021-04-26 21:03:44.527975 ===> The issue seems to be with these duplicate templates(id 297 and 296).
    296 Host - Last Checkin t ReportTemplate 2021-04-26 21:03:44.508732
    59 Jumpstart default t Ptable 2017-08-08 07:47:49.520343
    21 Jumpstart default t ProvisioningTemplate 2017-08-08 07:47:48.798974
    61 Kickstart default t Ptable 2017-08-08 07:47:49.549152
    206 Kickstart default t ProvisioningTemplate 2020-01-29 09:00:56.526946
    30 Preseed default t ProvisioningTemplate 2017-08-08 07:47:48.945963
    62 Preseed default t Ptable 2017-08-08 07:47:49.563543
    ------------+--------------------+----------------------------+-------------------------+
    => Execute the command to unlock the template:- // Take a snapshot only then proceed with the next steps.
  1. su - postgres -c "echo \"update templates set locked = 'f' where id='297';\" | psql foreman"

=> Run the following and verify the output shows one of the entities of "Host - Last Checkin"

  1. su - postgres -c "echo \"select id, name, type from templates where id='297';\" | psql foreman"

If looks okay, then rename the duplicate using the below query:-

  1. su - postgres -c "echo \"update templates set name = 'Host - Last Checkin 2' where id='297';\" | psql foreman"

Following should now have named as "Host - Last Checkin 2"

  1. su - postgres -c "echo \"select id, name, type from templates where id='297';\" | psql foreman"

Then rerun the satellite-installer to complete the minor update.


Related issues

Related to Foreman - Bug #32086: db seed triggered by sidekiq resulting in duplicate provisioning-templatesClosed

Associated revisions

Revision 5c92f976 (diff)
Added by Tomer Brisker 4 months ago

Fixes #32657 - Prevent duplicate templates

In certain race conditions when two seeds are executed at the same time,
some templates may be seeded twice. Since there is a unique name
validation in AR on templates, this renders such templates uneditable,
and in case they need updating during seeding, it also prevents the seed
from succeeding. To avoid this, an index is introduced to enforce
uniqueness on the DB level as well. Since this is a rare condition that
can only occur during seeding, it is safe to remove any duplicate
templates created in such manner.

History

#1 Updated by Tomer Brisker 4 months ago

  • Category changed from Statistics to Templates
  • Subject changed from Red Hat Satellite 6.8 minor upgrade fails with error Validation failed: Name has already been taken at db:seed stage to Upgrade fails with error Validation failed: Name has already been taken at db:seed stage

Templates do not have a unique constraint on name in the DB, causing potential race condition that allows duplicates to be created. Any duplicates should be removed and an index added.

#2 Updated by The Foreman Bot 4 months ago

  • Assignee set to Tomer Brisker
  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/8552 added

#3 Updated by Tomer Brisker 4 months ago

  • Related to Bug #32086: db seed triggered by sidekiq resulting in duplicate provisioning-templates added

#4 Updated by The Foreman Bot 4 months ago

  • Fixed in Releases 3.0.0 added

#5 Updated by Tomer Brisker 4 months ago

  • Status changed from Ready For Testing to Closed

#6 Updated by Tomer Brisker 4 months ago

  • Fixed in Releases 2.5.0 added
  • Fixed in Releases deleted (3.0.0)

#7 Updated by Tomer Brisker 4 months ago

  • Fixed in Releases 2.4.1 added

Also available in: Atom PDF