Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions check-plugins/rpm-versionlock/rpm-versionlock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 13 additions & 18 deletions check-plugins/rpm-versionlock/unit-test/run
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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__':
Expand Down