From: Guillaume Abrioux Date: Wed, 12 Nov 2025 15:15:31 +0000 (+0000) Subject: ceph-volume: migrate namedtuple based config and sysInfo to dataclasses X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=f5b2e2454adcb6d1b7857972a80a2e5880fb33b5;p=ceph.git ceph-volume: migrate namedtuple based config and sysInfo to dataclasses this commit replaces the previous namedtuple definitions for config and sys_info with dataclasses. namedtuple is meant to be immutable, but the code modifies its attributes, so using dataclasses fixes this misuse. UnloadedConfig is preserved as the default for ceph in Config to maintain the runtime error behavior when accessing ceph configuration before it is loaded. Signed-off-by: Guillaume Abrioux --- diff --git a/src/ceph-volume/ceph_volume/__init__.py b/src/ceph-volume/ceph_volume/__init__.py index 8c04969a7011a..e1db4042d05d7 100644 --- a/src/ceph-volume/ceph_volume/__init__.py +++ b/src/ceph-volume/ceph_volume/__init__.py @@ -1,10 +1,15 @@ import os import logging -from collections import namedtuple +from dataclasses import dataclass +from typing import Any, Optional +@dataclass +class SysInfo: + devices: dict[str, list] -sys_info = namedtuple('sys_info', ['devices']) +sys_info = SysInfo(devices={}) sys_info.devices = dict() + logger = logging.getLogger(__name__) BEING_REPLACED_HEADER: str = 'CEPH_DEVICE_BEING_REPLACED' @@ -42,9 +47,17 @@ class UnloadedConfig(object): allow_loop_devices = AllowLoopDevices() -conf = namedtuple('config', ['ceph', 'cluster', 'verbosity', 'path', 'log_path', 'dmcrypt_no_workqueue']) -conf.ceph = UnloadedConfig() -conf.dmcrypt_no_workqueue = None + +@dataclass +class Config: + ceph: Any = UnloadedConfig() + cluster: Optional[str] = None + verbosity: Optional[int] = None + path: Optional[str] = None + log_path: str = '' + dmcrypt_no_workqueue: bool = False + +conf = Config() __version__ = "1.0.0" diff --git a/src/ceph-volume/ceph_volume/configuration.py b/src/ceph-volume/ceph_volume/configuration.py index e0f7ef1f0c655..fffad48ba265a 100644 --- a/src/ceph-volume/ceph_volume/configuration.py +++ b/src/ceph-volume/ceph_volume/configuration.py @@ -5,6 +5,7 @@ import re from ceph_volume import terminal, conf from ceph_volume import exceptions from sys import version_info as sys_version_info +from typing import Optional if sys_version_info.major >= 3: import configparser @@ -43,7 +44,7 @@ def load_ceph_conf_path(cluster_name='ceph'): conf.cluster = cluster_name -def load(abspath=None): +def load(abspath: Optional[str] = None): if abspath is None: abspath = conf.path