Bug#1061794: crmsh fails its autopkg tests with Python 3.12

2024-02-13 Thread Florent 'Skia' Jacquet

Hi,

Those two patches should fix autopkgtest.

The importlib one shouldn't be a problem.

The looseversion one, otoh, requires a bit more attention. LooseVersion 
was part of distutils, and got removed with Python 3.12, but there 
doesn't seem to be any replacement anywhere in the standard library.

There are basically two solutions here for now:
  * use that patch since setuptools is already packaged and provide a 
working implementation of LooseVersion. It's still in a `._distutils` 
module, which doesn't make it appear as being officially part of the 
API, meaning it could break eventually if it gets removed from here too.
  * make another patch that would make use of the `looseversion` 
package [1], that is currently not packaged in Debian, but should 
probably be the safer way forward, since the only purpose of that 
package is to provide that API. I haven't yet started the work of 
packaging that `looseversion` module, and don't know if that's the right 
path forward.


Obviously, this also depends on what solution upstream will take to 
support Python 3.12. I've already opened an issue here: 
https://github.com/ClusterLabs/crmsh/issues/1324


I also have that branch that passes autopkgtests locally: 
https://git.launchpad.net/~hyask/ubuntu/+source/crmsh/log/


[1]: https://github.com/effigies/looseversion



Skiadiff --git a/test/unittests/test_utils.py b/test/unittests/test_utils.py
index 77fd14b0b67d..900e8528143a 100644
--- a/test/unittests/test_utils.py
+++ b/test/unittests/test_utils.py
@@ -7,7 +7,7 @@ from __future__ import unicode_literals
 import os
 import socket
 import re
-import imp
+import importlib
 import subprocess
 import unittest
 import pytest
@@ -24,7 +24,7 @@ def setup_function():
 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.utils.get_stdout_stderr")
diff --git a/crmsh/ra.py b/crmsh/ra.py
index 6060ec7a3fd5..fcadc860aa5f 100644
--- a/crmsh/ra.py
+++ b/crmsh/ra.py
@@ -49,15 +49,15 @@ def crm_resource(opts):
 
 @utils.memoize
 def can_use_lrmadmin():
-from distutils import version
+from setuptools._distutils.version import LooseVersion
 # after this glue release all users can get meta-data and
 # similar from lrmd
 minimum_glue = "1.0.10"
 _rc, glue_ver = 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 = LooseVersion(minimum_glue)
+v_this = LooseVersion(glue_ver)
 if v_this < v_min:
 return False
 if userdir.getuser() not in ("root", config.path.crm_daemon_user):
diff --git a/crmsh/utils.py b/crmsh/utils.py
index 51ff5b326d56..40c74a9019b5 100644
--- a/crmsh/utils.py
+++ b/crmsh/utils.py
@@ -34,7 +34,7 @@ from . import userdir
 from . import constants
 from . import options
 from . import term
-from distutils.version import LooseVersion
+from setuptools._distutils.version import LooseVersion
 from .constants import SSH_OPTION
 from . import log
 
diff --git a/debian/control b/debian/control
index 8fe560e13935..ea924b952335 100644
--- a/debian/control
+++ b/debian/control
@@ -40,6 +40,7 @@ Depends:
  python3-lxml,
  python3-packaging,
  python3-parallax,
+ python3-setuptools,
  python3-yaml
 Recommends: pacemaker (>= 1.1.12)
 Replaces: pacemaker (<< 1.1.12)


Bug#1061794: crmsh fails its autopkg tests with Python 3.12

2024-01-29 Thread Matthias Klose

Package: src:crmsh
Version: 4.5.0-1
Severity: important
Tags: sid trixie ftbfs
User: debian-pyt...@lists.debian.org
Usertags: python3.12

With python3-defaults from experimental, the package fails its autopkg 
tests:


[...]
1370s  ERRORS 

1370s __ ERROR collecting test_bootstrap.py 
__
1370s ImportError while importing test module 
'/usr/share/crmsh/tests/unittests/test_bootstrap.py'.

1370s Hint: make sure your test modules/packages have valid Python names.
1370s Traceback:
1370s /usr/lib/python3/dist-packages/_pytest/python.py:617: in 
_importtestmodule
1370s mod = import_path(self.path, mode=importmode, 
root=self.config.rootpath)

1370s /usr/lib/python3/dist-packages/_pytest/pathlib.py:567: in import_path
1370s importlib.import_module(module_name)
1370s /usr/lib/python3.12/importlib/__init__.py:90: in import_module
1370s return _bootstrap._gcd_import(name[level:], package, level)
1370s :1387: in _gcd_import
1370s ???
1370s :1360: in _find_and_load
1370s ???
1370s :1310: in _find_and_load_unlocked
1370s ???
1370s :488: in _call_with_frames_removed
1370s ???
1370s :1387: in _gcd_import
1370s ???
1370s :1360: in _find_and_load
1370s ???
1370s :1331: in _find_and_load_unlocked
1370s ???
1370s :935: in _load_unlocked
1370s ???
1370s :994: in exec_module
1370s ???
1370s :488: in _call_with_frames_removed
1370s ???
1370s __init__.py:22: in 
1370s from crmsh import cibconfig
1370s /usr/lib/python3/dist-packages/crmsh/cibconfig.py:15: in 
1370s from . import tmpfiles
1370s /usr/lib/python3/dist-packages/crmsh/tmpfiles.py:13: in 
1370s from . import utils
1370s /usr/lib/python3/dist-packages/crmsh/utils.py:37: in 
1370s from distutils.version import LooseVersion
1370s E   ModuleNotFoundError: No module named 'distutils'
1370s  ERROR collecting test_bugs.py 
_
1370s ImportError while importing test module 
'/usr/share/crmsh/tests/unittests/test_bugs.py'.

1370s Hint: make sure your test modules/packages have valid Python names.