Esempio n. 1
0
def get_image_filename(params, root_dir):
    """
    Generate an image path from params and root_dir.

    :param params: Dictionary containing the test parameters.
    :param root_dir: Base directory for relative filenames.
    :param image_name: Force name of image.
    :param image_format: Format for image.

    :note: params should contain:
           image_name -- the name of the image file, without extension
           image_format -- the format of the image (qcow2, raw etc)
    :raise VMDeviceError: When no matching disk found (in indirect method).
    """
    enable_gluster = params.get("enable_gluster", "no") == "yes"
    enable_ceph = params.get("enable_ceph", "no") == "yes"
    image_name = params.get("image_name")
    if image_name:
        if enable_gluster:
            image_name = params.get("image_name", "image")
            image_format = params.get("image_format", "qcow2")
            return gluster.get_image_filename(params, image_name, image_format)
        if enable_ceph:
            image_format = params.get("image_format", "qcow2")
            ceph_monitor = params["ceph_monitor"]
            rbd_pool_name = params["rbd_pool_name"]
            rbd_image_name = "%s.%s" % (image_name.split("/")[-1],
                                        image_format)
            return ceph.get_image_filename(ceph_monitor, rbd_pool_name,
                                           rbd_image_name)
        return get_image_filename_filesytem(params, root_dir)
    else:
        logging.warn("image_name parameter not set.")
Esempio n. 2
0
def get_image_filename(params, root_dir):
    """
    Generate an image path from params and root_dir.

    :param params: Dictionary containing the test parameters.
    :param root_dir: Base directory for relative filenames.
    :param image_name: Force name of image.
    :param image_format: Format for image.

    :note: params should contain:
           image_name -- the name of the image file, without extension
           image_format -- the format of the image (qcow2, raw etc)
    :raise VMDeviceError: When no matching disk found (in indirect method).
    """
    enable_gluster = params.get("enable_gluster", "no") == "yes"
    image_name = params.get("image_name")
    if image_name:
        if enable_gluster:
            image_name = params.get("image_name", "image")
            image_format = params.get("image_format", "qcow2")
            return gluster.get_image_filename(params, image_name, image_format)

        return get_image_filename_filesytem(params, root_dir)
    else:
        logging.warn("image_name parameter not set.")
Esempio n. 3
0
def get_image_filename(params, root_dir):
    """
    Generate an image path from params and root_dir.

    :param params: Dictionary containing the test parameters.
    :param root_dir: Base directory for relative filenames.
    :param image_name: Force name of image.
    :param image_format: Format for image.

    :note: params should contain:
           image_name -- the name of the image file, without extension
           image_format -- the format of the image (qcow2, raw etc)
    :raise VMDeviceError: When no matching disk found (in indirect method).
    """
    enable_gluster = params.get("enable_gluster", "no") == "yes"
    if enable_gluster:
        image_name = params.get("image_name", "image")
        image_format = params.get("image_format", "qcow2")
        return gluster.get_image_filename(params, image_name, image_format)

    return get_image_filename_filesytem(params, root_dir)
Esempio n. 4
0
def get_image_filename(params, root_dir):
    """
    Generate an image path from params and root_dir.

    :param params: Dictionary containing the test parameters.
    :param root_dir: Base directory for relative filenames.

    :note: params should contain:
           image_name -- the name of the image file, without extension
           image_format -- the format of the image (qcow2, raw etc)
    :raise VMDeviceError: When no matching disk found (in indirect method).
    """
    def sort_cmp(first, second):
        """
        This function used for sort to suit for this test, first sort by len
        then by value.
        """
        first_contains_digit = re.findall(r'[vhs]d[a-z]*[\d]+', first)
        second_contains_digit = re.findall(r'[vhs]d[a-z]*[\d]+', second)

        if not first_contains_digit and not second_contains_digit:
            if len(first) > len(second):
                return 1
            elif len(first) < len(second):
                return -1
        if len(first) == len(second):
            if first_contains_digit and second_contains_digit:
                return cmp(first, second)
            elif first_contains_digit:
                return -1
            elif second_contains_digit:
                return 1
        return cmp(first, second)

    image_name = params.get("image_name", "image")
    indirect_image_select = params.get("indirect_image_select")
    if indirect_image_select:
        re_name = image_name
        indirect_image_select = int(indirect_image_select)
        matching_images = utils.system_output("ls -1d %s" % re_name)
        matching_images = sorted(matching_images.split('\n'), cmp=sort_cmp)
        if matching_images[-1] == '':
            matching_images = matching_images[:-1]
        try:
            image_name = matching_images[indirect_image_select]
        except IndexError:
            raise virt_vm.VMDeviceError("No matching disk found for "
                                        "name = '%s', matching = '%s' and "
                                        "selector = '%s'" %
                                        (re_name, matching_images,
                                         indirect_image_select))
        for protected in params.get('indirect_image_blacklist', '').split(' '):
            match_image = re.match(protected, image_name)
            if match_image and match_image.group(0) == image_name:
                # We just need raise an error if it is totally match, such as
                # sda sda1 and so on, but sdaa should not raise an error.
                raise virt_vm.VMDeviceError("Matching disk is in blacklist. "
                                            "name = '%s', matching = '%s' and "
                                            "selector = '%s'" %
                                            (re_name, matching_images,
                                             indirect_image_select))
    image_format = params.get("image_format", "qcow2")
    gluster_image = params.get("gluster_brick")
    if params.get("image_raw_device") == "yes":
        return image_name
    if image_format:
        image_filename = "%s.%s" % (image_name, image_format)
    else:
        image_filename = image_name
    if gluster_image:
        image_filename = gluster.get_image_filename(params, image_name,
                                                    image_format)
    else:
        image_filename = utils_misc.get_path(root_dir, image_filename)
    return image_filename
Esempio n. 5
0
def get_image_filename(params, root_dir):
    """
    Generate an image path from params and root_dir.

    @param params: Dictionary containing the test parameters.
    @param root_dir: Base directory for relative filenames.

    @note: params should contain:
           image_name -- the name of the image file, without extension
           image_format -- the format of the image (qcow2, raw etc)
    @raise VMDeviceError: When no matching disk found (in indirect method).
    """
    def sort_cmp(first, second):
        """
        This function used for sort to suit for this test, first sort by len
        then by value.
        """
        first_contains_digit = re.findall(r'[vhs]d[a-z]*[\d]+', first)
        second_contains_digit = re.findall(r'[vhs]d[a-z]*[\d]+', second)

        if not first_contains_digit and not second_contains_digit:
            if len(first) > len(second):
                return 1
            elif len(first) < len(second):
                return -1
        if len(first) == len(second):
            if first_contains_digit and second_contains_digit:
                return cmp(first, second)
            elif first_contains_digit:
                return -1
            elif second_contains_digit:
                return 1
        return cmp(first, second)

    image_name = params.get("image_name", "image")
    indirect_image_select = params.get("indirect_image_select")
    if indirect_image_select:
        re_name = image_name
        indirect_image_select = int(indirect_image_select)
        matching_images = utils.system_output("ls -1d %s" % re_name)
        matching_images = sorted(matching_images.split('\n'), cmp=sort_cmp)
        if matching_images[-1] == '':
            matching_images = matching_images[:-1]
        try:
            image_name = matching_images[indirect_image_select]
        except IndexError:
            raise virt_vm.VMDeviceError(
                "No matching disk found for "
                "name = '%s', matching = '%s' and "
                "selector = '%s'" %
                (re_name, matching_images, indirect_image_select))
        for protected in params.get('indirect_image_blacklist', '').split(' '):
            match_image = re.match(protected, image_name)
            if match_image and match_image.group(0) == image_name:
                # We just need raise an error if it is totally match, such as
                # sda sda1 and so on, but sdaa should not raise an error.
                raise virt_vm.VMDeviceError(
                    "Matching disk is in blacklist. "
                    "name = '%s', matching = '%s' and "
                    "selector = '%s'" %
                    (re_name, matching_images, indirect_image_select))
    image_format = params.get("image_format", "qcow2")
    gluster_image = params.get("gluster_brick")
    if params.get("image_raw_device") == "yes":
        return image_name
    if image_format:
        image_filename = "%s.%s" % (image_name, image_format)
    else:
        image_filename = image_name
    if gluster_image:
        image_filename = gluster.get_image_filename(params, image_name,
                                                    image_format)
    else:
        image_filename = utils_misc.get_path(root_dir, image_filename)
    return image_filename