Пример #1
0
 def test_get_lvm_info(self, mock_filter_lvm_info):
     """
     make sure that the get lvm info functions make the right calls to
     lvm._filter_lvm_info
     """
     lvm.get_pvols_in_volgroup(self.vg_name)
     mock_filter_lvm_info.assert_called_with('pvdisplay', 'vg_name',
                                             'pv_name', self.vg_name)
     lvm.get_lvols_in_volgroup(self.vg_name)
     mock_filter_lvm_info.assert_called_with('lvdisplay', 'vg_name',
                                             'lv_name', self.vg_name)
Пример #2
0
def _device_is_multipathed(devpath):
    devpath = os.path.realpath(devpath)
    info = udevadm_info(devpath)
    if multipath.is_mpath_device(devpath, info=info):
        return True
    if multipath.is_mpath_partition(devpath, info=info):
        return True

    if devpath.startswith('/dev/dm-'):
        # check members of composed devices (LVM, dm-crypt)
        if 'DM_LV_NAME' in info:
            volgroup = info.get('DM_VG_NAME')
            if volgroup:
                if any((multipath.is_mpath_member(pv)
                        for pv in lvm.get_pvols_in_volgroup(volgroup))):
                    return True

    elif devpath.startswith('/dev/md'):
        if any((multipath.is_mpath_member(md)
                for md in md_get_devices_list(devpath) +
                md_get_spares_list(devpath))):
            return True

    result = multipath.is_mpath_member(devpath)
    return result
Пример #3
0
def shutdown_lvm(device):
    """
    Shutdown specified lvm device.
    """
    device = block.sys_block_path(device)
    # lvm devices have a dm directory that containes a file 'name' containing
    # '{volume group}-{logical volume}'. The volume can be freed using lvremove
    name_file = os.path.join(device, 'dm', 'name')
    lvm_name = util.load_file(name_file).strip()
    (vg_name, lv_name) = lvm.split_lvm_name(lvm_name)
    vg_lv_name = "%s/%s" % (vg_name, lv_name)
    devname = "/dev/" + vg_lv_name

    # wipe contents of the logical volume first
    LOG.info('Wiping lvm logical volume: %s', devname)
    block.quick_zero(devname, partitions=False)

    # remove the logical volume
    LOG.debug('using "lvremove" on %s', vg_lv_name)
    util.subp(['lvremove', '--force', '--force', vg_lv_name])

    # if that was the last lvol in the volgroup, get rid of volgroup
    if len(lvm.get_lvols_in_volgroup(vg_name)) == 0:
        pvols = lvm.get_pvols_in_volgroup(vg_name)
        util.subp(['vgremove', '--force', '--force', vg_name], rcs=[0, 5])

        # wipe the underlying physical volumes
        for pv in pvols:
            LOG.info('Wiping lvm physical volume: %s', pv)
            block.quick_zero(pv, partitions=False)

    # refresh lvmetad
    lvm.lvm_scan()