]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
teuthology: implement strtobool and use it
authorKefu Chai <tchaikov@gmail.com>
Thu, 18 Dec 2025 09:27:35 +0000 (17:27 +0800)
committerDavid Galloway <david.galloway@ibm.com>
Mon, 12 Jan 2026 22:10:34 +0000 (17:10 -0500)
The distutils module was deprecated in Python 3.10 and removed in
Python 3.12. This commit replaces the deprecated distutils.utils.strtobool
imports with strtobool in teuthology.util module.

Changes:
- Add strtobool.py to teuthology/util
- Replace distutils.util.strtobool with
teuthology.util.strtobool.strtobool

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
teuthology/describe_tests.py
teuthology/suite/__init__.py
teuthology/util/strtobool.py [new file with mode: 0644]

index c0054adc168005694c1266387d8d7e049f6c5a29..80c6f528dbf81f774c30dac6003e59b654dfae24 100644 (file)
@@ -8,12 +8,11 @@ import sys
 import yaml
 
 import random
-from distutils.util import strtobool
-
 from teuthology.exceptions import ParseError
 from teuthology.suite.build_matrix import \
         build_matrix, generate_combinations, _get_matrix
 from teuthology.suite import util, merge
+from teuthology.util.strtobool import strtobool
 
 def main(args):
     try:
index 8a17cf5f105e8d3e115586e45ae906abc98e8c88..5c87197eee1136fb4ec5e98b2501a977abbcabeb 100644 (file)
@@ -7,7 +7,6 @@ import os
 import random
 import sys
 import time
-from distutils.util import strtobool
 
 import teuthology
 from teuthology.config import config, YamlConfig
@@ -16,6 +15,7 @@ from teuthology.results import UNFINISHED_STATUSES
 
 from teuthology.suite.run import Run
 from teuthology.suite.util import schedule_fail
+from teuthology.util.strtobool import strtobool
 
 log = logging.getLogger(__name__)
 
diff --git a/teuthology/util/strtobool.py b/teuthology/util/strtobool.py
new file mode 100644 (file)
index 0000000..b6737e8
--- /dev/null
@@ -0,0 +1,14 @@
+def strtobool(val):
+    """Convert a string representation of truth to true (1) or false (0).
+    
+    True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
+    are 'n', 'no', 'f', 'false', 'off', and '0'.  Raises ValueError if
+    'val' is anything else.
+    """
+    val = val.lower()
+    if val in ('y', 'yes', 't', 'true', 'on', '1'):
+        return 1
+    elif val in ('n', 'no', 'f', 'false', 'off', '0'):
+        return 0
+    else:
+        raise ValueError(f"invalid truth value {val!r}")