From 87ff15a92ccbbed37ae213e40b83d461981fd15e Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman <rjeffman@redhat.com> Date: Fri, 1 Jul 2022 10:03:55 -0300 Subject: [PATCH] api_check_ipa_version: Fix version comparison for more than one digit The fallback function used to compare IPA versions was spliting the version string into a tuple of strings, and the comparison of the tuple would fail if comparing a field with one digit aginst a two-digit one, for example, '8' with '10', as the string comparison would put '10' before the '8'. This patch forces the version fields to be converted to integers, so a numerical comparison will be performed. If a version string field cannot be converted to a number, than the string comparison will still be used. --- plugins/module_utils/ansible_freeipa_module.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py index 862aaabb..b6c17625 100644 --- a/plugins/module_utils/ansible_freeipa_module.py +++ b/plugins/module_utils/ansible_freeipa_module.py @@ -67,9 +67,15 @@ else: """ Split a version string A.B.C, into a tuple. - This will not work for `rc`, `dev` or similar version string. + This will not work for `rc`, `dev` or similar. """ - return tuple(re.split("[-_.]", version_str)) # noqa: W605 + try: + _version = tuple( + (int(x) for x in re.split("[-_.]", version_str)) + ) + except ValueError: + _version = tuple(re.split("[-_.]", version_str)) + return _version from ipalib import api from ipalib import errors as ipalib_errors # noqa -- GitLab