Skip to content

Commit ee73c5e

Browse files
authored
Merge pull request ceph#66219 from guits/cv-migrate-to-dataclass
ceph-volume: migrate namedtuple based config and sysInfo to dataclasses
2 parents d168969 + 7a26546 commit ee73c5e

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
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: str = ''
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: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@
55
from ceph_volume import terminal, conf
66
from ceph_volume import exceptions
77
from sys import version_info as sys_version_info
8-
9-
if sys_version_info.major >= 3:
10-
import configparser
11-
conf_parentclass = configparser.ConfigParser
12-
elif sys_version_info.major < 3:
13-
import ConfigParser as configparser
14-
conf_parentclass = configparser.SafeConfigParser
15-
else:
16-
raise RuntimeError('Not expecting python version > 3 yet.')
17-
8+
import configparser
9+
from typing import Optional
1810

1911
logger = logging.getLogger(__name__)
2012

@@ -43,7 +35,7 @@ def load_ceph_conf_path(cluster_name='ceph'):
4335
conf.cluster = cluster_name
4436

4537

46-
def load(abspath=None):
38+
def load(abspath: Optional[str] = None):
4739
if abspath is None:
4840
abspath = conf.path
4941

@@ -65,7 +57,7 @@ def load(abspath=None):
6557
raise RuntimeError('Unable to read configuration file: %s' % abspath)
6658

6759

68-
class Conf(conf_parentclass):
60+
class Conf(configparser.ConfigParser):
6961
"""
7062
Subclasses from ConfigParser to give a few helpers for Ceph
7163
configuration.
@@ -81,10 +73,10 @@ def is_valid(self):
8173
except (configparser.NoSectionError, configparser.NoOptionError):
8274
raise exceptions.ConfigurationKeyError('global', 'fsid')
8375

84-
def optionxform(self, s):
85-
s = s.replace('_', ' ')
86-
s = '_'.join(s.split())
87-
return s
76+
def optionxform(self, optionstr):
77+
optionstr = optionstr.replace('_', ' ')
78+
optionstr = '_'.join(optionstr.split())
79+
return optionstr
8880

8981
def get_safe(self, section, key, default=None, check_valid=True):
9082
"""

src/ceph-volume/ceph_volume/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def main(self, argv):
168168
# we warn only here, because it is possible that the configuration
169169
# file is not needed, or that it will be loaded by some other means
170170
# (like reading from lvm tags)
171-
logger.warning('ignoring inability to load ceph.conf', exc_info=1)
171+
logger.warning('ignoring inability to load ceph.conf')
172172
terminal.yellow(error)
173173
# dispatch to sub-commands
174174
terminal.dispatch(self.mapper, subcommand_args)

0 commit comments

Comments
 (0)