Bug 2051945

Summary: InventoryFullSync wrongly updates host status of disconnected hosts
Product: Red Hat Satellite Reporter: Pavel Moravec <pmoravec>
Component: RH Cloud - InventoryAssignee: Shimon Shtein <sshtein>
Status: CLOSED WORKSFORME QA Contact: Satellite QE Team <sat-qe-bz-list>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.10.3CC: ankulkar, aruzicka, jsenkyri, momran, qfz769, ramesh.daryani, sshtein
Target Milestone: UnspecifiedKeywords: EasyFix, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-07-11 16:09:48 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:

Description Pavel Moravec 2022-02-08 11:23:28 UTC
Description of problem:
user story: switching off some Hosts, an attempt to delete them after some days fails with:

PG::ForeignKeyViolation: ERROR:  update or delete on table "hosts" violates fore
ign key constraint "host_status_hosts_host_id_fk" on table "host_status"
DETAIL:  Key (id)=(75170) is still referenced from table "host_status".

The root cause is the following:
1) InventoryFullSync does update HostStatus of disconnected hosts to InventoryStatus::DISCONNECT (https://github.com/theforeman/foreman_rh_cloud/blob/master/lib/inventory_sync/async/inventory_full_sync.rb#L57)
2) but this update does not set "type" of the HostStatus (cf. https://github.com/theforeman/foreman_rh_cloud/blob/master/lib/inventory_sync/async/host_result.rb#L24)
3) that means, a host_status record in psql looks like:
# su - postgres -c "psql foreman -c \"SELECT * FROM host_status WHERE type IS null\""
   id   | type | status | host_id |        reported_at
--------+------+--------+---------+----------------------------
 719546 |      |      0 |  111613 | 2022-02-02 00:01:15.146124
..
4) the empty type then prevents deletion of such host (here of host_id 111613).


Version-Release number of selected component (if applicable):
Sat 6.10 (any version applicable, though)


How reproducible:
100%


Steps to Reproduce:
(havent reproduced by myself, just guessing the reproducer)
1. register a Host to RH cloud
2. switch off the host for few days
3. Ensure InventoryFullSync was run meantime
4. Try to delete the Host
5. Check in postgres host_status.type where host_status.host_id = <ID>


Actual results:
4. is expected to raise the PG::ForeignKeyViolation error
5. the Host's status has empty type.


Expected results:
5. the Host's status does not have empty type
4. The Host can be deleted.


Additional info:

Comment 1 Ramesh Daryani 2022-03-12 13:27:01 UTC
Please share if there is plan to include a fix for this bug in the next z stream of Satellite 6.10.