diff --git a/check-plugins/rpm-versionlock/rpm-versionlock b/check-plugins/rpm-versionlock/rpm-versionlock index 01540b6fc..e2e91bdda 100755 --- a/check-plugins/rpm-versionlock/rpm-versionlock +++ b/check-plugins/rpm-versionlock/rpm-versionlock @@ -565,6 +565,9 @@ def get_dnf5_locks(root): DNF5_LOCKFILE_VERSION for the difference and for what was measured. """ if tomllib is None: + lockfile = rooted(root, DNF5_LOCKFILE) + if lib.disk.file_exists(lockfile, allow_empty=True): + return [], [], [f'{lockfile} cannot be read, this needs Python 3.11 or newer'] return [], [], [] lockfile = rooted(root, DNF5_LOCKFILE) diff --git a/check-plugins/rpm-versionlock/unit-test/run b/check-plugins/rpm-versionlock/unit-test/run index b3ed67fff..c2282622e 100755 --- a/check-plugins/rpm-versionlock/unit-test/run +++ b/check-plugins/rpm-versionlock/unit-test/run @@ -24,13 +24,11 @@ except ImportError: # The plugin reads the dnf 5 lock file with `tomllib` and ships no backport, because # every distribution that ships dnf 5 also ships a Python that has that module. On the -# older interpreters of the tox matrix the plugin therefore reports no dnf 5 locks, and -# the testcases that expect parsed locks cannot pass. They are skipped there instead of -# asserting the degraded result, so a real regression on those interpreters still fails -# the run. `ok-dnf5-no-locks` and `warn-excludes-disabled-wholesale-dnf5` stay in, -# because neither needs the TOML file to be parsed. Drop this skip once the plugin -# reports the unreadable file instead of staying silent about it, see -# https://github.com/Linuxfabrik/monitoring-plugins/issues/1462. +# older interpreters without `tomllib` the plugin reports the unreadable file with +# WARN ("cannot be read, this needs Python 3.11 or newer") instead of staying silent, +# so those testcases now assert that message. `ok-dnf5-no-locks` and +# `warn-excludes-disabled-wholesale-dnf5` stay as they are, because neither needs the +# TOML file to be parsed, see https://github.com/Linuxfabrik/monitoring-plugins/issues/1462. NEEDS_TOMLLIB = [ 'warn-dnf5-broken-toml', 'warn-dnf5-excludes-checked', @@ -601,18 +599,15 @@ class TestCheck(unittest.TestCase): check = '../rpm-versionlock' -lib.lftest.attach_tests(TestCheck, TESTS) - if tomllib is None: - for test_id in NEEDS_TOMLLIB: - method_name = 'test_' + test_id.replace('-', '_') - setattr( - TestCheck, - method_name, - unittest.skip('dnf 5 locks are TOML, which needs Python 3.11 or newer')( - getattr(TestCheck, method_name) - ), - ) + for testcase in TESTS: + if testcase['id'] in NEEDS_TOMLLIB: + testcase['assert-retc'] = STATE_WARN + testcase['assert-in'] = ['cannot be read, this needs Python 3.11 or newer'] + testcase.pop('assert-not-in', None) + testcase.pop('assert-regex', None) + +lib.lftest.attach_tests(TestCheck, TESTS) if __name__ == '__main__':