Description of problem: While attempting to upgrade the Red Hat Satellite server 6.8 to 6.9, 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): Satellite 6.9 [ 6.8 to 6.9 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 Satellite 6.8 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
Created redmine issue https://projects.theforeman.org/issues/32498 from this bug
Upstream bug assigned to iballou
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/32498 has been resolved.
Verified on 6.9.3 snap 1.0. Steps: 1. On Satellite 6.8.6, create a lifecycle environment, content view, and host group. 2. Update the host group in the database to point to a non-existent content view. *** # su - postgres -c 'psql foreman' foreman=# select id, name, content_view_id, lifecycle_environment_id from hostgroups; id | name | content_view_id | lifecycle_environment_id ----+-----------------+-----------------+-------------------------- 1 | test-host-group | 2 | 2 (1 row) foreman=# select id, name from katello_content_views; id | name ----+--------------------------- 1 | Default Organization View 2 | test-cv (2 rows) foreman=# update hostgroups set content_view_id=3; foreman=# select id, name, content_view_id, lifecycle_environment_id from hostgroups; id | name | content_view_id | lifecycle_environment_id ----+-----------------+-----------------+-------------------------- 1 | test-host-group | 3 | 2 (1 row) 3. Upgrade to 6.9.3: # satellite-maintain upgrade list-versions # satellite-maintain service stop # satellite-maintain upgrade check --target-version 6.9 --whitelist="repositories-validate,repositories-setup" # satellite-maintain upgrade run --target-version 6.9 --whitelist="foreman-fact-names,repositories-validate,repositories-setup" Verify successful upgrade, and warning logged in /var/log/foreman/production.log: 2021-06-07T16:56:53 [W|app|] Unable to save content facet hostgroup for #<Hostgroup id: 1, name: "test-host-group", [...]> due to bad hostgroup data.
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 (Satellite 6.9.3 Async Bug Fix Update), 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/RHBA-2021:2636