diff --git a/0002-Handle-files-that-don-t-exist-in-FileCheck.patch b/0002-Handle-files-that-don-t-exist-in-FileCheck.patch new file mode 100644 index 0000000..e9e04e1 --- /dev/null +++ b/0002-Handle-files-that-don-t-exist-in-FileCheck.patch @@ -0,0 +1,63 @@ +From 7db48931c9b3045406e465abb4d2a21beaadfcc4 Mon Sep 17 00:00:00 2001 +From: Rob Crittenden +Date: Mon, 14 Jun 2021 08:44:39 -0400 +Subject: [PATCH] Handle files that don't exist in FileCheck + +A raw os.stat() was called which could raise an exception if the file +doesn't exist. Instead call os.path.exists() and if the result is False +then raise a SUCCESS with a message that the file doesn't exist. + +https://github.com/freeipa/freeipa-healthcheck/issues/213 + +Signed-off-by: Rob Crittenden +--- + src/ipahealthcheck/core/files.py | 7 +++++++ + tests/test_core_files.py | 17 +++++++++++++++++ + 2 files changed, 24 insertions(+) + +diff --git a/src/ipahealthcheck/core/files.py b/src/ipahealthcheck/core/files.py +index a63c06b..0a7641e 100644 +--- a/src/ipahealthcheck/core/files.py ++++ b/src/ipahealthcheck/core/files.py +@@ -33,6 +33,13 @@ class FileCheck: + owner = tuple((owner,)) + if not isinstance(group, tuple): + group = tuple((group,)) ++ if not os.path.exists(path): ++ for type in ('mode', 'owner', 'group'): ++ key = '%s_%s' % (path.replace('/', '_'), type) ++ yield Result(self, constants.SUCCESS, key=key, ++ type=type, path=path, ++ msg='File does not exist') ++ continue + stat = os.stat(path) + fmode = str(oct(stat.st_mode)[-4:]) + key = '%s_mode' % path.replace('/', '_') +diff --git a/tests/test_core_files.py b/tests/test_core_files.py +index 3b71469..10824ab 100644 +--- a/tests/test_core_files.py ++++ b/tests/test_core_files.py +@@ -144,3 +144,20 @@ def test_files_mode(mock_stat): + my_results = get_results(results, 'mode') + assert my_results.results[0].result == constants.WARNING + assert my_results.results[1].result == constants.WARNING ++ ++ ++@patch('os.path.exists') ++def test_files_not_found(mock_exists): ++ mock_exists.return_value = False ++ ++ f = FileCheck() ++ f.files = files ++ ++ results = capture_results(f) ++ ++ for type in ('mode', 'group', 'owner'): ++ my_results = get_results(results, type) ++ assert len(my_results.results) == 4 ++ for result in my_results.results: ++ assert result.result == constants.SUCCESS ++ assert result.kw.get('msg') == 'File does not exist' +-- +2.26.3 + diff --git a/freeipa-healthcheck.spec b/freeipa-healthcheck.spec index 7f1368a..1192428 100644 --- a/freeipa-healthcheck.spec +++ b/freeipa-healthcheck.spec @@ -17,7 +17,7 @@ Name: %{prefix}-healthcheck Version: 0.9 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Health check tool for %{productname} BuildArch: noarch License: GPLv3 @@ -26,6 +26,7 @@ Source0: https://github.com/freeipa/freeipa-healthcheck/archive/%{version Source1: ipahealthcheck.conf Patch0001: 0001-Remove-ipaclustercheck.patch +Patch0002: 0002-Handle-files-that-don-t-exist-in-FileCheck.patch Requires: %{name}-core = %{version}-%{release} Requires: %{prefix}-server @@ -155,6 +156,9 @@ PYTHONPATH=src PATH=$PATH:$RPM_BUILD_ROOT/usr/bin pytest-3 tests/test_* %changelog +* Mon Jun 14 2021 Rob Crittenden - 0.9-2 +- FileCheck would raise a CRITICAL for non-existent files + * Tue Jun 8 2021 Rob Crittenden - 0.9-1 - Update to upstream 0.9 - Fix bad date in 0.8-6.1 changelog entry