def _call_image_func(): if params.get("skip_image_processing") == "yes": return if params.objects("vms"): for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) vm = env.get_vm(vm_name) unpause_vm = False if vm is not None and vm.is_alive() and not vm.is_paused(): vm.pause() unpause_vm = True try: err = "" for image_name in vm_params.objects("images"): image_params = vm_params.object_params(image_name) # Call image_func for each image try: image_func(test, image_params, image_name) except Exception, details: err += "\n%s: %s" % (image_name, details) if err: raise virt_vm.VMImageCheckError( "Error(s) occured " "while processing images: %s" % err) finally: if unpause_vm:
def check_image(self, params, root_dir): """ Check an image using the appropriate tools for each virt backend. :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 VMImageCheckError: In case qemu-img check fails on the image. """ image_filename = self.image_filename logging.debug("Checking image file %s", image_filename) qemu_img_cmd = self.image_cmd image_is_checkable = self.image_format in ['qcow2', 'qed'] if (storage.file_exists(params, image_filename) or params.get("enable_gluster", "no") == "yes") and image_is_checkable: check_img = self.support_cmd("check") and self.support_cmd("info") if not check_img: logging.debug("Skipping image check " "(lack of support in qemu-img)") else: try: utils.run("%s info %s" % (qemu_img_cmd, image_filename), verbose=True) except error.CmdError: logging.error("Error getting info from image %s", image_filename) cmd_result = utils.run("%s check %s" % (qemu_img_cmd, image_filename), ignore_status=True, verbose=True) # Error check, large chances of a non-fatal problem. # There are chances that bad data was skipped though if cmd_result.exit_status == 1: for e_line in cmd_result.stdout.splitlines(): logging.error("[stdout] %s", e_line) for e_line in cmd_result.stderr.splitlines(): logging.error("[stderr] %s", e_line) chk = params.get("backup_image_on_check_error", "no") if chk == "yes": self.backup_image(params, root_dir, "backup", False) raise error.TestWarn("qemu-img check error. Some bad " "data in the image may have gone" " unnoticed (%s)" % image_filename) # Exit status 2 is data corruption for sure, # so fail the test elif cmd_result.exit_status == 2: for e_line in cmd_result.stdout.splitlines(): logging.error("[stdout] %s", e_line) for e_line in cmd_result.stderr.splitlines(): logging.error("[stderr] %s", e_line) chk = params.get("backup_image_on_check_error", "no") if chk == "yes": self.backup_image(params, root_dir, "backup", False) raise virt_vm.VMImageCheckError(image_filename) # Leaked clusters, they are known to be harmless to data # integrity elif cmd_result.exit_status == 3: raise error.TestWarn("Leaked clusters were noticed" " during image check. No data " "integrity problem was found " "though. (%s)" % image_filename) # Just handle normal operation if params.get("backup_image", "no") == "yes": self.backup_image(params, root_dir, "backup", True, True) else: if not storage.file_exists(params, image_filename): logging.debug("Image file %s not found, skipping check", image_filename) elif not image_is_checkable: logging.debug( "Image format %s is not checkable, skipping check", self.image_format)
def check_image(self, params, root_dir): """ Check an image using the appropriate tools for each virt backend. @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 VMImageCheckError: In case qemu-img check fails on the image. """ image_filename = self.image_filename logging.debug("Checking image file %s", image_filename) qemu_img_cmd = self.image_cmd image_is_qcow2 = self.image_format == 'qcow2' if os.path.exists(image_filename) and image_is_qcow2: # Verifying if qemu-img supports 'check' q_result = utils.run(qemu_img_cmd, ignore_status=True) q_output = q_result.stdout check_img = True if not "check" in q_output: logging.error("qemu-img does not support 'check', " "skipping check") check_img = False if not "info" in q_output: logging.error("qemu-img does not support 'info', " "skipping check") check_img = False if check_img: try: utils.system("%s info %s" % (qemu_img_cmd, image_filename)) except error.CmdError: logging.error("Error getting info from image %s", image_filename) cmd_result = utils.run("%s check %s" % (qemu_img_cmd, image_filename), ignore_status=True) # Error check, large chances of a non-fatal problem. # There are chances that bad data was skipped though if cmd_result.exit_status == 1: for e_line in cmd_result.stdout.splitlines(): logging.error("[stdout] %s", e_line) for e_line in cmd_result.stderr.splitlines(): logging.error("[stderr] %s", e_line) chk = params.get("backup_image_on_check_error", "no") if chk == "yes": self.backup_image(params, root_dir, "backup", False) raise error.TestWarn("qemu-img check error. Some bad " "data in the image may have gone" " unnoticed") # Exit status 2 is data corruption for sure, # so fail the test elif cmd_result.exit_status == 2: for e_line in cmd_result.stdout.splitlines(): logging.error("[stdout] %s", e_line) for e_line in cmd_result.stderr.splitlines(): logging.error("[stderr] %s", e_line) chk = params.get("backup_image_on_check_error", "no") if chk == "yes": self.backup_image(params, root_dir, "backup", False) raise virt_vm.VMImageCheckError(image_filename) # Leaked clusters, they are known to be harmless to data # integrity elif cmd_result.exit_status == 3: raise error.TestWarn("Leaked clusters were noticed" " during image check. No data " "integrity problem was found " "though.") # Just handle normal operation if params.get("backup_image", "no") == "yes": self.backup_image(params, root_dir, "backup", True) else: if not os.path.exists(image_filename): logging.debug("Image file %s not found, skipping check", image_filename) elif not image_is_qcow2: logging.debug("Image file %s not qcow2, skipping check", image_filename)