def preprocess_image(test, params, image_name): """ Preprocess a single QEMU image according to the instructions in params. @param test: Autotest test object. @param params: A dict containing image preprocessing parameters. @note: Currently this function just creates an image if requested. """ if params.get("storage_type") == "iscsi": iscsidev = kvm_storage.Iscsidev(params, test.bindir, image_name) params["image_name"] = iscsidev.setup() else: image_filename = virt_storage.get_image_filename(params, test.bindir) create_image = False if params.get("force_create_image") == "yes": logging.debug("Param 'force_create_image' specified, creating image") create_image = True elif (params.get("create_image") == "yes" and not os.path.exists(image_filename)): create_image = True if create_image: image = kvm_storage.QemuImg(params, test.bindir, image_name) if not image.create(params): raise error.TestError("Could not create image")
def check_disk_params(self, params, root_dir=''): """ Check gathered info from qtree/block with params @param params: autotest params @param root_dir: root_dir of images. If all images use absolute path it's safe to omit this param. @return: number of errors """ err = 0 disks = {} for disk in self.disks: if isinstance(disk, QtreeDisk): disks[disk.get_qname()] = disk.get_params().copy() # We don't have the params name so we need to map file_names instead qname = None for name in params.objects('images'): current = None image_params = params.object_params(name) image_name = os.path.realpath( virt_storage.get_image_filename(image_params, root_dir)) for (qname, disk) in disks.iteritems(): if disk.get('image_name') == image_name: current = disk # autotest params might use relative path current['image_name'] = image_params.get('image_name') break if not current: logging.error("Disk %s is not in qtree but is in params.", name) err += 1 continue for prop in current.iterkeys(): handled = False if prop == "drive_format": # HOOK: params to qemu translation if current.get(prop).startswith(image_params.get(prop)): handled = True elif (image_params.get(prop) and image_params.get(prop) == current.get(prop)): handled = True if not handled: logging.error( "Disk %s property %s=%s doesn't match params" " %s", qname, prop, current.get(prop), image_params.get(prop)) err += 1 disks.pop(qname) if disks: logging.error( 'Some disks were in qtree but not in autotest params' ': %s', disks) err += 1 return err
def check_disk_params(self, params, root_dir=''): """ Check gathered info from qtree/block with params @param params: autotest params @param root_dir: root_dir of images. If all images use absolute path it's safe to omit this param. @return: number of errors """ err = 0 disks = {} for disk in self.disks: if isinstance(disk, QtreeDisk): disks[disk.get_qname()] = disk.get_params().copy() # We don't have the params name so we need to map file_names instead qname = None for name in params.objects('images'): current = None image_params = params.object_params(name) image_name = os.path.realpath( virt_storage.get_image_filename(image_params, root_dir)) for (qname, disk) in disks.iteritems(): if disk.get('image_name') == image_name: current = disk # autotest params might use relative path current['image_name'] = image_params.get('image_name') break if not current: logging.error("Disk %s is not in qtree but is in params.", name) err += 1 continue for prop in current.iterkeys(): handled = False if prop == "drive_format": # HOOK: params to qemu translation if current.get(prop).startswith(image_params.get(prop)): handled = True elif (image_params.get(prop) and image_params.get(prop) == current.get(prop)): handled = True if not handled: logging.error("Disk %s property %s=%s doesn't match params" " %s", qname, prop, current.get(prop), image_params.get(prop)) err += 1 disks.pop(qname) if disks: logging.error('Some disks were in qtree but not in autotest params' ': %s', disks) err += 1 return err
def convert(self, params, root_dir): """ Convert image @param params: dictionary containing the test parameters @param root_dir: dir for save the convert image @note: params should contain: convert_image_tag -- the image name of the convert image convert_filename -- the name of the image after convert convert_fmt -- the format after convert compressed -- indicates that target image must be compressed encrypted -- there are two value "off" and "on", default value is "off" """ convert_image_tag = params.get("image_convert") convert_image = params.get("image_name_%s" % convert_image_tag) convert_compressed = params.get("convert_compressed") convert_encrypted = params.get("convert_encrypted", "off") convert_format = params.get("image_format_%s" % convert_image_tag) params_convert = {"image_name": convert_image, "image_format": convert_format} convert_image_filename = virt_storage.get_image_filename(params_convert, root_dir) cmd = self.image_cmd cmd += " convert" if convert_compressed == "yes": cmd += " -c" if convert_encrypted != "off": cmd += " -o encryption=%s" % convert_encrypted if self.image_format: cmd += " -f %s" % self.image_format cmd += " -O %s" % convert_format cmd += " %s %s" % (self.image_filename, convert_image_filename) logging.info("Convert image %s from %s to %s", self.image_filename, self.image_format,convert_format) utils.system(cmd) return convert_image_tag
def preprocess_image(test, params, image_name): """ Preprocess a single QEMU image according to the instructions in params. @param test: Autotest test object. @param params: A dict containing image preprocessing parameters. @note: Currently this function just creates an image if requested. """ image_filename = virt_storage.get_image_filename(params, test.bindir) create_image = False if params.get("force_create_image") == "yes": logging.debug("Param 'force_create_image' specified, creating image") create_image = True elif (params.get("create_image") == "yes" and not os.path.exists(image_filename)): create_image = True if create_image: image = kvm_storage.QemuImg(params, test.bindir, image_name) if not image.create(params): raise error.TestError("Could not create image")