def create_report(self, lvs): """ Create a report for LVM dev(s) passed. Returns '{}' to denote failure. """ report = {} pvs = api.get_pvs() for lv in lvs: if not api.is_ceph_device(lv): continue osd_id = lv.tags['ceph.osd_id'] report.setdefault(osd_id, []) lv_report = lv.as_dict() lv_report['devices'] = [ pv.name for pv in pvs if pv.lv_uuid == lv.lv_uuid ] if pvs else [] report[osd_id].append(lv_report) phys_devs = self.create_report_non_lv_device(lv) if phys_devs: report[osd_id].append(phys_devs) return report
def test_get_pvs_single_pv(self, monkeypatch): pv1 = api.PVolume(pv_name='/dev/sda', pv_uuid='0000', pv_tags={}, vg_name='vg1') pvs = [pv1] stdout = ['{};;;;;;'.format(pv1.pv_name)] monkeypatch.setattr(api.process, 'call', lambda x,**kw: (stdout, '', 0)) pvs_ = api.get_pvs() assert len(pvs_) == 1 assert pvs_[0].pv_name == pvs[0].pv_name
def test_get_pvs(self, monkeypatch): pv1 = api.PVolume(pv_name='/dev/sda', pv_uuid='0000', pv_tags={}, vg_name='vg1') pv2 = api.PVolume(pv_name='/dev/sdb', pv_uuid='0001', pv_tags={}, vg_name='vg2') pvs = [pv1, pv2] stdout = ['{};{};{};{};;'.format(pv1.pv_name, pv1.pv_tags, pv1.pv_uuid, pv1.vg_name), '{};{};{};{};;'.format(pv2.pv_name, pv2.pv_tags, pv2.pv_uuid, pv2.vg_name)] monkeypatch.setattr(api.process, 'call', lambda x,**kw: (stdout, '', 0)) pvs_ = api.get_pvs() assert len(pvs_) == len(pvs) for pv, pv_ in zip(pvs, pvs_): assert pv_.pv_name == pv.pv_name
def create_report(self, lvs, full_report=True, arg_is_vg=False): """ Create a report for LVM dev(s) passed. Returns '{}' to denote failure. """ if not lvs: return {} def create_report_for_nonlv_device(): # bluestore will not have a journal, filestore will not have # a block/wal/db, so we must skip if not present if dev_type == 'data': return device_uuid = lv.tags.get('ceph.%s_uuid' % dev_type) pv = api.get_first_pv(filters={'vg_name': lv.vg_name}) if device_uuid and pv: report[osd_id].append({'tags': {'PARTUUID': device_uuid}, 'type': dev_type, 'path': pv.pv_name}) report = {} lvs = [lvs] if isinstance(lvs, api.Volume) else lvs for lv in lvs: if not api.is_ceph_device(lv): continue osd_id = lv.tags['ceph.osd_id'] report.setdefault(osd_id, []) lv_report = lv.as_dict() dev_type = lv.tags.get('ceph.type', None) if dev_type != 'journal' or (dev_type == 'journal' and full_report): pvs = api.get_pvs(filters={'lv_uuid': lv.lv_uuid}) lv_report['devices'] = [pv.name for pv in pvs] if pvs else [] report[osd_id].append(lv_report) if arg_is_vg or dev_type in ['journal', 'wal']: create_report_for_nonlv_device() return report
def test_get_pvs_empty(self, monkeypatch): monkeypatch.setattr(api.process, 'call', lambda x,**kw: ('', '', 0)) assert api.get_pvs() == []