def test_list_logical_volumes_path_mode(self):
     with patch(STORAGE_LINUX_LVM + '.check_output') as check_output:
         check_output.return_value = LVS_WITH_VG
         self.assertEqual(lvm.list_logical_volumes(path_mode=True), [
             'cinder-volumes/cinder-volumes-pool', 'cinder-volumes/testvol',
             'cinder-volumes/volume-48be6ba0-84c3-4b8d-9be5-e68e47fc7682',
             'cinder-volumes/volume-f8c1d2fd-1fa1-4d84-b4e0-431dba7d582e'
         ])
         check_output.assert_called_with(
             ['lvs', '--options', 'vg_name,lv_name', '--noheadings'])
 def test_list_logical_volumes_select_criteria(self):
     with patch(STORAGE_LINUX_LVM + '.check_output') as check_output:
         check_output.return_value = LVS_THIN_POOLS
         self.assertEqual(
             lvm.list_logical_volumes(select_criteria='lv_attr =~ ^t'),
             ['cinder-volumes-pool'])
         check_output.assert_called_with([
             'lvs', '--options', 'lv_name', '--noheadings', '--select',
             'lv_attr =~ ^t'
         ])
Esempio n. 3
0
def manage_lvm(device, dirname):
    """Add the device to the VG corresponding to the dirname.

    In this case, logical volume name will be dirname with /
    replaced by _ symbols. If logical volume already exists,
    then, device is added as a new physical device and the entire
    logical volume is resized.

    If logical volume name does not exist, then prepare the
    physical device and add to the newly created volume.
    """
    lv_name = "lvm" + dirname.replace("/", "_")
    vg_name = "vg" + dirname.replace("/", "_")
    pv = device
    try:
        if list_lvm_volume_group(device):
            # PV already used, raise this as an issue
            pv = None
    except subprocess.CalledProcessError:
        # Device does not exist in the list, continue
        pass
    if not pv:
        raise DiskMapHelperPVAlreadyTakenForLVM(device, lv_name)
    if not is_lvm_physical_volume(device):
        # This is not a PV yet, create one
        create_lvm_physical_volume(device)
    if lv_name not in list_logical_volumes():
        # lv_name is always associated 1:1 with vg_name
        # If one does not exist, so we need to create both.
        create_lvm_volume_group(vg_name, pv)
        create_logical_volume(lv_name, vg_name)
    else:
        # Now extend the lv_name:
        extend_logical_volume_by_device(lv_name, pv)
        # TODO: find FS already present and resize it as well
    return "/dev/{}/{}".format(vg_name, lv_name)
Esempio n. 4
0
 def test_list_logical_volumes_empty(self):
     with patch(STORAGE_LINUX_LVM + '.check_output') as check_output:
         check_output.return_value = b''
         self.assertEqual(lvm.list_logical_volumes(), [])