Skip to content

Commit

Permalink
[stable-2.18] facts: Skip path if the distribution path is directory (#…
Browse files Browse the repository at this point in the history
…84036)

Skip path if the distribution path is directory instead of file.
Handle exception raised while handling distribution path.

Fixes: #84006

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit 34f8f55)
  • Loading branch information
Akasurde authored Oct 14, 2024
1 parent 6e4732f commit a3656b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/os_family.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- facts - skip if distribution file path is directory, instead of raising error (https://github.com/ansible/ansible/issues/84006).
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/facts/system/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_uname(module, flags=('-v')):

def _file_exists(path, allow_empty=False):
# not finding the file, exit early
if not os.path.exists(path):
if not os.path.isfile(path):
return False

# if just the path needs to exists (ie, it can be empty) we are done
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright: Contributors to the Ansible project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import annotations

import tempfile


from ansible.module_utils.facts.system.distribution import DistributionFiles


def test_distribution_files(mock_module):
d = DistributionFiles(mock_module)
temp_dir = tempfile.TemporaryDirectory()
dist_file, dist_file_content = d._get_dist_file_content(temp_dir.name)
assert not dist_file
assert dist_file_content is None

0 comments on commit a3656b2

Please sign in to comment.