Esempio n. 1
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()
Esempio n. 2
0
 def test_split_lvm_name(self, mock_util):
     """
     make sure that split_lvm_name makes the right call to dmsetup splitname
     """
     lv_name = 'root_lvol'
     full_name = '{}-{}'.format(self.vg_name, lv_name)
     mock_util.subp.return_value = ('  {vg_name}{sep}{lv_name} '.format(
         vg_name=self.vg_name, lv_name=lv_name, sep=lvm._SEP), '')
     (res_vg_name, res_lv_name) = lvm.split_lvm_name(full_name)
     self.assertEqual(res_vg_name, self.vg_name)
     self.assertEqual(res_lv_name, lv_name)
     mock_util.subp.assert_called_with([
         'dmsetup', 'splitname', full_name, '-c', '--noheadings',
         '--separator', lvm._SEP, '-o', 'vg_name,lv_name'
     ],
                                       capture=True)