Description: Fix build with python 3.12 Author: Valentin Vidic Last-Update: 2024-03-04 --- This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ --- a/crmsh/ra.py +++ b/crmsh/ra.py @@ -50,15 +50,15 @@ @utils.memoize def can_use_lrmadmin(): - from distutils import version + from packaging.version import Version # after this glue release all users can get meta-data and # similar from lrmd minimum_glue = "1.0.10" _rc, glue_ver = ShellUtils().get_stdout("%s -v" % lrmadmin_prog, stderr_on=False) if not glue_ver: # lrmadmin probably not found return False - v_min = version.LooseVersion(minimum_glue) - v_this = version.LooseVersion(glue_ver) + v_min = Version(minimum_glue) + v_this = Version(glue_ver) if v_this < v_min: return False if userdir.getuser() not in ("root", config.path.crm_daemon_user): --- a/crmsh/utils.py +++ b/crmsh/utils.py @@ -37,7 +37,7 @@ from . import constants from . import options from . import term -from distutils.version import LooseVersion +from packaging import version from .constants import SSH_OPTION from . import log from .prun import prun @@ -1632,8 +1632,15 @@ return val_l -def is_larger_than_min_version(version, min_version): - return LooseVersion(version) >= LooseVersion(min_version) +def is_larger_than_min_version(this_version, min_version): + version_re = re.compile(version.VERSION_PATTERN, re.VERBOSE | re.IGNORECASE) + match1 = version_re.search(this_version) + if not match1: + raise InvalidVersion(f"Invalid version: '{this_version}'") + match2 = version_re.search(min_version) + if not match2: + raise InvalidVersion(f"Invalid version: '{min_version}'") + return version.parse(match1.group(0)) >= version.parse(match2.group(0)) def is_min_pcmk_ver(min_ver, cib_f=None): --- a/test/unittests/test_utils.py +++ b/test/unittests/test_utils.py @@ -7,7 +7,7 @@ import os import socket import re -import imp +import importlib import subprocess import unittest import pytest @@ -24,7 +24,7 @@ utils._ip_for_cloud = None # Mock memoize method and reload the module under test later with imp mock.patch('crmsh.utils.memoize', lambda x: x).start() - imp.reload(utils) + importlib.reload(utils) @mock.patch("crmsh.sh.ShellUtils.get_stdout_stderr")