Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAP-39365 facts are unintentionally deleted when the inventory is modified during a job execution #15910

Open
wants to merge 14 commits into
base: devel
Choose a base branch
from

Conversation

djyasin
Copy link
Member

@djyasin djyasin commented Mar 28, 2025

SUMMARY

This change fixes facts are unintentionally deleted when the inventory is modified during a job execution

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • API
AWX VERSION
awx: 24.6.2
ADDITIONAL INFORMATION

Copy link

codecov bot commented Mar 28, 2025

Codecov Report

Attention: Patch coverage is 19.09091% with 89 lines in your changes missing coverage. Please review.

Project coverage is 52.88%. Comparing base (99be91e) to head (5f1d3c2).

✅ All tests successful. No failed tests found.

❌ Your project check has failed because the head coverage (52.88%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (99be91e) and HEAD (5f1d3c2). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (99be91e) HEAD (5f1d3c2)
CI-GHA 8 7
pytest 5 4
OS-Linux 8 7
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@djyasin djyasin marked this pull request as ready for review March 31, 2025 13:11
@@ -130,6 +131,9 @@ def finish_fact_cache(hosts, destination, facts_write_time, log_data, job_id=Non
log_data['unmodified_ct'] += 1
else:
# if the file goes missing, ansible removed it (likely via clear_facts)
# if the file goes missing, but the host hasnot started facts, then we should not clear the facts
if hosts_cached and host.name not in hosts_cached:
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outer iteration loop no longer makes any sense, that being for host in hosts:. On the surface-level you might as well change that to for host in hosts_cached: (and any associated changes), and get rid of the continue added here.

This requires changing the method signature (this is a structural change and that should not be surprising). As passing in job.get_hosts_for_fact_cache() for hosts carries a non-trivial cost and it is no longer needed considering what you're doing.

Given that you don't need to pass it into finish_fact_cache, I'm also unclear if it should be passed into start_fact_cache. A semi-isolated way to do that might be to pass the full Inventory object from the outset.

I talked a good deal with @chrismeyersfsu about further consequences and I'm not sure if the refactor should even stop there. The contract between the start/finish methods is mainly the artifacts directory, and passing around the list of cached hosts in memory (given this particular kind of toxic code path) may be less maintainable than passing it around on disk. I would seriously consider saving the data structure in a file next to the fact cache folder (both being inside of artifacts). If you did that, I also expect it would lead into removing the facts_write_time argument.

Copy link

last_filepath_written = None
for host in hosts:
for host in hosts_cached:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The start_fact_cache still needs to get the host list from the database, which is job.get_hosts_for_fact_cache(), which is still passed in as hosts to this method still. It's only the finishing method that should defer to the cached hosts from the starting method... somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants