Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 1402513 - Can not delete host if there are SCAP reports for that host
Can not delete host if there are SCAP reports for that host
Status: CLOSED ERRATA
Product: Red Hat Satellite 6
Classification: Red Hat
Component: SCAP Plugin (Show other bugs)
6.2.4
All Linux
medium Severity medium (vote)
: GA
: Unused
Assigned To: Marek Hulan
Ales Dujicek
: Reopened, Triaged
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-12-07 12:28 EST by Ian Tewksbury
Modified: 2018-10-16 14:53 EDT (History)
19 users (show)

See Also:
Fixed In Version: foreman-1.18.0.6-1
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2018-10-16 14:53:07 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 2953101 None None None 2018-07-24 11:29 EDT
Foreman Issue Tracker 24269 None None None 2018-07-17 07:09 EDT

  None (edit)
Description Ian Tewksbury 2016-12-07 12:28:29 EST
Description of problem:

If a host has any SCAP reports and you try to delete said host from the Hosts -> All Hosts view or by click on the host and select the delete option then you get the following error message:

error: PG::Error: ERROR: update or delete on table "hosts" violates foreign key constraint "reports_host_id_fk" on table "reports" DETAIL: Key (id)=(43) is still referenced from table "reports". : DELETE FROM "hosts" WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."id" = $1

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

6.2.4

How reproducible:

Always if a host has any SCAP reports.


Steps to Reproduce:
1. attempt to delete a host that has any SCAP reports

Actual results:

Host deletion fails with cryptic message

Expected results:

The host and the SCAP reports get deleted without error. OR, an option pops up to also delete the SCAP reports or preserve them even after host has been deleted.
Comment 5 Ian Tewksbury 2017-01-03 09:17:13 EST
@Marek and @Shlomi,

My apologies. I misread Shlomi's note and thought they had tried it on a newer version of Satellite then I encountered the issue on.


I will run through the procedure again and attach a production log.
Comment 6 Ian Tewksbury 2017-01-03 11:11:56 EST
@Marek and @Shlomi,

When I wen't back to reproduce again I could not. It worked as expected.

You can close this out. Apologies for the ghost.
Comment 7 Marek Hulan 2017-01-03 11:26:54 EST
Thanks for letting us know. I'm closing as NOTABUG, please feel free to reopen if you find the reproducer.
Comment 8 Justin Matlock 2017-01-13 15:30:06 EST
Experiencing this same issue on Satellite 6.2.6, when trying to delete hosts that have any SCAP reports. We have to go in and delete all reports for the host before it will allow us to delete the host itself. This is a problem since we have permissions configured to prevent users from deleting SCAP reports (we don't want them mucking about security reports for active systems). This error pops up for both admin users and regular users. 

It seems that the host deletion process should remove the SCAP reports before trying to delete the host?

[root@uatdocker01 ~]# subscription-manager unregister

ERROR:  update or delete on table "hosts" violates foreign key constraint "reports_host_id_fk" on table "reports"
DETAIL:  Key (id)=(119) is still referenced from table "reports".
Comment 9 Justin Matlock 2017-01-13 15:38:08 EST
Follow up: I believe discovered the cause. Upgrading a capsule server (using "satellite-installer --scenario capsule --upgrade") that receives SCAP reports seems to be the root cause -- any reports created before the upgrade cause the foreign key violation error. If I go into the postgresql database and issue SQL to delete all reports created before the capsule upgrade, the rest of the reports get deleted automatically when the host is unregistered.
Comment 10 Marek Hulan 2017-01-25 03:03:38 EST
Justin, please see the linked BZ #1334035 (comment 2). The workaround or fix from there might help.
Comment 11 Marek Hulan 2017-01-25 03:09:05 EST
Please let us know about you findings. If it does not help, I'll reopen the BZ and try your reproducing steps.
Comment 18 Ian Tewksbury 2017-09-19 11:09:35 EDT
@Marek,

1. get scap reports for a host
2. attempt to delete the host
3. it will error trying to delete the host
4. delete all the scap reports for the VM
5. attempt to delete the host
6. it works then
Comment 21 mharris 2017-10-03 15:24:24 EDT
Since I'm awful at anonymizing:

I ran into this today.

The error I was getting:

(Truncated, and "anonymized", from an ansible script)

[NOTIFICATION], [2017-10-03 18:42:09], [Writing FQDN katello-fact] 
[[94mRUNNING[0m], [2017-10-03 18:42:10], [Disassociating host id 1205 for host YYYYY.YYYYY.com] 
[[94mRUNNING[0m], [2017-10-03 18:42:11], [Deleting host id 1205 for host YYYYY.YYYYY.com] 
An error occured: HTTP Error 500: Internal Server Error
url: https://XXXXX.XXXXX.com:443/api/v2/hosts//1205
code: 500
error: {
  "error": {
    "message": "ERROR:  update or delete on table \"hosts\" violates foreign key constraint \"reports_host_id_fk\" on table \"reports\"\nDETAIL:  Key (id)=(1205) is still referenced from table \"reports\".\n"
  }
}
Comment 32 Marek Hulan 2018-07-17 07:09:08 EDT
Created redmine issue https://projects.theforeman.org/issues/24269 from this bug
Comment 33 Marek Hulan 2018-07-17 07:14:06 EDT
After hours of debugging I finally figured out the reproducing steps. This is present even in recent versions but it only happens when host has 0 config reports and at least 1 arf_report. Due to a bug in a code, if we see at least 1 config report, all reports (including arf_reports) are removed prior host deletion. If there's 0 config reports, reports table remains untouched, hence arf_reports remain in the table and foreign key causes the 500.
Comment 35 pm-sat@redhat.com 2018-07-17 08:11:48 EDT
Upstream bug assigned to mhulan@redhat.com
Comment 36 pm-sat@redhat.com 2018-07-17 08:11:54 EDT
Upstream bug assigned to mhulan@redhat.com
Comment 37 pm-sat@redhat.com 2018-07-17 18:12:15 EDT
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/24269 has been resolved.
Comment 38 Marek Hulan 2018-07-18 02:32:41 EDT
The fix has landed in Foreman 1.20 (current develop branch)
Comment 42 Bryan Kearney 2018-10-16 14:53:07 EDT
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-2018:2927

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