Skip to content

Fix job history for constructed inventory hosts#577

Open
fernandorocagonzalez wants to merge 1 commit into
ctrliq:mainfrom
fernandorocagonzalez:fix-constructed-host-summaries
Open

Fix job history for constructed inventory hosts#577
fernandorocagonzalez wants to merge 1 commit into
ctrliq:mainfrom
fernandorocagonzalez:fix-constructed-host-summaries

Conversation

@fernandorocagonzalez

Copy link
Copy Markdown
Contributor

Summary

When looking at a host or group inside a constructed inventory, the job history (job_host_summaries endpoint) was coming back empty. This happened because the API was querying the wrong foreign key on JobHostSummary: it used the host FK (which points to the source inventory host) instead of constructed_host (which points to the constructed inventory host). The serializer already handled this correctly for the recent_jobs field, but the full list endpoint did not.

On top of that, when an inventory source syncs with overwrite and a host temporarily disappears from the source, the host object gets deleted and recreated with a new PK. The old JobHostSummary records lose their host link (SET_NULL), so even after the host comes back, the job history is gone. This adds a relink step after each inventory sync that reconnects those orphaned records by matching on host_name, scoped to the same inventory so it wont accidentally link summaries from a different inventory that happens to have a host with the same name.

Changes:

  • HostJobHostSummariesList and GroupJobHostSummariesList now use constructed_host_summaries for constructed inventory hosts/groups
  • New Group.constructed_host_summaries property (Host already had one)
  • New _relink_orphaned_job_host_summaries method in inventory_import, called after each sync
  • 12 new tests covering the API fix, the relink logic, constructed inventories, and cross-inventory isolation

Test plan

  • Existing tests pass (48 inventory import + 8 host summary = 56 total, 0 regressions)
  • New test: constructed host job summaries returned via API
  • New test: regular (non-constructed) host summaries still work
  • New test: no false positives (summaries from source inventory dont leak to constructed)
  • New test: constructed group summaries returned via API
  • New test: orphaned summaries re-linked after host is deleted and recreated
  • New test: summaries not re-linked when host PK is preserved (no orphan)
  • New test: constructed inventory orphaned summaries re-linked via constructed_host FK
  • New test: re-link does NOT cross inventories (inventory A sync wont steal inventory B orphans)

…aries

The job_host_summaries API endpoint for hosts and groups in constructed
inventories was returning empty results because it queried the host FK
(which points to the source inventory host) instead of the
constructed_host FK. This matches the fix already present in the
serializer for recent_jobs.

Also adds a relink step after inventory sync that reconnects orphaned
JobHostSummary records (where the host FK became NULL after the host
was deleted by an overwrite sync) to the new host object by matching
on host_name, scoped to the same inventory to prevent cross-inventory
mis-linking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant