def create_lvm_pool(spool, pool_name, block_device, vg_name="vg_v2v", target_path="/dev/vg_v2v"): """ Create a persistent lvm pool. """ # Check pool before creating if spool.pool_exists(pool_name): logging.debug("Pool '%s' already exists.", pool_name) return False if not spool.define_lvm_pool( pool_name, block_device, vg_name=vg_name, target_path=target_path): return False vgroups = lv_utils.vg_list() if vg_name not in vgroups.keys() and not spool.build_pool(pool_name): return False # To verify if volume group has been set. try: lv_utils.lv_create(vg_name, "v2v_sample", "10M", True) lv_utils.lv_remove(vg_name, "v2v_sample") except (error.TestError, error.CmdError), detail: logging.error("Check volume group failed:\n%s", str(detail)) return False
def create_lvm_pool(spool, pool_name, block_device, vg_name="vg_v2v", target_path="/dev/vg_v2v"): """ Create a persistent lvm pool. """ # Check pool before creating if spool.pool_exists(pool_name): logging.debug("Pool '%s' already exists.", pool_name) return False if not spool.define_lvm_pool(pool_name, block_device, vg_name=vg_name, target_path=target_path): return False vgroups = lv_utils.vg_list() if vg_name not in vgroups.keys() and not spool.build_pool(pool_name): return False # To verify if volume group has been set. try: lv_utils.lv_create(vg_name, "v2v_sample", "10M", True) lv_utils.lv_remove(vg_name, "v2v_sample") except (error.TestError, error.CmdError), detail: logging.error("Check volume group failed:\n%s", str(detail)) return False
def run_once( self, vg_name="autotest_vg", lv_name="autotest_lv", lv_size="1G", lv_snapshot_name="autotest_sn", lv_snapshot_size="1G", # size in MB ramdisk_vg_size="40000", ramdisk_basedir="/tmp", ramdisk_sparse_filename="virtual_hdd", override_flag=0, ): """ General logical volume setup. The main part of the lvm setup checks whether the provided volume group exists and if not, creates one from the ramdisk. It then creates a logical volume if there is no logical volume, takes a snapshot from the logical if there is logical volume but no snapshot, and merges with the snapshot if both the snapshot and the logical volume are present. @param vg_name: Name of the volume group. @param lv_name: Name of the logical volume. @param lv_size: Size of the logical volume as string in the form "#G" (for example 30G). @param lv_snapshot_name: Name of the snapshot with origin the logical volume. @param lv_snapshot_size: Size of the snapshot with origin the logical volume also as "#G". @param override_flag: Flag to override default policy. Override flag can be set to -1 to force remove, 1 to force create, and 0 for default policy. """ # if no virtual group is defined create one based on ramdisk if not lv_utils.vg_check(vg_name): lv_utils.vg_ramdisk(vg_name, ramdisk_vg_size, ramdisk_basedir, ramdisk_sparse_filename) # if no snapshot is defined start fresh logical volume if override_flag == 1 and lv_utils.lv_check(vg_name, lv_name): lv_utils.lv_remove(vg_name, lv_name) lv_utils.lv_create(vg_name, lv_name, lv_size) elif override_flag == -1 and lv_utils.lv_check(vg_name, lv_name): lv_utils.lv_remove(vg_name, lv_name) else: # perform normal check policy if lv_utils.lv_check(vg_name, lv_snapshot_name) and lv_utils.lv_check(vg_name, lv_name): lv_utils.lv_revert(vg_name, lv_name, lv_snapshot_name) lv_utils.lv_take_snapshot(vg_name, lv_name, lv_snapshot_name, lv_snapshot_size) elif lv_utils.lv_check(vg_name, lv_snapshot_name) and not lv_utils.lv_check(vg_name, lv_name): raise error.TestError("Snapshot origin not found") elif not lv_utils.lv_check(vg_name, lv_snapshot_name) and lv_utils.lv_check(vg_name, lv_name): lv_utils.lv_take_snapshot(vg_name, lv_name, lv_snapshot_name, lv_snapshot_size) else: lv_utils.lv_create(vg_name, lv_name, lv_size)
def delete_local_disk(disk_type, path=None, vgname=None, lvname=None): if disk_type in ["file", "floppy", "iso"]: if path is None: raise error.TestError("Path is needed for deleting local disk") else: cmd = "rm -f %s" % path utils.run(cmd, ignore_status=True) elif disk_type == "lvm": if vgname is None or lvname is None: raise error.TestError("Both VG name and LV name needed") lv_utils.lv_remove(vgname, lvname) else: raise error.TestError("Unknown disk type %s" % disk_type)
af_fstrim_cpy = get_disk_capacity(disk_type, imagefile=device_path, lvname="lvthin") logging.debug("\nBefore occupying disk:%s\n" "After occupied disk:%s\n" "After fstrim operation:%s", bf_cpy, bf_fstrim_cpy, af_fstrim_cpy) # Check results if fstrim_type in ["fstrim_cmd", "qemu-guest-agent"]: if not sig_delta(bf_fstrim_cpy, af_fstrim_cpy) and \ not status_error: raise error.TestFail("Manual 'fstrims' didn't work.") elif fstrim_type == "mount_with_discard": if sig_delta(bf_cpy, bf_fstrim_cpy) and not status_error: raise error.TestFail("Automatical 'fstrims' didn't work.") finally: if new_vm.is_alive(): new_vm.destroy() new_vm.undefine() if disk_type == "block": try: lv_utils.lv_remove("vgthin", "lvthin") except error.TestError, detail: logging.debug(str(detail)) try: lv_utils.vg_remove("vgthin") except error.TestError, detail: logging.debug(str(detail)) utils.run("pvremove -f %s" % discard_device, ignore_status=True) if create_iscsi: utlv.setup_or_cleanup_iscsi(is_setup=False)
def run_once( self, vg_name='autotest_vg', lv_name='autotest_lv', lv_size='1G', lv_snapshot_name='autotest_sn', lv_snapshot_size='1G', # size in MB ramdisk_vg_size="40000", ramdisk_basedir="/tmp", ramdisk_sparse_filename="virtual_hdd", override_flag=0): """ General logical volume setup. The main part of the lvm setup checks whether the provided volume group exists and if not, creates one from the ramdisk. It then creates a logical volume if there is no logical volume, takes a snapshot from the logical if there is logical volume but no snapshot, and merges with the snapshot if both the snapshot and the logical volume are present. @param vg_name: Name of the volume group. @param lv_name: Name of the logical volume. @param lv_size: Size of the logical volume as string in the form "#G" (for example 30G). @param lv_snapshot_name: Name of the snapshot with origin the logical volume. @param lv_snapshot_size: Size of the snapshot with origin the logical volume also as "#G". @param override_flag: Flag to override default policy. Override flag can be set to -1 to force remove, 1 to force create, and 0 for default policy. """ # if no virtual group is defined create one based on ramdisk if not lv_utils.vg_check(vg_name): lv_utils.vg_ramdisk(vg_name, ramdisk_vg_size, ramdisk_basedir, ramdisk_sparse_filename) # if no snapshot is defined start fresh logical volume if override_flag == 1 and lv_utils.lv_check(vg_name, lv_name): lv_utils.lv_remove(vg_name, lv_name) lv_utils.lv_create(vg_name, lv_name, lv_size) elif override_flag == -1 and lv_utils.lv_check(vg_name, lv_name): lv_utils.lv_remove(vg_name, lv_name) else: # perform normal check policy if (lv_utils.lv_check(vg_name, lv_snapshot_name) and lv_utils.lv_check(vg_name, lv_name)): lv_utils.lv_revert(vg_name, lv_name, lv_snapshot_name) lv_utils.lv_take_snapshot(vg_name, lv_name, lv_snapshot_name, lv_snapshot_size) elif (lv_utils.lv_check(vg_name, lv_snapshot_name) and not lv_utils.lv_check(vg_name, lv_name)): raise error.TestError("Snapshot origin not found") elif (not lv_utils.lv_check(vg_name, lv_snapshot_name) and lv_utils.lv_check(vg_name, lv_name)): lv_utils.lv_take_snapshot(vg_name, lv_name, lv_snapshot_name, lv_snapshot_size) else: lv_utils.lv_create(vg_name, lv_name, lv_size)
imagefile=device_path, lvname="lvthin") logging.debug( "\nBefore occupying disk:%s\n" "After occupied disk:%s\n" "After fstrim operation:%s", bf_cpy, bf_fstrim_cpy, af_fstrim_cpy) # Check results if fstrim_type in ["fstrim_cmd", "qemu-guest-agent"]: if not sig_delta(bf_fstrim_cpy, af_fstrim_cpy) and \ not status_error: raise error.TestFail("Manual 'fstrims' didn't work.") elif fstrim_type == "mount_with_discard": if sig_delta(bf_cpy, bf_fstrim_cpy) and not status_error: raise error.TestFail("Automatical 'fstrims' didn't work.") finally: if new_vm.is_alive(): new_vm.destroy() new_vm.undefine() if disk_type == "block": try: lv_utils.lv_remove("vgthin", "lvthin") except error.TestError, detail: logging.debug(str(detail)) try: lv_utils.vg_remove("vgthin") except error.TestError, detail: logging.debug(str(detail)) utils.run("pvremove -f %s" % discard_device, ignore_status=True) if create_iscsi: utlv.setup_or_cleanup_iscsi(is_setup=False)