def _parse(self): if not sys_info.devices: sys_info.devices = disk.get_devices() self.sys_api = sys_info.devices.get(self.abspath, {}) if not self.sys_api: # if no device was found check if we are a partition partname = self.abspath.split('/')[-1] for device, info in sys_info.devices.items(): part = info['partitions'].get(partname, {}) if part: self.sys_api = part break # start with lvm since it can use an absolute or relative path lv = lvm.get_lv_from_argument(self.path) if lv: self.lv_api = lv self.lvs = [lv] self.abspath = lv.lv_path self.vg_name = lv.vg_name self.lv_name = lv.name else: dev = disk.lsblk(self.path) self.blkid_api = disk.blkid(self.path) self.disk_api = dev device_type = dev.get('TYPE', '') # always check is this is an lvm member if device_type in ['part', 'disk']: self._set_lvm_membership() self.ceph_disk = CephDiskDevice(self)
def get_devices(self): # remove devices with partitions devices = [(device, details) for device, details in disk.get_devices().items() if details.get('partitions') == {}] size_sort = lambda x: (x[0], x[1]['size']) return device_formatter(sorted(devices, key=size_sort))
def _parse(self): if not sys_info.devices: sys_info.devices = disk.get_devices() self.sys_api = sys_info.devices.get(self.abspath, {}) if not self.sys_api: # if no device was found check if we are a partition partname = self.abspath.split('/')[-1] for device, info in sys_info.devices.items(): part = info['partitions'].get(partname, {}) if part: self.sys_api = part break # start with lvm since it can use an absolute or relative path lv = lvm.get_lv_from_argument(self.path) if lv: self.lv_api = lv self.lvs = [lv] self.abspath = lv.lv_path self.vg_name = lv.vg_name self.lv_name = lv.name else: dev = disk.lsblk(self.path) self.blkid_api = disk.blkid(self.path) self.disk_api = dev device_type = dev.get('TYPE', '') # always check is this is an lvm member if device_type in ['part', 'disk']: self._set_lvm_membership() self.ceph_disk = CephDiskDevice(self)
def test_sda_size(self, patched_get_block_devs_sysfs, fake_filesystem): sda_path = '/dev/sda' patched_get_block_devs_sysfs.return_value = [[sda_path, sda_path, 'disk']] fake_filesystem.create_file('/sys/block/sda/size', contents = '1024') result = disk.get_devices() assert list(result.keys()) == [sda_path] assert result[sda_path]['human_readable_size'] == '512.00 KB'
def test_sda_sectorsize_does_not_fallback(self, patched_get_block_devs_sysfs, fake_filesystem): sda_path = '/dev/sda' patched_get_block_devs_sysfs.return_value = [[sda_path, sda_path, 'disk']] fake_filesystem.create_file('/sys/block/sda/queue/logical_block_size', contents = '99') fake_filesystem.create_file('/sys/block/sda/queue/hw_sector_size', contents = '1024') result = disk.get_devices() assert result[sda_path]['sectorsize'] == '99'
def __init__(self, filter_for_batch=False): if not sys_info.devices: sys_info.devices = disk.get_devices() self.devices = [Device(k) for k in sys_info.devices.keys()] if filter_for_batch: self.devices = [d for d in self.devices if d.available_lvm_batch]
def test_no_devices_are_found_errors(self, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) os.makedirs(os.path.join(block_path, 'sda')) result = disk.get_devices( _sys_block_path=block_path, # has 1 device _dev_path=str(tmpdir), # exists but no devices _mapper_path='/does/not/exist/path') # does not exist assert result == {}
def test_sda_sectorsize_fallsback(self, patched_get_block_devs_sysfs, fake_filesystem): # if no sectorsize, it will use queue/hw_sector_size sda_path = '/dev/sda' patched_get_block_devs_sysfs.return_value = [[sda_path, sda_path, 'disk']] fake_filesystem.create_file('/sys/block/sda/queue/hw_sector_size', contents = '1024') result = disk.get_devices() assert list(result.keys()) == [sda_path] assert result[sda_path]['sectorsize'] == '1024'
def test_sda_block_is_found(self, patched_get_block_devs_sysfs, fake_filesystem): sda_path = '/dev/sda' patched_get_block_devs_sysfs.return_value = [[sda_path, sda_path, 'disk']] result = disk.get_devices() assert len(result.keys()) == 1 assert result[sda_path]['human_readable_size'] == '0.00 B' assert result[sda_path]['model'] == '' assert result[sda_path]['partitions'] == {}
def test_no_devices_are_found_errors(self, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) os.makedirs(os.path.join(block_path, 'sda')) result = disk.get_devices( _sys_block_path=block_path, # has 1 device _dev_path=str(tmpdir), # exists but no devices _mapper_path='/does/not/exist/path') # does not exist assert result == {}
def get_devices(self): all_devices = disk.get_devices() # remove devices with partitions # XXX Should be optional when getting device info for device, detail in all_devices.items(): if detail.get('partitions') != {}: del all_devices[device] devices = sorted(all_devices.items(), key=lambda x: (x[0], x[1]['size'])) return device_formatter(devices)
def get_devices(self): all_devices = disk.get_devices() # remove devices with partitions # XXX Should be optional when getting device info for device, detail in all_devices.items(): if detail.get('partitions') != {}: del all_devices[device] devices = sorted(all_devices.items(), key=lambda x: (x[0], x[1]['size'])) return device_formatter(devices)
def test_is_ceph_rbd(self, tmpfile, tmpdir, patched_get_block_devs_lsblk): rbd_path = '/dev/rbd0' patched_get_block_devs_lsblk.return_value = [[ rbd_path, rbd_path, 'disk' ]] block_path = self.setup_path(tmpdir) block_rbd_path = os.path.join(block_path, 'rbd0') os.makedirs(block_rbd_path) result = disk.get_devices(_sys_block_path=block_path) assert rbd_path not in result
def test_sda_size(self, tmpfile, tmpdir, patched_get_block_devs_lsblk): sda_path = '/dev/sda' patched_get_block_devs_lsblk.return_value = [[sda_path, sda_path, 'disk']] block_path = self.setup_path(tmpdir) block_sda_path = os.path.join(block_path, 'sda') os.makedirs(block_sda_path) tmpfile('size', '1024', directory=block_sda_path) result = disk.get_devices(_sys_block_path=block_path) assert list(result.keys()) == [sda_path] assert result[sda_path]['human_readable_size'] == '512.00 KB'
def test_sda_block_is_found(self, tmpdir, patched_get_block_devs_lsblk): sda_path = '/dev/sda' patched_get_block_devs_lsblk.return_value = [[sda_path, sda_path, 'disk']] block_path = self.setup_path(tmpdir) os.makedirs(os.path.join(block_path, 'sda')) result = disk.get_devices(_sys_block_path=block_path) assert len(result.keys()) == 1 assert result[sda_path]['human_readable_size'] == '0.00 B' assert result[sda_path]['model'] == '' assert result[sda_path]['partitions'] == {}
def test_is_rotational(self, tmpfile, tmpdir, patched_get_block_devs_lsblk): sda_path = '/dev/sda' patched_get_block_devs_lsblk.return_value = [[sda_path, sda_path, 'disk']] block_path = self.setup_path(tmpdir) block_sda_path = os.path.join(block_path, 'sda') sda_queue_path = os.path.join(block_sda_path, 'queue') os.makedirs(block_sda_path) os.makedirs(sda_queue_path) tmpfile('rotational', contents='1', directory=sda_queue_path) result = disk.get_devices(_sys_block_path=block_path) assert result[sda_path]['rotational'] == '1'
def test_sda_sectorsize_from_logical_block(self, tmpfile, tmpdir, patched_get_block_devs_lsblk): sda_path = '/dev/sda' patched_get_block_devs_lsblk.return_value = [[sda_path, sda_path, 'disk']] block_path = self.setup_path(tmpdir) block_sda_path = os.path.join(block_path, 'sda') sda_queue_path = os.path.join(block_sda_path, 'queue') os.makedirs(block_sda_path) os.makedirs(sda_queue_path) tmpfile('logical_block_size', contents='99', directory=sda_queue_path) result = disk.get_devices(_sys_block_path=block_path) assert result[sda_path]['sectorsize'] == '99'
def test_sda_size(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) block_sda_path = os.path.join(block_path, 'sda') dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(block_sda_path) os.makedirs(dev_sda_path) tmpfile('size', '1024', directory=block_sda_path) result = disk.get_devices(_sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert list(result.keys()) == [dev_sda_path] assert result[dev_sda_path]['human_readable_size'] == '512.00 KB'
def test_sda_block_is_found(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(os.path.join(block_path, 'sda')) os.makedirs(dev_sda_path) result = disk.get_devices(_sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert len(result.keys()) == 1 assert result[dev_sda_path]['human_readable_size'] == '0.00 B' assert result[dev_sda_path]['model'] == '' assert result[dev_sda_path]['partitions'] == {}
def test_sda_is_removable_gets_skipped(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) dev_sda_path = os.path.join(dev_path, 'sda') block_sda_path = os.path.join(block_path, 'sda') os.makedirs(block_sda_path) os.makedirs(dev_sda_path) tmpfile('removable', contents='1', directory=block_sda_path) result = disk.get_devices(_sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert result == {}
def test_sda_sectorsize_fallsback(self, tmpfile, tmpdir, patched_get_block_devs_lsblk): # if no sectorsize, it will use queue/hw_sector_size sda_path = '/dev/sda' patched_get_block_devs_lsblk.return_value = [[sda_path, sda_path, 'disk']] block_path = self.setup_path(tmpdir) block_sda_path = os.path.join(block_path, 'sda') sda_queue_path = os.path.join(block_sda_path, 'queue') os.makedirs(block_sda_path) os.makedirs(sda_queue_path) tmpfile('hw_sector_size', contents='1024', directory=sda_queue_path) result = disk.get_devices(_sys_block_path=block_path) assert list(result.keys()) == [sda_path] assert result[sda_path]['sectorsize'] == '1024'
def test_sda_size(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) block_sda_path = os.path.join(block_path, 'sda') dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(block_sda_path) os.makedirs(dev_sda_path) tmpfile('size', '1024', directory=block_sda_path) result = disk.get_devices( _sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert list(result.keys()) == [dev_sda_path] assert result[dev_sda_path]['human_readable_size'] == '512.00 KB'
def test_sda_sectorsize_from_logical_block(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) block_sda_path = os.path.join(block_path, 'sda') sda_queue_path = os.path.join(block_sda_path, 'queue') dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(block_sda_path) os.makedirs(sda_queue_path) os.makedirs(dev_sda_path) tmpfile('logical_block_size', contents='99', directory=sda_queue_path) result = disk.get_devices(_sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert result[dev_sda_path]['sectorsize'] == '99'
def test_is_rotational(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) block_sda_path = os.path.join(block_path, 'sda') sda_queue_path = os.path.join(block_sda_path, 'queue') dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(block_sda_path) os.makedirs(sda_queue_path) os.makedirs(dev_sda_path) tmpfile('rotational', contents='1', directory=sda_queue_path) result = disk.get_devices(_sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert result[dev_sda_path]['rotational'] == '1'
def test_sda_block_is_found(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(os.path.join(block_path, 'sda')) os.makedirs(dev_sda_path) result = disk.get_devices( _sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert len(result.keys()) == 1 assert result[dev_sda_path]['human_readable_size'] == '0.00 B' assert result[dev_sda_path]['model'] == '' assert result[dev_sda_path]['partitions'] == {}
def test_sda_is_removable_gets_skipped(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) dev_sda_path = os.path.join(dev_path, 'sda') block_sda_path = os.path.join(block_path, 'sda') os.makedirs(block_sda_path) os.makedirs(dev_sda_path) tmpfile('removable', contents='1', directory=block_sda_path) result = disk.get_devices( _sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert result == {}
def test_sda_sectorsize_from_logical_block(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) block_sda_path = os.path.join(block_path, 'sda') sda_queue_path = os.path.join(block_sda_path, 'queue') dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(block_sda_path) os.makedirs(sda_queue_path) os.makedirs(dev_sda_path) tmpfile('logical_block_size', contents='99', directory=sda_queue_path) result = disk.get_devices( _sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert result[dev_sda_path]['sectorsize'] == '99'
def test_is_rotational(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) block_sda_path = os.path.join(block_path, 'sda') sda_queue_path = os.path.join(block_sda_path, 'queue') dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(block_sda_path) os.makedirs(sda_queue_path) os.makedirs(dev_sda_path) tmpfile('rotational', contents='1', directory=sda_queue_path) result = disk.get_devices( _sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert result[dev_sda_path]['rotational'] == '1'
def test_sda_sectorsize_fallsback(self, tmpfile, tmpdir): # if no sectorsize, it will use queue/hw_sector_size block_path, dev_path, mapper_path = self.setup_paths(tmpdir) block_sda_path = os.path.join(block_path, 'sda') sda_queue_path = os.path.join(block_sda_path, 'queue') dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(block_sda_path) os.makedirs(sda_queue_path) os.makedirs(dev_sda_path) tmpfile('hw_sector_size', contents='1024', directory=sda_queue_path) result = disk.get_devices(_sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert list(result.keys()) == [dev_sda_path] assert result[dev_sda_path]['sectorsize'] == '1024'
def test_dm_device_is_not_used(self, monkeypatch, tmpdir): # the link to the mapper is used instead monkeypatch.setattr(disk.lvm, 'is_lv', lambda: True) block_path, dev_path, mapper_path = self.setup_paths(tmpdir) dev_dm_path = os.path.join(dev_path, 'dm-0') ceph_data_path = os.path.join(mapper_path, 'ceph-data') os.symlink(dev_dm_path, ceph_data_path) block_dm_path = os.path.join(block_path, 'dm-0') os.makedirs(block_dm_path) result = disk.get_devices(_sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) result = list(result.keys()) assert len(result) == 1 assert result == [ceph_data_path]
def __init__(self, filter_for_batch=False, with_lsm=False): lvs = lvm.get_lvs() lsblk_all = disk.lsblk_all() all_devices_vgs = lvm.get_all_devices_vgs() if not sys_info.devices: sys_info.devices = disk.get_devices() self.devices = [ Device(k, with_lsm, lvs=lvs, lsblk_all=lsblk_all, all_devices_vgs=all_devices_vgs) for k in sys_info.devices.keys() ] if filter_for_batch: self.devices = [d for d in self.devices if d.available_lvm_batch]
def get_filtered_devices(self, devices): """ Parse all devices in the current system and keep only the ones that are being explicity passed in """ system_devices = disk.get_devices() if not devices: return system_devices.values() parsed_devices = [] for device in devices: try: parsed_devices.append(system_devices[device]) except KeyError: continue return parsed_devices
def test_sda_sectorsize_fallsback(self, tmpfile, tmpdir): # if no sectorsize, it will use queue/hw_sector_size block_path, dev_path, mapper_path = self.setup_paths(tmpdir) block_sda_path = os.path.join(block_path, 'sda') sda_queue_path = os.path.join(block_sda_path, 'queue') dev_sda_path = os.path.join(dev_path, 'sda') os.makedirs(block_sda_path) os.makedirs(sda_queue_path) os.makedirs(dev_sda_path) tmpfile('hw_sector_size', contents='1024', directory=sda_queue_path) result = disk.get_devices( _sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert list(result.keys()) == [dev_sda_path] assert result[dev_sda_path]['sectorsize'] == '1024'
def get_filtered_devices(self, devices): """ Parse all devices in the current system and keep only the ones that are being explicity passed in """ system_devices = disk.get_devices() if not devices: return system_devices.values() parsed_devices = [] for device in devices: try: parsed_devices.append(system_devices[device]) except KeyError: continue return parsed_devices
def __init__(self, path, with_lsm=False, lvs=None, lsblk_all=None, all_devices_vgs=None): self.path = path # LVs can have a vg/lv path, while disks will have /dev/sda self.symlink = None # check if we are a symlink if os.path.islink(self.path): self.symlink = self.path real_path = os.path.realpath(self.path) # check if we are not a device mapper if "dm-" not in real_path: self.path = real_path if not sys_info.devices: sys_info.devices = disk.get_devices() if sys_info.devices.get(self.path, {}): self.device_nodes = sys_info.devices[self.path]['device_nodes'] self.sys_api = sys_info.devices.get(self.path, {}) self.partitions = self._get_partitions() self.lv_api = None self.lvs = [] if not lvs else lvs self.lsblk_all = lsblk_all self.all_devices_vgs = all_devices_vgs self.vgs = [] self.vg_name = None self.lv_name = None self.disk_api = {} self.blkid_api = None self._exists = None self._is_lvm_member = None self._parse() self.lsm_data = self.fetch_lsm(with_lsm) self.ceph_device = None self.available_lvm, self.rejected_reasons_lvm = self._check_lvm_reject_reasons( ) self.available_raw, self.rejected_reasons_raw = self._check_raw_reject_reasons( ) self.available = self.available_lvm and self.available_raw self.rejected_reasons = list( set(self.rejected_reasons_lvm + self.rejected_reasons_raw)) self.device_id = self._get_device_id()
def test_dm_device_is_not_used(self, monkeypatch, tmpdir): # the link to the mapper is used instead monkeypatch.setattr(disk.lvm, 'is_lv', lambda: True) block_path, dev_path, mapper_path = self.setup_paths(tmpdir) dev_dm_path = os.path.join(dev_path, 'dm-0') ceph_data_path = os.path.join(mapper_path, 'ceph-data') os.symlink(dev_dm_path, ceph_data_path) block_dm_path = os.path.join(block_path, 'dm-0') os.makedirs(block_dm_path) result = disk.get_devices( _sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) result = list(result.keys()) assert len(result) == 1 assert result == [ceph_data_path]
def _parse(self): # start with lvm since it can use an absolute or relative path lv = lvm.get_lv_from_argument(self.path) if lv: self.lv_api = lv self.abspath = lv.lv_path else: dev = disk.lsblk(self.path) self.disk_api = dev device_type = dev.get('TYPE', '') # always check is this is an lvm member if device_type in ['part', 'disk']: self._set_lvm_membership() if not sys_info.devices: sys_info.devices = disk.get_devices() self.sys_api = sys_info.devices.get(self.abspath, {})
def _parse(self): # start with lvm since it can use an absolute or relative path lv = lvm.get_lv_from_argument(self.path) if lv: self.lv_api = lv self.abspath = lv.lv_path else: dev = disk.lsblk(self.path) self.disk_api = dev device_type = dev.get('TYPE', '') # always check is this is an lvm member if device_type in ['part', 'disk']: self._set_lvm_membership() if not sys_info.devices: sys_info.devices = disk.get_devices() self.sys_api = sys_info.devices.get(self.abspath, {})
def _parse(self): if not sys_info.devices: sys_info.devices = disk.get_devices() self.sys_api = sys_info.devices.get(self.abspath, {}) if not self.sys_api: # if no device was found check if we are a partition partname = self.abspath.split('/')[-1] for device, info in sys_info.devices.items(): part = info['partitions'].get(partname, {}) if part: self.sys_api = part break # if the path is not absolute, we have 'vg/lv', let's use LV name # to get the LV. if self.path[0] == '/': lv = lvm.get_single_lv(filters={'lv_path': self.path}) else: vgname, lvname = self.path.split('/') lv = lvm.get_single_lv(filters={'lv_name': lvname, 'vg_name': vgname}) if lv: self.lv_api = lv self.lvs = [lv] self.abspath = lv.lv_path self.vg_name = lv.vg_name self.lv_name = lv.name self.ceph_device = lvm.is_ceph_device(lv) else: dev = disk.lsblk(self.path) self.blkid_api = disk.blkid(self.path) self.disk_api = dev device_type = dev.get('TYPE', '') # always check is this is an lvm member if device_type in ['part', 'disk']: self._set_lvm_membership() out, err, rc = process.call([ 'ceph-bluestore-tool', 'show-label', '--dev', self.path], verbose_on_failure=False) if rc: self.ceph_device = True self.ceph_disk = CephDiskDevice(self)
def test_sda1_partition(self, tmpfile, tmpdir): block_path, dev_path, mapper_path = self.setup_paths(tmpdir) block_sda_path = os.path.join(block_path, 'sda') block_sda1_path = os.path.join(block_sda_path, 'sda1') block_sda1_holders = os.path.join(block_sda1_path, 'holders') dev_sda_path = os.path.join(dev_path, 'sda') dev_sda1_path = os.path.join(dev_path, 'sda1') os.makedirs(block_sda_path) os.makedirs(block_sda1_path) os.makedirs(dev_sda1_path) os.makedirs(block_sda1_holders) os.makedirs(dev_sda_path) tmpfile('size', '1024', directory=block_sda_path) tmpfile('partition', '1', directory=block_sda1_path) result = disk.get_devices(_sys_block_path=block_path, _dev_path=dev_path, _mapper_path=mapper_path) assert dev_sda_path in list(result.keys()) assert '/dev/sda1' in list(result.keys()) assert result['/dev/sda1']['holders'] == []
def _parse(self): if not sys_info.devices: sys_info.devices = disk.get_devices() self.sys_api = sys_info.devices.get(self.abspath, {}) if not self.sys_api: # if no device was found check if we are a partition partname = self.abspath.split('/')[-1] for device, info in sys_info.devices.items(): part = info['partitions'].get(partname, {}) if part: self.sys_api = part break # if the path is not absolute, we have 'vg/lv', let's use LV name # to get the LV. if self.path[0] == '/': lv = lvm.get_first_lv(filters={'lv_path': self.path}) else: vgname, lvname = self.path.split('/') lv = lvm.get_first_lv(filters={ 'lv_name': lvname, 'vg_name': vgname }) if lv: self.lv_api = lv self.lvs = [lv] self.abspath = lv.lv_path self.vg_name = lv.vg_name self.lv_name = lv.name else: dev = disk.lsblk(self.path) self.blkid_api = disk.blkid(self.path) self.disk_api = dev device_type = dev.get('TYPE', '') # always check is this is an lvm member if device_type in ['part', 'disk']: self._set_lvm_membership() self.ceph_disk = CephDiskDevice(self)
def __init__(self, devices=None): if not sys_info.devices: sys_info.devices = disk.get_devices() self.devices = [Device(k) for k in sys_info.devices.keys()]
def get_devices(self): # remove devices with partitions devices = [(device, details) for device, details in disk.get_devices().items() if details.get('partitions') == {}] size_sort = lambda x: (x[0], x[1]['size']) return device_formatter(sorted(devices, key=size_sort))
def test_no_devices_are_found(self, tmpdir): result = disk.get_devices( _sys_block_path=str(tmpdir), _dev_path=str(tmpdir), _mapper_path=str(tmpdir)) assert result == {}