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.
This commit is contained in:
Rafael Guterres Jeffman
2022-07-01 10:03:55 -03:00
parent c8d5cb7ee2
commit 87ff15a92c

View File

@@ -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