Skip to content

Commit 79acee1

Browse files
committed
ceph-volume: fix type annotation in objectore
This commit addresses some python type annotations errors in `objectstore` code. Signed-off-by: Guillaume Abrioux <[email protected]>
1 parent 3f6dae8 commit 79acee1

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

src/ceph-volume/ceph_volume/api/lvm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ def __init__(self, **kw: Any) -> None:
835835
self.lv_name: str = ''
836836
self.lv_uuid: str = ''
837837
self.vg_name: str = ''
838+
self.lv_tags: Dict[str, Any] = {}
838839
for k, v in kw.items():
839840
setattr(self, k, v)
840841
self.lv_api = kw

src/ceph-volume/ceph_volume/objectstore/baseobjectstore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def prepare_data_device(self,
6464
osd_uuid: str) -> Optional["Volume"]:
6565
raise NotImplementedError()
6666

67-
def safe_prepare(self, args: "argparse.Namespace") -> None:
67+
def safe_prepare(self, args: Optional["argparse.Namespace"] = None) -> None:
6868
raise NotImplementedError()
6969

7070
def add_objectstore_opts(self) -> None:

src/ceph-volume/ceph_volume/objectstore/bluestore.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def osd_mkfs(self) -> None:
101101
if self.method == 'raw':
102102
path = self.args.__dict__.get(dev_type, None)
103103
else:
104-
path = self.block_lv.tags.get(dev_type, None)
104+
if self.block_lv is not None:
105+
path = self.block_lv.tags.get(dev_type, None)
106+
else:
107+
raise RuntimeError('Unexpected error while running bluestore mkfs.')
105108
if path is not None:
106109
CephLuks2(path).config_luks2({'subsystem': f'ceph_fsid={self.osd_fsid}'})

src/ceph-volume/ceph_volume/objectstore/lvmbluestore.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ def safe_prepare(self,
121121
except ValueError:
122122
lv = None
123123

124-
if api.is_ceph_device(lv):
125-
logger.info("device {} is already used".format(self.args.data))
126-
raise RuntimeError("skipping {}, it is already prepared".format(
127-
self.args.data))
124+
if lv is not None:
125+
if api.is_ceph_device(lv):
126+
logger.info("device {} is already used".format(self.args.data))
127+
raise RuntimeError("skipping {}, it is already prepared".format(
128+
self.args.data))
128129
try:
129130
self.prepare()
130131
except Exception:
@@ -253,23 +254,26 @@ def setup_device(self,
253254
lv_type = "osd-{}".format(device_type)
254255
name_uuid = system.generate_uuid()
255256
kwargs = {
257+
'name_prefix': lv_type,
258+
'uuid': name_uuid,
259+
'vg': None,
256260
'device': device_name,
261+
'slots': slots,
262+
'extents': None,
263+
'size': None,
257264
'tags': tags,
258-
'slots': slots
259265
}
260266
# TODO use get_block_db_size and co here to get configured size in
261267
# conf file
262268
if size != 0:
263269
kwargs['size'] = size
264-
lv = api.create_lv(
265-
lv_type,
266-
name_uuid,
267-
**kwargs)
268-
path = lv.lv_path
269-
tags['ceph.{}_device'.format(device_type)] = path
270-
tags['ceph.{}_uuid'.format(device_type)] = lv.lv_uuid
271-
lv_uuid = lv.lv_uuid
272-
lv.set_tags(tags)
270+
lv = api.create_lv(**kwargs)
271+
if lv is not None:
272+
path = lv.lv_path
273+
lv_uuid = lv.lv_uuid
274+
tags['ceph.{}_device'.format(device_type)] = path
275+
tags['ceph.{}_uuid'.format(device_type)] = lv_uuid
276+
lv.set_tags(tags)
273277
else:
274278
# otherwise assume this is a regular disk partition
275279
name_uuid = self.get_ptuuid(device_name)
@@ -282,8 +286,7 @@ def setup_device(self,
282286
def get_osd_device_path(self,
283287
osd_lvs: List["Volume"],
284288
device_type: str,
285-
dmcrypt_secret: Optional[str] =
286-
None) -> Optional[str]:
289+
dmcrypt_secret: str = '') -> Optional[str]:
287290
"""
288291
``device_type`` can be one of ``db``, ``wal`` or ``block`` so that we
289292
can query LVs on system and fallback to querying the uuid if that is
@@ -303,7 +306,7 @@ def get_osd_device_path(self,
303306
logger.debug('Found block device (%s) with encryption: %s',
304307
osd_block_lv.name, is_encrypted)
305308
uuid_tag = 'ceph.%s_uuid' % device_type
306-
device_uuid = osd_block_lv.tags.get(uuid_tag)
309+
device_uuid = osd_block_lv.tags.get(uuid_tag, '')
307310
if not device_uuid:
308311
return None
309312

src/ceph-volume/ceph_volume/objectstore/rawbluestore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, args: "argparse.Namespace") -> None:
2222
super().__init__(args)
2323
self.method = 'raw'
2424
self.devices: List[str] = getattr(args, 'devices', [])
25-
self.osd_id = getattr(self.args, 'osd_id', None)
25+
self.osd_id = getattr(self.args, 'osd_id', '')
2626
self.osd_fsid = getattr(self.args, 'osd_fsid', '')
2727
self.block_device_path = getattr(self.args, 'data', '')
2828
self.db_device_path = getattr(self.args, 'block_db', '')
@@ -164,7 +164,7 @@ def activate(self) -> None:
164164
activated_any: bool = False
165165

166166
for d in disk.lsblk_all(abspath=True):
167-
device: str = d.get('NAME')
167+
device: str = d.get('NAME', '')
168168
luks2 = encryption_utils.CephLuks2(device)
169169
if luks2.is_ceph_encrypted:
170170
if luks2.is_tpm2_enrolled and self.osd_fsid == luks2.osd_fsid:

0 commit comments

Comments
 (0)