Bug 2051945 - InventoryFullSync wrongly updates host status of disconnected hosts
Summary: InventoryFullSync wrongly updates host status of disconnected hosts
Keywords:
Status: CLOSED WORKSFORME
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: RH Cloud - Inventory
Version: 6.10.3
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: Unspecified
Assignee: Shimon Shtein
QA Contact: Satellite QE Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-02-08 11:23 UTC by Pavel Moravec
Modified: 2023-07-11 16:09 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-07-11 16:09:48 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 6718711 0 None None None 2022-02-09 12:28:12 UTC

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.


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