assert result[lv_path]['human_readable_size'] == '100.00 MB'
+class TestGetBlockDevsSysfs(object):
+ def test_optical_device_is_skipped(self, fake_filesystem):
+ # sr0 is a CDROM (IPMI/BMC virtual media),not a usable disk.
+ fake_filesystem.create_file('/dev/sr0')
+ fake_filesystem.create_dir('/sys/dev/block')
+ fake_filesystem.create_dir('/sys/block/sr0/holders')
+ fake_filesystem.create_dir('/sys/block/sr0/device')
+ fake_filesystem.create_file('/sys/block/sr0/device/type', contents='5\n')
+
+ assert disk.get_block_devs_sysfs(device='sr0') == []
+
+ def test_regular_device_is_not_skipped(self, fake_filesystem):
+ # normal disk should still be reported.
+ fake_filesystem.create_file('/dev/sda')
+ fake_filesystem.create_dir('/sys/dev/block')
+ fake_filesystem.create_dir('/sys/block/sda/holders')
+
+ result = disk.get_block_devs_sysfs(device='sda')
+ assert result == [['/dev/sda', '/dev/sda', 'disk', '/dev/sda']]
+
+
class TestSizeCalculations(object):
@pytest.mark.parametrize('aliases', [
name = kname = pname = os.path.join("/dev", dev)
if not os.path.exists(name):
continue
+ # Exclude any CDROM devices (ex: IPMI devices)
+ # The linux kernel reports these as SCSI device type 5 under /sys/block/<dev>/device/type
+ # and they appear as /dev/sr* (ex: /dev/sr0)
+ # These are not physical disks and are not valid OSD targets, so skip them.
+ if get_file_contents(os.path.join(_sys_block_path, dev, 'device/type'), '').strip() == '5':
+ continue
type_: str = 'disk'
holders: List[str] = os.listdir(os.path.join(_sys_block_path, dev, 'holders'))
if holder_inner_loop():