Description of problem: When is deleted hostgroup with associated OpenScap policies, policies are not cleaned properly which end with failing API and hammer calls Version-Release number of selected component (if applicable): How reproducible: Always. Same for 6.4, most likely even older Satellite. Steps to Reproduce: 1. Create hostgroup x,y,z 2. Create scap content a,b,c 3. Create scap policy d,e,f 4. Edit policy d,e,f and attach hostgroups x,y,z 5. Delete hostgroups x,y,z 6. hammer policy info --name d Actual results: Couldn't find all Hostgroups with 'id': (1, 2, 3) (found 0 results, but was looking for 3). Expected results: Id: 1 Name: d Created at: 2019-01-01 00:00:00 UTC Period: weekly Weekday: monday Day of month: Cron line: SCAP content Id: 1 SCAP Content profile Id: 1 Tailoring file Id: Tailoring file profile Id: Locations: Default Location Organizations: Default Organization Hostgroups: Additional info: In Database records are staying. select * from foreman_openscap_assets; id | created_at | updated_at | assetable_type | assetable_id ----+----------------------------+----------------------------+----------------+-------------- 1 | 2019-07-09 07:51:27.390499 | 2019-07-09 07:51:27.390499 | Hostgroup | 1 2 | 2019-07-09 07:51:27.470928 | 2019-07-09 07:51:27.470928 | Hostgroup | 2 3 | 2019-07-09 07:51:27.474601 | 2019-07-09 07:51:27.474601 | Hostgroup | 3 4 | 2019-07-09 07:51:38.68147 | 2019-07-09 07:51:38.68147 | Hostgroup | 1 5 | 2019-07-09 07:51:38.698747 | 2019-07-09 07:51:38.698747 | Hostgroup | 2 6 | 2019-07-09 07:51:38.702891 | 2019-07-09 07:51:38.702891 | Hostgroup | 3 select * from foreman_openscap_asset_policies; asset_id | policy_id ----------+----------- 1 | 1 2 | 1 3 | 1 4 | 2 5 | 2 6 | 2 7 | 3 8 | 3 9 | 3 Those records should be properly cleaned during hostgroup deletion.
Created redmine issue https://projects.theforeman.org/issues/27259 from this bug
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.
Thank you for your interest in Red Hat Satellite. We have evaluated this request, and while we recognize that it is a valid request, we do not expect this to be implemented in the product in the foreseeable future. This is due to other priorities for the product, and not a reflection on the request itself. We are therefore closing this out as WONTFIX. If you have any concerns about this feel free to contact your Red Hat Account Team. Thank you.
Reopening it as I have a reproducer. Basic idea: assign a Hostgroup to more Policies and then delete the HG. Second (and third etc., I expect) associated Policy will have invalid reference to the deleted HG. Particular steps: 0) Create two policies (I use names 'SCAP-policy-test' with id=1 and 'SCAP-policy-test2' with id=2 below) 1) Have reproducer script reproducer_for_HG_Policy.sh : HGNAME="HostGroup_$((RANDOM%100))" hmr="echo " $hmr policy update --name 'SCAP-policy-test' $hmr policy update --name 'SCAP-policy-test2' $hmr hostgroup create --name $HGNAME $hmr policy update --hostgroups $HGNAME --id 1 $hmr policy update --hostgroups $HGNAME --id 2 $hmr hostgroup delete --name $HGNAME $hmr policy update --name 'SCAP-policy-test' $hmr policy update --name 'SCAP-policy-test2' $hmr policy update --id 1 $hmr policy update --id 2 $hmr hostgroup create --name ${HGNAME}_2 $hmr policy update --hostgroups ${HGNAME}_2 --id 1 $hmr policy update --hostgroups ${HGNAME}_2 --id 2 $hmr hostgroup delete --name ${HGNAME}_2 $hmr policy update --id 1 $hmr policy update --id 2 2) Execute it: ./reproducer_for_HG_Policy.sh | hammer shell 3) See the results: hammer> policy update --name SCAP-policy-test Policy updated hammer> policy update --name SCAP-policy-test2 Policy updated hammer> hostgroup create --name HostGroup_88 Hostgroup created. hammer> policy update --hostgroups HostGroup_88 --id 1 Policy updated hammer> policy update --hostgroups HostGroup_88 --id 2 Policy updated hammer> hostgroup delete --name HostGroup_88 Hostgroup deleted. hammer> policy update --name SCAP-policy-test Policy updated hammer> policy update --name SCAP-policy-test2 Could not update the policy: Couldn't find Hostgroup with 'id'=26 hammer> policy update --id 1 Policy updated hammer> policy update --id 2 Policy updated hammer> hostgroup create --name HostGroup_88_2 Hostgroup created. hammer> policy update --hostgroups HostGroup_88_2 --id 1 Policy updated hammer> policy update --hostgroups HostGroup_88_2 --id 2 Policy updated hammer> hostgroup delete --name HostGroup_88_2 Hostgroup deleted. hammer> policy update --id 1 Policy updated hammer> policy update --id 2 Policy updated hammer> Surprisingly, "policy update --id .." _does_ work well, byt "policy update --name .." does _not_ work . Don't ask me why :) I have no clue. But at least "policy update --id .." is a workaround (that keeps orphaned records in DB, such that e.g. "policy list" does not work).
Please note that the key technical problem is in orphaned records in foreman_openscap_assets table. BUT *any* HG deletion (even associated to one Policy) leaves an orphaned record in foreman_openscap_asset_policies table. These foreman_openscap_asset_policies orphans are not an issue now, as far as I tried various steps. But still it isn't nice to leave orphaned records either where, due to several reasons, and we should ideally fix this as well.
Reopening, we might take a stab at this as part of refreshing openscap.