From 7a2654679e0c107757041790b02015a33a729115 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Wed, 12 Nov 2025 15:49:44 +0000 Subject: [PATCH] ceph-volume: drop legacy python2 support from configuration.py python 2 is no longer supported, so clean up the code accordingly. this also resolves a linter warning. Signed-off-by: Guillaume Abrioux --- src/ceph-volume/ceph_volume/__init__.py | 2 +- src/ceph-volume/ceph_volume/configuration.py | 21 ++++++-------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/ceph-volume/ceph_volume/__init__.py b/src/ceph-volume/ceph_volume/__init__.py index e1db4042d05d..59feb5c09152 100644 --- a/src/ceph-volume/ceph_volume/__init__.py +++ b/src/ceph-volume/ceph_volume/__init__.py @@ -53,7 +53,7 @@ class Config: ceph: Any = UnloadedConfig() cluster: Optional[str] = None verbosity: Optional[int] = None - path: Optional[str] = None + path: str = '' log_path: str = '' dmcrypt_no_workqueue: bool = False diff --git a/src/ceph-volume/ceph_volume/configuration.py b/src/ceph-volume/ceph_volume/configuration.py index fffad48ba265..6322c04fd154 100644 --- a/src/ceph-volume/ceph_volume/configuration.py +++ b/src/ceph-volume/ceph_volume/configuration.py @@ -5,18 +5,9 @@ import re from ceph_volume import terminal, conf from ceph_volume import exceptions from sys import version_info as sys_version_info +import configparser from typing import Optional -if sys_version_info.major >= 3: - import configparser - conf_parentclass = configparser.ConfigParser -elif sys_version_info.major < 3: - import ConfigParser as configparser - conf_parentclass = configparser.SafeConfigParser -else: - raise RuntimeError('Not expecting python version > 3 yet.') - - logger = logging.getLogger(__name__) @@ -66,7 +57,7 @@ def load(abspath: Optional[str] = None): raise RuntimeError('Unable to read configuration file: %s' % abspath) -class Conf(conf_parentclass): +class Conf(configparser.ConfigParser): """ Subclasses from ConfigParser to give a few helpers for Ceph configuration. @@ -82,10 +73,10 @@ class Conf(conf_parentclass): except (configparser.NoSectionError, configparser.NoOptionError): raise exceptions.ConfigurationKeyError('global', 'fsid') - def optionxform(self, s): - s = s.replace('_', ' ') - s = '_'.join(s.split()) - return s + def optionxform(self, optionstr): + optionstr = optionstr.replace('_', ' ') + optionstr = '_'.join(optionstr.split()) + return optionstr def get_safe(self, section, key, default=None, check_valid=True): """ -- 2.47.3