Exemple #1
0
def create_local_disk(disk_type, path=None,
                      size="10", disk_format="raw",
                      vgname=None, lvname=None):
    if disk_type != "lvm" and path is None:
        raise error.TestError("Path is needed for creating local disk")
    if path:
        utils.run("mkdir -p %s" % os.path.dirname(path))
    try:
        size = str(float(size)) + "G"
    except ValueError:
        pass
    cmd = ""
    if disk_type == "file":
        cmd = "qemu-img create -f %s %s %s" % (disk_format, path, size)
    elif disk_type == "floppy":
        cmd = "dd if=/dev/zero of=%s count=1024 bs=1024" % path
    elif disk_type == "iso":
        cmd = "mkisofs -o %s /root/*.*" % path
    elif disk_type == "lvm":
        if vgname is None or lvname is None:
            raise error.TestError("Both VG name and LV name are needed")
        lv_utils.lv_create(vgname, lvname, size)
        path = "/dev/%s/%s" % (vgname, lvname)
    else:
        raise error.TestError("Unknown disk type %s" % disk_type)
    if cmd:
        utils.run(cmd, ignore_status=True)
    return path
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)
Exemple #5
0
    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)