def create_snapshot(self, t_params=None): """ create snapshot image file """ error_context.context("create snapshot image") params = self.params.object_params(self.tag) if t_params: params.update(t_params) if len(params.get("image_chain", "").split()) < 2: return {} snapshot = storage.get_image_filename(params, self.data_dir) storage.file_remove(params, snapshot) super(QemuImgTest, self).create(params) self.trash.append(snapshot) return params
def remove(self): """ Remove an image file. """ logging.debug("Removing image file %s", self.image_filename) storage.file_remove(self.params, self.image_filename) secret_files = [] if self.encryption_config.key_secret: secret_files.append(self.encryption_config.key_secret.filename) access_secret, _ = self._get_access_secret_info() if access_secret is not None: secret_files.append(access_secret.filename) for f in secret_files: if os.path.exists(f): os.unlink(f)
def run(test, params, env): """ Convert remote image. 1) Start VM and create a tmp file, record its md5sum, shutdown VM 2) Convert image 3) Start VM by the converted image and then check the md5sum """ def _check_file(boot_image, md5_value): logging.debug("Check md5sum.") vm = img_utils.boot_vm_with_images(test, params, env, (boot_image, )) session = vm.wait_for_login() guest_temp_file = params["guest_temp_file"] md5sum_bin = params.get("md5sum_bin", "md5sum") img_utils.check_md5sum(guest_temp_file, md5sum_bin, session, md5_value_to_check=md5_value) session.close() vm.destroy() vm = img_utils.boot_vm_with_images(test, params, env) session = vm.wait_for_login() guest_temp_file = params["guest_temp_file"] md5sum_bin = params.get("md5sum_bin", "md5sum") sync_bin = params.get("sync_bin", "sync") logging.info("Create temporary file on guest: %s", guest_temp_file) img_utils.save_random_file_to_vm(vm, guest_temp_file, 2048 * 512, sync_bin) md5_value = img_utils.check_md5sum(guest_temp_file, md5sum_bin, session) logging.info("Get md5 value of the temporary file: %s", md5_value) session.close() vm.destroy() root_dir = data_dir.get_data_dir() # Make a list of all source and target image pairs img_pairs = [(params["convert_source"], params["convert_target"])] if params.get("convert_target_remote"): # local -> remote img_pairs.append( (params["convert_target"], params["convert_target_remote"])) # Convert images for source, target in img_pairs: params["convert_source"] = source params["convert_target"] = target source_params = params.object_params(source) target_params = params.object_params(target) source_image = qemu_storage.QemuImg(source_params, root_dir, source) target_image = qemu_storage.QemuImg(target_params, root_dir, target) # remove the target target_filename = storage.get_image_filename(target_params, root_dir) storage.file_remove(target_params, target_filename) # Convert source to target cache_mode = params.get("cache_mode") source_cache_mode = params.get("source_cache_mode") logging.info("Convert %s to %s", source, target) fail_on((process.CmdError, ))(source_image.convert)( params, root_dir, cache_mode=cache_mode, source_cache_mode=source_cache_mode) _check_file(target, md5_value) # Remove images converted for _, target in img_pairs: target_params = params.object_params(target) target_image = qemu_storage.QemuImg(target_params, root_dir, target) target_image.remove()
def clean(self): params = self.params for sn in params.get("image_chain").split()[1:]: _params = params.object_params(sn) _image = storage.get_image_filename(_params, self.data_dir) storage.file_remove(_params, _image)