Skip to content

Fixes #39088 - Search generated_reports for report file paths#1165

Merged
chris1984 merged 1 commit intotheforeman:foreman_3_18from
zjhuntin:backport-1155-to-3.18
Mar 4, 2026
Merged

Fixes #39088 - Search generated_reports for report file paths#1165
chris1984 merged 1 commit intotheforeman:foreman_3_18from
zjhuntin:backport-1155-to-3.18

Conversation

@zjhuntin
Copy link
Contributor

@zjhuntin zjhuntin commented Mar 4, 2026

Summary

Backport of #1155 to foreman_3_18 branch.

Changes

  • Updates report_file_paths to search for reports in priority order: generated_reports → uploads → done
  • Adds generated_reports_file_path helper method
  • Fixes base_folder to use parent directory in dev environments

Original PR

#1155

Summary by Sourcery

Search inventory report files in all expected locations and correct the base directory used in development environments.

Bug Fixes:

  • Ensure report file lookup checks generated, uploads, and done folders in priority order so the latest report is found.
  • Fix base folder selection in development environments to use the parent of the current working directory instead of the working directory itself.

Enhancements:

  • Introduce a helper for building file paths in the generated_reports folder to simplify path handling.

…and dev setup (theforeman#1155)

* Improve report file paths and dev environment setup

Updates report_file_paths to search in priority order (done, uploads,
generated) ensuring downloads return the most recent report. Also fixes
base_folder to use parent directory in dev environments, keeping
generated files outside the Foreman repo directory.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Add documentation for report_file_paths search order

Explains the file lifecycle through generated → uploads → done
folders and why the search order prioritizes newest files first.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 4, 2026

Reviewer's Guide

Adjusts Foreman inventory report file discovery to search a new generated_reports directory with correct priority, introduces a helper for generated report paths, and fixes the base folder resolution for development vs production environments.

Class diagram for ForemanInventoryUpload changes

classDiagram
  class ForemanInventoryUpload {
    <<module>>
    +base_folder() String
    +done_folder() String
    +uploads_folder() String
    +generated_reports_folder() String
    +outputs_folder() String
    +facts_archive_name(organization_id) String
    +uploads_file_path(filename) String
    +done_file_path(filename) String
    +generated_reports_file_path(filename) String
    +report_file_paths(organization_id) Array~String~
  }

  ForemanInventoryUpload : base_folder uses Dir.glob
  ForemanInventoryUpload : base_folder uses File.dirname
  ForemanInventoryUpload : generated_reports_file_path builds path under generated_reports_folder
  ForemanInventoryUpload : report_file_paths searches generated_reports, uploads, done in order
Loading

Flow diagram for report_file_paths search order

flowchart TD
  A["Start report_file_paths"] --> B["Compute filename = facts_archive_name(organization_id)"]
  B --> C["Build path_generated = generated_reports_file_path(filename)"]
  C --> D["Build path_uploads = uploads_file_path(filename)"]
  D --> E["Build path_done = done_file_path(filename)"]
  E --> F["Return Dir[ path_generated, path_uploads, path_done ]"]
Loading

Flow diagram for base_folder resolution in prod vs dev

flowchart TD
  A["Start base_folder"] --> B["Search selinux_path = Dir.glob(/var/lib/foreman).first"]
  B --> C{"selinux_path found?"}
  C -- Yes --> D["base_root = selinux_path"]
  C -- No --> E["base_root = File.dirname(Dir.getwd)"]
  D --> F["base_folder = File.join(base_root, red_hat_inventory/)"]
  E --> F
  F --> G["Return base_folder"]
Loading

File-Level Changes

Change Details Files
Fix base directory resolution for inventory upload storage in dev vs production.
  • Corrects comment and path from a typo /ver/lib/foreman to /var/lib/foreman in documentation
  • Changes dev-environment fallback from using the current working directory to using its parent directory via File.dirname(Dir.getwd) when /var/lib/foreman does not exist
  • Keeps red_hat_inventory/ as the fixed subdirectory for all storage under the resolved base folder
lib/foreman_inventory_upload.rb
Extend report file path resolution to include generated_reports with explicit search priority.
  • Remove the old report_file_paths implementation that only checked uploads and done folders
  • Introduce generated_reports_folder usage and a new generated_reports_file_path helper that joins the generated_reports folder with a given filename
  • Update report_file_paths(organization_id) to build the facts archive filename and return all matching paths in priority order: generated_reports, uploads, then done, with inline comments explaining the move semantics and reasoning for the ordering
lib/foreman_inventory_upload.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@chris1984 chris1984 merged commit 85f73a5 into theforeman:foreman_3_18 Mar 4, 2026
6 of 7 checks passed
@zjhuntin zjhuntin deleted the backport-1155-to-3.18 branch March 4, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants