Project

General

Profile

Bug #32498

Katello 3.16 to 3.17 upgrade fails at the db:migrate stage with error "ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint"

Added by Ian Ballou about 1 year ago. Updated 11 months ago.

Status:
Closed
Priority:
High
Assignee:
Category:
Repositories
Target version:
Difficulty:
Triaged:
Yes
Bugzilla link:
Fixed in Releases:
Found in Releases:
Red Hat JIRA:

Description

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

Description of problem:

While attempting to upgrade Katello, It fails at the db:migrate stage with either of these two errors.

2021-04-28 11:23:10 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: PG::ForeignKeyViolation: ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint "fk_rails_9cae1dc9a3"
2021-04-28 11:23:10 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: DETAIL: Key (content_view_id)=(4) is not present in table "katello_content_views".

or,

2021-04-26 15:06:49 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: PG::ForeignKeyViolation: ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint "fk_rails_159087f51c"
2021-04-26 15:06:49 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: DETAIL: Key (lifecycle_environment_id)=(9) is not present in table "katello_environments".

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

Katello 3.16 [ 3.16 to 3.17 upgrade ]

How reproducible:

Under specific circumstances i.e. the missing foreign key constraints might be the cause and somehow it bypassed the "dependent:" constraint in rails

Steps to reproduce:

1. On Katello 3.16 with CV\LCE\Hostgroups preconfigured

2. Associate a hostgroup with one CV and LCE

3. Find a way to delete that LCE or CV so that they get removed from their respective tables but the hostgroups table in DB still holds the association.

Example:
For CV --> Katello::ContentView.where(id: <cv id>).delete_all
or,
For LCE --> Katello::KTEnvironment.where(id: <lce id>).delete_all

4. Perform the upgrade to 6.9

Actual Results:

db:migrate stage will fail at following

2021-04-28 11:23:10 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: PG::ForeignKeyViolation: ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint "fk_rails_9cae1dc9a3"
2021-04-28 11:23:10 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: DETAIL: Key (content_view_id)=(4) is not present in table "katello_content_views".

or,

2021-04-26 15:06:49 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: PG::ForeignKeyViolation: ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint "fk_rails_159087f51c"
2021-04-26 15:06:49 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: DETAIL: Key (lifecycle_environment_id)=(9) is not present in table "katello_environments".

Expected results:

Before the db:migrate happens, these inconsistencies\stale associations should be removed from hostgroups table and then the db:migrate should be executed.

Additional Information:

Manual Solution present in https://access.redhat.com/solutions/6003311

Associated revisions

Revision 1fbe1f1d (diff)
Added by Ian Ballou about 1 year ago

Fixes #32498 - 3.17 upgrade fails if there is stale hostgroup data (#9333)

History

#1 Updated by The Foreman Bot about 1 year ago

  • Assignee set to Ian Ballou
  • Status changed from New to Ready For Testing
  • Pull request https://github.com/Katello/katello/pull/9333 added

#2 Updated by Ian Ballou about 1 year ago

  • Triaged changed from No to Yes
  • Target version set to Katello 4.2.0
  • Subject changed from Katello 3.16 to 3.17 upgrade fails at the db:migrate stage with error "ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint" to Katello 3.16 to 3.17 upgrade fails at the db:migrate stage with error "ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint"

For the future Katello 4.2 release manager, you can leave this issue out of the release notes. It isn't relevant to those on Katello versions newer than 3.16, but triaging to 3.17 didn't make sense at the time.

#3 Updated by The Foreman Bot about 1 year ago

  • Fixed in Releases Katello 4.2.0 added

#4 Updated by Anonymous about 1 year ago

  • Status changed from Ready For Testing to Closed

#5 Updated by Jeremy Lenz 11 months ago

  • Target version changed from Katello 4.2.0 to Katello 4.1.0

Also available in: Atom PDF