]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: migrate namedtuple based config and sysInfo to dataclasses
authorGuillaume Abrioux <gabrioux@ibm.com>
Wed, 12 Nov 2025 15:15:31 +0000 (15:15 +0000)
committerGuillaume Abrioux <gabrioux@ibm.com>
Wed, 12 Nov 2025 15:21:01 +0000 (15:21 +0000)
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 <gabrioux@ibm.com>
src/ceph-volume/ceph_volume/__init__.py
src/ceph-volume/ceph_volume/configuration.py

index 8c04969a7011a34446c82324645ba42c54bf8472..e1db4042d05d7b113344d6ee320bf12d27370604 100644 (file)
@@ -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"
 
index e0f7ef1f0c6551e89385643cf77ec51e3d1f02b2..fffad48ba265a4236d04513d0bc0f3ae231865bd 100644 (file)
@@ -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