55from textwrap import dedent
66from ceph_volume import decorators , process
77from ceph_volume .util import disk
8- from typing import Any , Dict , List
8+ from typing import Any , Dict , List as _List
99
1010logger = logging .getLogger (__name__ )
1111
@@ -20,50 +20,35 @@ def direct_report(devices):
2020 _list = List ([])
2121 return _list .generate (devices )
2222
23- def _get_bluestore_info (dev ):
23+ def _get_bluestore_info (dev : str ) -> Dict [str , Any ]:
24+ result : Dict [str , Any ] = {}
2425 out , err , rc = process .call ([
2526 'ceph-bluestore-tool' , 'show-label' ,
2627 '--dev' , dev ], verbose_on_failure = False )
2728 if rc :
2829 # ceph-bluestore-tool returns an error (below) if device is not bluestore OSD
2930 # > unable to read label for <device>: (2) No such file or directory
3031 # but it's possible the error could be for a different reason (like if the disk fails)
31- logger .debug ('assuming device {} is not BlueStore; ceph-bluestore-tool failed to get info from device: {}\n {}' .format (dev , out , err ))
32- return None
33- oj = json .loads ('' .join (out ))
34- if dev not in oj :
35- # should be impossible, so warn
36- logger .warning ('skipping device {} because it is not reported in ceph-bluestore-tool output: {}' .format (dev , out ))
37- return None
38- try :
39- r = {
40- 'osd_uuid' : oj [dev ]['osd_uuid' ],
41- }
42- if oj [dev ]['description' ] == 'main' :
43- whoami = oj [dev ]['whoami' ]
44- r .update ({
45- 'type' : 'bluestore' ,
46- 'osd_id' : int (whoami ),
47- 'ceph_fsid' : oj [dev ]['ceph_fsid' ],
48- 'device' : dev ,
49- })
50- elif oj [dev ]['description' ] == 'bluefs db' :
51- r ['device_db' ] = dev
52- elif oj [dev ]['description' ] == 'bluefs wal' :
53- r ['device_wal' ] = dev
54- return r
55- except KeyError as e :
56- # this will appear for devices that have a bluestore header but aren't valid OSDs
57- # for example, due to incomplete rollback of OSDs: https://tracker.ceph.com/issues/51869
58- logger .error ('device {} does not have all BlueStore data needed to be a valid OSD: {}\n {}' .format (dev , out , e ))
59- return None
32+ logger .debug (f'assuming device { dev } is not BlueStore; ceph-bluestore-tool failed to get info from device: { out } \n { err } ' )
33+ else :
34+ oj = json .loads ('' .join (out ))
35+ if dev not in oj :
36+ # should be impossible, so warn
37+ logger .warning (f'skipping device { dev } because it is not reported in ceph-bluestore-tool output: { out } ' )
38+ try :
39+ result = disk .bluestore_info (dev , oj )
40+ except KeyError as e :
41+ # this will appear for devices that have a bluestore header but aren't valid OSDs
42+ # for example, due to incomplete rollback of OSDs: https://tracker.ceph.com/issues/51869
43+ logger .error (f'device { dev } does not have all BlueStore data needed to be a valid OSD: { out } \n { e } ' )
44+ return result
6045
6146
6247class List (object ):
6348
6449 help = 'list BlueStore OSDs on raw devices'
6550
66- def __init__ (self , argv ) :
51+ def __init__ (self , argv : _List [ str ]) -> None :
6752 self .argv = argv
6853
6954 def is_atari_partitions (self , _lsblk : Dict [str , Any ]) -> bool :
@@ -81,7 +66,7 @@ def is_atari_partitions(self, _lsblk: Dict[str, Any]) -> bool:
8166 return True
8267 return False
8368
84- def exclude_atari_partitions (self , _lsblk_all : Dict [str , Any ]) -> List [Dict [str , Any ]]:
69+ def exclude_atari_partitions (self , _lsblk_all : Dict [str , Any ]) -> _List [Dict [str , Any ]]:
8570 return [_lsblk for _lsblk in _lsblk_all if not self .is_atari_partitions (_lsblk )]
8671
8772 def generate (self , devs = None ):
@@ -113,7 +98,7 @@ def generate(self, devs=None):
11398 logger .debug ('inspecting devices: {}' .format (devs ))
11499 for info_device in info_devices :
115100 bs_info = _get_bluestore_info (info_device ['NAME' ])
116- if bs_info is None :
101+ if not bs_info :
117102 # None is also returned in the rare event that there is an issue reading info from
118103 # a BlueStore disk, so be sure to log our assumption that it isn't bluestore
119104 logger .info ('device {} does not have BlueStore information' .format (info_device ['NAME' ]))
0 commit comments