def single_report(self, device): """ Generate a report for a single device. This can be either a logical volume in the form of vg/lv or a device with an absolute path like /dev/sda1 or /dev/sda. Returns '{}' to denote failure. """ lv = api.get_first_lv(filters={'lv_path': device}) # whether the dev to reported is lv... arg_is_vg = False # The `device` argument can be a logical volume name or a device path. # If it's a path that exists, use the canonical path (in particular, # dereference symlinks); otherwise, assume it's a logical volume name # and use it as-is. if os.path.exists(device): device = os.path.realpath(device) lv = api.get_first_lv(filters={'lv_path': device}) if not lv: # if device at given path is not LV, it might be PV... pv = api.get_first_pv(filters={'pv_name': device}) if pv: lv = api.get_first_lv(filters={'vg_name': pv.vg_name}) # or VG. else: vg_name = os.path.dirname(device) lv = api.get_first_lv(filters={'vg_name': vg_name}) arg_is_vg = True if not lv: return {} return self.create_report(lv, full_report=False, arg_is_vg=arg_is_vg)
def test_get_first_pv_single_pv(self, monkeypatch): pv = api.PVolume(pv_name='/dev/sda', pv_uuid='0000', pv_tags={}, vg_name='vg1') stdout = ['{};;;;;;'.format(pv.pv_name)] monkeypatch.setattr(api.process, 'call', lambda x,**kw: (stdout, '', 0)) pv_ = api.get_first_pv() assert isinstance(pv_, api.PVolume) assert pv_.pv_name == pv.pv_name
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})
def test_get_first_pv_empty(self, monkeypatch): monkeypatch.setattr(api.process, 'call', lambda x,**kw: ('', '', 0)) assert api.get_first_pv() == []