Beispiel #1
0
    def _get_image_filename(img_name,
                            enable_gluster=False,
                            enable_nvme=False,
                            img_fmt=None):
        """
        Generate an image path.

        :param image_name: Force name of image.
        :param enable_gluster: Enable gluster or not.
        :param enable_nvme: Enable nvme or not.
        :param image_format: Format for image.
        """
        if enable_gluster:
            gluster_uri = gluster.create_gluster_uri(params)
            image_filename = "%s%s" % (gluster_uri, img_name)
            if img_fmt:
                image_filename += ".%s" % img_fmt
        elif enable_nvme:
            image_filename = image_name
        else:
            if img_fmt:
                img_name = "%s.%s" % (img_name, img_fmt)
            image_filename = utils_misc.get_path(data_dir.get_data_dir(),
                                                 img_name)
        return image_filename
Beispiel #2
0
    def create_iso_image(params, name, prepare=True, file_size=None):
        """
        Creates 'new' iso image with one file on it

        :param params: parameters for test
        :param name: name of new iso image file
        :param preapre: if True then it prepare cd images.
        :param file_size: Size of iso image in MB

        :return: path to new iso image file.
        """
        error_context.context("Creating test iso image '%s'" % name,
                              logging.info)
        cdrom_cd = params["target_cdrom"]
        cdrom_cd = params[cdrom_cd]
        if not os.path.isabs(cdrom_cd):
            cdrom_cd = utils_misc.get_path(data_dir.get_data_dir(), cdrom_cd)
        iso_image_dir = os.path.dirname(cdrom_cd)
        if file_size is None:
            file_size = 10
        g_mount_point = tempfile.mkdtemp("gluster")
        image_params = params.object_params(name)
        if image_params.get("enable_gluster") == "yes":
            if params.get("gluster_server"):
                gluster_server = params.get("gluster_server")
            else:
                gluster_server = "localhost"
            volume_name = params["gluster_volume_name"]
            g_mount_link = "%s:/%s" % (gluster_server, volume_name)
            mount_cmd = "mount -t glusterfs %s %s" % (g_mount_link,
                                                      g_mount_point)
            process.system(mount_cmd, timeout=60)
            file_name = os.path.join(g_mount_point, "%s.iso" % name)
        else:
            file_name = utils_misc.get_path(iso_image_dir, "%s.iso" % name)
        if prepare:
            cmd = "dd if=/dev/urandom of=%s bs=1M count=%d"
            process.run(cmd % (name, file_size))
            process.run("mkisofs -o %s %s" % (file_name, name))
            process.run("rm -rf %s" % (name))
        if image_params.get("enable_gluster") == "yes":
            gluster_uri = gluster.create_gluster_uri(image_params)
            file_name = "%s%s.iso" % (gluster_uri, name)
            try:
                umount_cmd = "umount %s" % g_mount_point
                process.system(umount_cmd, timeout=60)
                os.rmdir(g_mount_point)
            except Exception as err:
                msg = "Fail to clean up %s" % g_mount_point
                msg += "Error message %s" % err
                logging.warn(msg)
        return file_name
Beispiel #3
0
    def create_iso_image(params, name, prepare=True, file_size=None):
        """
        Creates 'new' iso image with one file on it

        :param params: parameters for test
        :param name: name of new iso image file
        :param preapre: if True then it prepare cd images.
        :param file_size: Size of iso image in MB

        :return: path to new iso image file.
        """
        error_context.context("Creating test iso image '%s'" % name,
                              logging.info)
        cdrom_cd = params["target_cdrom"]
        cdrom_cd = params[cdrom_cd]
        if not os.path.isabs(cdrom_cd):
            cdrom_cd = utils_misc.get_path(data_dir.get_data_dir(), cdrom_cd)
        iso_image_dir = os.path.dirname(cdrom_cd)
        if file_size is None:
            file_size = 10
        g_mount_point = tempfile.mkdtemp("gluster")
        image_params = params.object_params(name)
        if image_params.get("enable_gluster") == "yes":
            if params.get("gluster_server"):
                gluster_server = params.get("gluster_server")
            else:
                gluster_server = "localhost"
            volume_name = params["gluster_volume_name"]
            g_mount_link = "%s:/%s" % (gluster_server, volume_name)
            mount_cmd = "mount -t glusterfs %s %s" % (g_mount_link, g_mount_point)
            process.system(mount_cmd, timeout=60)
            file_name = os.path.join(g_mount_point, "%s.iso" % name)
        else:
            file_name = utils_misc.get_path(iso_image_dir, "%s.iso" % name)
        if prepare:
            cmd = "dd if=/dev/urandom of=%s bs=1M count=%d"
            process.run(cmd % (name, file_size))
            process.run("mkisofs -o %s %s" % (file_name, name))
            process.run("rm -rf %s" % (name))
        if image_params.get("enable_gluster") == "yes":
            gluster_uri = gluster.create_gluster_uri(image_params)
            file_name = "%s%s.iso" % (gluster_uri, name)
            try:
                umount_cmd = "umount %s" % g_mount_point
                process.system(umount_cmd, timeout=60)
                os.rmdir(g_mount_point)
            except Exception as err:
                msg = "Fail to clean up %s" % g_mount_point
                msg += "Error message %s" % err
                logging.warn(msg)
        return file_name
Beispiel #4
0
    def _get_image_filename(img_name, enable_gluster=False, img_fmt=None):
        """
        Generate an image path.

        :param image_name: Force name of image.
        :param enable_gluster: Enable gluster or not.
        :param image_format: Format for image.
        """
        if enable_gluster:
            gluster_uri = gluster.create_gluster_uri(params)
            image_filename = "%s%s" % (gluster_uri, img_name)
            if img_fmt:
                image_filename += ".%s" % img_fmt
        else:
            if img_fmt:
                img_name = "%s.%s" % (img_name, img_fmt)
            image_filename = utils_misc.get_path(data_dir.get_data_dir(), img_name)
        return image_filename
Beispiel #5
0
 def backup_img_chain(image_file):
     """
     Backup whole image in a image chain;
     """
     mount_point = tempfile.mkdtemp(dir=test.resultsdir)
     qemu_img = utils_misc.get_qemu_img_binary(params)
     if enable_gluster:
         g_uri = gluster.create_gluster_uri(params)
         gluster.glusterfs_mount(g_uri, mount_point)
         image_name = os.path.basename(image_file)
         image_file = os.path.join(mount_point, image_name)
     logging.warn("backup %s to %s" % (image_file, test.resultsdir))
     shutil.copy(image_file, test.resultsdir)
     backing_file = _info(qemu_img, image_file, "backing file", None)
     if backing_file:
         backup_img_chain(backing_file)
     elif enable_gluster:
         utils_misc.umount(g_uri, mount_point, "glusterfs", False, "fuse.glusterfs")
         shutil.rmtree(mount_point)
     return None
Beispiel #6
0
 def backup_img_chain(image_file):
     """
     Backup whole image in a image chain;
     """
     mount_point = tempfile.mkdtemp(dir=test.resultsdir)
     qemu_img = utils_misc.get_qemu_img_binary(params)
     if enable_gluster:
         g_uri = gluster.create_gluster_uri(params)
         gluster.glusterfs_mount(g_uri, mount_point)
         image_name = os.path.basename(image_file)
         image_file = os.path.join(mount_point, image_name)
     logging.warn("backup %s to %s" % (image_file, test.resultsdir))
     shutil.copy(image_file, test.resultsdir)
     backing_file = _info(qemu_img, image_file, "backing file", None)
     if backing_file:
         backup_img_chain(backing_file)
     elif enable_gluster:
         utils_misc.umount(g_uri, mount_point, "glusterfs", False,
                           "fuse.glusterfs")
         shutil.rmtree(mount_point)
     return None