Repository navigation
Use shared tmpdir for inventory report storage - #1262
Merged
nofaralfasi merged 3 commits intoSep 28, 2026
Merged
Conversation
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="lib/foreman_inventory_upload.rb" line_range="10" />
<code_context>
+ # directory does not exist, so fall back to Rails.root/tmp.
@base_folder ||= File.join(
- Dir.glob('/var/lib/foreman').first || File.dirname(Dir.getwd),
+ Dir.exist?(SHARED_TMPDIR) ? SHARED_TMPDIR : Rails.root.join('tmp').to_s,
'red_hat_inventory/'
)
</code_context>
<issue_to_address>
**issue (bug_risk):** When `/var/run/foreman` exists but is not writable by the Foreman process, `base_folder` selects it and `generated_reports_folder` subsequently raises `Errno::EACCES` from `FileUtils.mkdir_p` instead of falling back to `Rails.root/tmp`.
**Triggers:** When the shared directory is present but owned by another user or has restrictive permissions, such as in a non-container development or misconfigured deployment.
**Suggested fix:** Select the shared directory only when it exists and is writable, or rescue the directory-creation failure and use the Rails temporary directory.
</issue_to_address>
### Comment 2
<location path="README.md" line_range="32-37" />
<code_context>
# generate report for specific organization (don't upload)
export organization_id=1
- export target=/var/lib/foreman/red_hat_inventory/generated_reports/
+ export target=/var/run/foreman/red_hat_inventory/generated_reports/
/usr/sbin/foreman-rake rh_cloud_inventory:report:generate
</code_context>
<issue_to_address>
**issue:** These instructions set the `target` environment variable explicitly, which bypasses `ForemanInventoryUpload.base_folder` and therefore bypasses its development fallback. In a development environment where the documented target does not exist or is not writable, `report:generate` switches to an unrelated `Dir.mktmpdir`, while the subsequent documented `report:upload` still reads from the unwritable target and raises when moving the report.
**Triggers:** When a developer follows the documented generate/upload commands without creating and granting access to `/var/run/foreman/red_hat_inventory/generated_reports/`.
**Suggested fix:** Use the plugin's resolved default folder in development, or instruct developers to create the target directory and ensure it is writable before running both commands.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and the report location changes to a shared runtime directory, so a wrong path or permission setup could make generated reports unavailable to the upload process or cause them to disappear on restart. Reverting restores the old behavior, and any misplaced reports are bounded artifacts that can be removed or regenerated.
Blocking findings: lib/foreman_inventory_upload.rb:10, README.md:37
Change base_folder from /var/lib/foreman/red_hat_inventory/ to /var/run/foreman/red_hat_inventory/. In containerized deployments (foremanctl), /var/run/foreman is already shared between Foreman and Dynflow via the foreman-data-run volume. Writing inventory reports there lets Dynflow's generated archives be visible to Foreman's send_file without mounting an additional volume. In development, /var/run/foreman does not exist, so the path falls back to Rails.root/tmp/red_hat_inventory/ (gitignored). Ref: theforeman/foremanctl#825
nofaralfasi
force-pushed
the
use-rails-tmp-for-inventory
branch
2 times, most recently
from
September 24, 2026 14:58
2093e81 to
6b52ec2
Compare
Use File.writable? instead of Dir.exist? so the fallback to Rails.root/tmp also kicks in when /var/run/foreman exists but is not writable by the current process. Freeze the constant to satisfy Style/MutableConstant.
nofaralfasi
force-pushed
the
use-rails-tmp-for-inventory
branch
from
September 24, 2026 15:03
6b52ec2 to
dd1ea37
Compare
ehelms
reviewed
Sep 24, 2026
ehelms
self-requested a review
September 24, 2026 15:12
nofaralfasi
force-pushed
the
use-rails-tmp-for-inventory
branch
from
September 24, 2026 15:32
575d192 to
390fb34
Compare
ehelms
reviewed
Sep 24, 2026
Rails.root/tmp is symlinked to /var/run/foreman inside the container, so there is no need to detect the shared volume path at runtime. Drop the SHARED_TMPDIR constant and File.writable? check.
nofaralfasi
force-pushed
the
use-rails-tmp-for-inventory
branch
from
September 24, 2026 15:39
390fb34 to
16ba476
Compare
ehelms
approved these changes
Sep 24, 2026
evgeni
approved these changes
Sep 25, 2026
chris1984
approved these changes
Sep 25, 2026
3 of 9 tasks
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.
Change
base_folderfrom/var/lib/foreman/red_hat_inventory/to/var/run/foreman/red_hat_inventory/.In containerized deployments,
/var/run/foremanis already shared between Foreman and Dynflow via theforeman-data-runvolume. Writing inventory reports there lets Dynflow's generated archives be visible to Foreman'ssend_filewithout mounting an additional volume.In development,
/var/run/foremandoes not exist, so the path falls back toRails.root/tmp/red_hat_inventory/(gitignored).Ref: theforeman/foremanctl#825