Bug 1954021
| Summary: | Red Hat Satellite 6.8 minor upgrade fails with error Validation failed: Name has already been taken at db:seed stage | ||
|---|---|---|---|
| Product: | Red Hat Satellite | Reporter: | Satyajit Das <sadas> |
| Component: | Reporting | Assignee: | Tomer Brisker <tbrisker> |
| Status: | CLOSED ERRATA | QA Contact: | Lukáš Hellebrandt <lhellebr> |
| Severity: | high | Docs Contact: | |
| Priority: | high | ||
| Version: | 6.8.0 | CC: | ahumbe, dhjoshi, dmatoule, egolov, kupadhya, mhulan, msunil, oprazak, pdwyer, saydas, tbrisker |
| Target Milestone: | 6.10.0 | Keywords: | PrioBumpGSS, Triaged, Upgrades |
| Target Release: | Unused | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | foreman-2.5.0 | Doc Type: | If docs needed, set a value |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2021-11-16 14:10:44 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
Looks like there is no unique constraint in the DB for template names, meaning that race condition could could duplicate templates to be created, leading to this issue on the next template seeding that attempts to save one of the duplicated templates. The same is true for other template kinds as well, not just report templates. Created redmine issue https://projects.theforeman.org/issues/32657 from this bug Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/32657 has been resolved. Verified with Sat 6.10.0 snap 4.0. # find / -name 20210525144427_enforce_unique_templates.rb /usr/share/foreman/migrate/20210525144427_enforce_unique_templates.rb # satellite-maintain upgrade run --target-version 6.10.z [...] # su - postgres -c "echo \"SELECT a.id, a.name, a.locked, a.type, a.created_at 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" id | name | locked | type | created_at -----+-------------------+--------+----------------------+---------------------------- 50 | Jumpstart default | t | ProvisioningTemplate | 2021-06-10 13:32:15.625061 117 | Jumpstart default | t | Ptable | 2021-06-10 13:32:17.464938 52 | Kickstart default | t | ProvisioningTemplate | 2021-06-10 13:32:15.704209 121 | Kickstart default | t | Ptable | 2021-06-10 13:32:17.561998 54 | Preseed default | t | ProvisioningTemplate | 2021-06-10 13:32:15.757862 125 | Preseed default | t | Ptable | 2021-06-10 13:32:17.656894 (6 rows) There are some templates with duplicate name but different type, I suppose it's expected (Tomer, can you confirm?). This BZ has component Reporting and there are no duplicate report templates => Verified. That's expected, the unique constraint is for [name, type] pairs. 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 (Moderate: Satellite 6.10 Release), 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-2021:4702 |
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 # 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:- # 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:- # 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. # 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" # 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:- # 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" # 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.