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
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
def create_or_clean_backend_dir(g_uri, params, session=None, is_clean=False): """ Create/cleanup backend directory :params g_uri: glusterfs uri :params params: the parameters to be checked :params session: VM/remote session object :params is_cleanup: True for cleanup backend directory; False for create one. :return: gluster_img if is_clean is equal to True """ mount_point = params.get("gluster_mount_dir") is_symlink = params.get("gluster_create_symlink") == "yes" symlink_name = params.get("gluster_symlink") gluster_img = None if not is_clean: if not utils_misc.check_exists(mount_point, session): utils_misc.make_dirs(mount_point, session) if gluster.glusterfs_is_mounted(mount_point, session): gluster.glusterfs_umount(g_uri, mount_point, session) gluster.glusterfs_mount(g_uri, mount_point, session) gluster_img = os.path.join(mount_point, disk_img) if is_symlink: utils_misc.make_symlink(mount_point, symlink_name) utils_misc.make_symlink(mount_point, symlink_name, remote_session) gluster_img = os.path.join(symlink_name, disk_img) return gluster_img else: if is_symlink: utils_misc.rm_link(symlink_name, session) gluster.glusterfs_umount(g_uri, mount_point, session) if utils_misc.check_exists(mount_point, session): utils_misc.safe_rmdir(gluster_mount_dir, session=session)