Bug 1819823
| Summary: | removing a content host does not remove openscap policy assets references to it | ||
|---|---|---|---|
| Product: | Red Hat Satellite | Reporter: | Joniel Pasqualetto <jpasqual> |
| Component: | SCAP Plugin | Assignee: | Adam Ruzicka <aruzicka> |
| Status: | CLOSED MIGRATED | QA Contact: | Peter Ondrejka <pondrejk> |
| Severity: | medium | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | 6.6.0 | CC: | akapse, aruzicka, inecas, mhulan, oezr, ofedoren, zhunting |
| Target Milestone: | stream | Keywords: | MigratedToJIRA, Reopened, Triaged |
| Target Release: | Unused | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | rubygem-foreman_openscap-8.0.1 | Doc Type: | If docs needed, set a value |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2024-06-05 21:37:56 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: | |||
Created redmine issue https://projects.theforeman.org/issues/33023 from this bug Upstream bug assigned to oezr Upstream bug assigned to oezr Upstream bug assigned to oezr Upstream bug assigned to oezr Upon review of our valid but aging backlog the Satellite Team has concluded that this Bugzilla does not meet the criteria for a resolution in the near term, and are planning to close in a month. This message may be a repeat of a previous update and the bug is again being considered to be closed. If you have any concerns about this, please contact your Red Hat Account team. Thank you. Closing this as duplicate of https://bugzilla.redhat.com/show_bug.cgi?id=1753313, which was fixed in Satellite 6.7.0. If you think this is still valid, please feel free to re-open. *** This bug has been marked as a duplicate of bug 1753313 *** I'll revive this one. It is true that we're removing records from foreman_openscap_assets when hosts are deleted, but we still keep around records in foreman_openscap_asset_policies. This does not prevent the policy from being updated, but can lead to unnecessary db bloat. This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there. Due to differences in account names between systems, some fields were not replicated. Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information. To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "SAT-" followed by an integer. You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like: "Bugzilla Bug" = 1234567 In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information. |
Description of problem: When removing a host which is associated with an openscap policy, its references are not removed from the DB. This makes impossible to edit the policy to which the host was associated. Version-Release number of selected component (if applicable): satellite 6.6 How reproducible: Always Steps to Reproduce: 1. Configure a host to use openscap 2. Wait until foreman_scap_client uploads the first report for that host. At this point, registries on the tables foreman_openscap_assets and foreman_openscap_asset_policies will be created: DB before any reports: ~~~ foreman=# select name,id from hosts where name = 'lila-calliste.jpasqualetto.local'; name | id ----------------------------------+------ lila-calliste.jpasqualetto.local | 1173 (1 row) foreman=# select * from foreman_openscap_assets where assetable_id = '1173'; id | created_at | updated_at | assetable_type | assetable_id ----+------------+------------+----------------+-------------- (0 rows) ~~~ After the first report is uploaded: ~~~ foreman=# select * from foreman_openscap_assets where assetable_id = '1173'; id | created_at | updated_at | assetable_type | assetable_id ----+---------------------------+---------------------------+----------------+-------------- 15 | 2020-04-01 16:01:01.64441 | 2020-04-01 16:01:01.64441 | Host::Base | 1173 (1 row) foreman=# select * from foreman_openscap_asset_policies where asset_id = '15'; asset_id | policy_id ----------+----------- 15 | 1 (1 row) ~~~ 3. Delete the host: ~~~ # hammer host delete --id 1173 Host deleted. ~~~ Checking the DB: ~~~ foreman=# select name,id from hosts where name = 'lila-calliste.jpasqualetto.local' or id = '1173'; name | id ------+---- (0 rows) foreman=# select * from foreman_openscap_assets where assetable_id = '1173'; id | created_at | updated_at | assetable_type | assetable_id ----+---------------------------+---------------------------+----------------+-------------- 15 | 2020-04-01 16:01:01.64441 | 2020-04-01 16:01:01.64441 | Host::Base | 1173 (1 row) foreman=# select * from foreman_openscap_asset_policies where asset_id = '15'; asset_id | policy_id ----------+----------- 15 | 1 (1 row) ~~~ See that the host is gone, but it is still referenced in the tables foreman_openscap_assets and foreman_openscap_asset_policies. 4. Try editing the policy to which this host was assigned. You don't need to make any changes, just enter edit mode and try clicking the submit button. Error in the webUI: ~~~ Oops, we're sorry but something went wrong undefined method `policies' for nil:NilClass ~~~ Snippet of the backtrace + sql logs on production.log, when trying to load the host with id 1173 (which was just deleted): ~~~ 2020-04-01T12:06:50 [D|sql|c530f7a6] Host::Base Load (0.5ms) SELECT "hosts".* FROM "hosts" WHERE "hosts"."organization_id" = $1 AND "hosts"."location_id" = $2 AND "hosts"."id" = $3 LIMIT $4 [["organization_id", 1], ["location_id", 2], ["id", 1173], ["LIMIT", 1]] 2020-04-01T12:06:50 [D|sql|c530f7a6] (0.2ms) ROLLBACK 2020-04-01T12:06:50 [W|app|c530f7a6] Action failed 2020-04-01T12:06:50 [D|app|c530f7a6] Backtrace for 'Action failed' error (NoMethodError): undefined method `policies' for nil:NilClass /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_openscap-1.0.8/app/models/foreman_openscap/policy.rb:315:in `block in no_mixed_deployments' /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/delegation.rb:41:in `each' /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/delegation.rb:41:in `each' ~~~ Actual results: Host is still referenced in the policy and policy cannot be edited anymore. Expected results: Host would have all references removed from any components and nothing would be broken. Additional info: Easy to fix the DB inconsistency (as a workaround, one could schedule a script to run this on Satellite to keep the DB consistent): ~~~ foreman=# delete from foreman_openscap_assets where id in (select foa.id from foreman_openscap_assets as foa left join hosts as h on foa.assetable_id = h.id where h.id is NULL and assetable_type = 'Host::Base'); DELETE 1 foreman=# delete from foreman_openscap_asset_policies where asset_id in (select foap.asset_id from foreman_openscap_asset_policies as foap left join foreman_openscap_assets as foa on foap.asset_id = foa.id where foa.id is NULL); DELETE 1 ~~~ To simply generate a list of inconsistencies: ~~~ select foa.id as Assetable_ID, foa.assetable_type as Assetable_Type from foreman_openscap_assets as foa left join hosts as h on foa.assetable_id = h.id where h.id is NULL and assetable_type = 'Host::Base'; select foap.asset_id, foap.policy_id from foreman_openscap_asset_policies as foap left join foreman_openscap_assets as foa on foap.asset_id = foa.id where foa.id is NULL; ~~~