summaryrefslogtreecommitdiffstats
path: root/debian/patches/0020-Replace-distutils.patch
blob: fd5cfb377729b53c53548645e4eda02a878b29cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Description: Fix build with python 3.12
Author: Valentin Vidic <vvidic@debian.org>
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")