Skip to content

Commit f5b2e24

Browse files
committed
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 <[email protected]>
1 parent be8a046 commit f5b2e24

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/ceph-volume/ceph_volume/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import os
22
import logging
3-
from collections import namedtuple
3+
from dataclasses import dataclass
4+
from typing import Any, Optional
45

6+
@dataclass
7+
class SysInfo:
8+
devices: dict[str, list]
59

6-
sys_info = namedtuple('sys_info', ['devices'])
10+
sys_info = SysInfo(devices={})
711
sys_info.devices = dict()
12+
813
logger = logging.getLogger(__name__)
914
BEING_REPLACED_HEADER: str = 'CEPH_DEVICE_BEING_REPLACED'
1015

@@ -42,9 +47,17 @@ def __getattr__(self, *a):
4247

4348

4449
allow_loop_devices = AllowLoopDevices()
45-
conf = namedtuple('config', ['ceph', 'cluster', 'verbosity', 'path', 'log_path', 'dmcrypt_no_workqueue'])
46-
conf.ceph = UnloadedConfig()
47-
conf.dmcrypt_no_workqueue = None
50+
51+
@dataclass
52+
class Config:
53+
ceph: Any = UnloadedConfig()
54+
cluster: Optional[str] = None
55+
verbosity: Optional[int] = None
56+
path: Optional[str] = None
57+
log_path: str = ''
58+
dmcrypt_no_workqueue: bool = False
59+
60+
conf = Config()
4861

4962
__version__ = "1.0.0"
5063

src/ceph-volume/ceph_volume/configuration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from ceph_volume import terminal, conf
66
from ceph_volume import exceptions
77
from sys import version_info as sys_version_info
8+
from typing import Optional
89

910
if sys_version_info.major >= 3:
1011
import configparser
@@ -43,7 +44,7 @@ def load_ceph_conf_path(cluster_name='ceph'):
4344
conf.cluster = cluster_name
4445

4546

46-
def load(abspath=None):
47+
def load(abspath: Optional[str] = None):
4748
if abspath is None:
4849
abspath = conf.path
4950

0 commit comments

Comments
 (0)