Fix job history for constructed inventory hosts#577
Open
fernandorocagonzalez wants to merge 1 commit into
Open
Fix job history for constructed inventory hosts#577fernandorocagonzalez wants to merge 1 commit into
fernandorocagonzalez wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
hostFK (which points to the source inventory host) instead ofconstructed_host(which points to the constructed inventory host). The serializer already handled this correctly for therecent_jobsfield, 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:
Test plan