diff --git a/qemu/tests/blk_stream.py b/qemu/tests/blk_stream.py index 5d43a2ce2f60e80a0e90314b7ee69fa69abda147..8f34ea374f3e51da1e11f4984604cdd3718a690d 100644 --- a/qemu/tests/blk_stream.py +++ b/qemu/tests/blk_stream.py @@ -61,39 +61,8 @@ class BlockStream(block_copy.BlockCopy): raise error.TestFail("create snapshot '%s' fail" % snapshot) self.trash_files.append(snapshot) - def job_finished(self): - """ - check if streaming job finished; - """ - if self.get_status(): - return False - if self.vm.monitor.protocol == "qmp": - return bool(self.vm.monitor.get_event("BLOCK_JOB_COMPLETED")) - return True - - def wait_for_finished(self): - """ - waiting until block stream job finished - """ - params = self.parser_test_args() - timeout = params.get("wait_timeout") - finished = utils_misc.wait_for(self.job_finished, timeout=timeout) - if not finished: - raise error.TestFail("Job not finished in %s seconds" % timeout) - logging.info("Block stream job done.") - def action_when_streaming(self): """ run steps when job in steaming; """ return self.do_steps("when_streaming") - - def action_after_finished(self): - """ - run steps after streaming done; - """ - params = self.parser_test_args() - # if block job cancelled, no need to wait it; - if params["wait_finished"] == "yes": - self.wait_for_finished() - return self.do_steps("after_finished") diff --git a/qemu/tests/block_copy.py b/qemu/tests/block_copy.py index 8e96c49a2d7d2facae7d8cbf7caf0fa41b101f39..0ed71c51acd1f71a3f374d1165cc54d488cffb22 100644 --- a/qemu/tests/block_copy.py +++ b/qemu/tests/block_copy.py @@ -300,6 +300,77 @@ class BlockCopy(object): if bg.isAlive(): self.processes.append(bg) + def job_finished(self): + """ + check if block job finished; + """ + if self.get_status(): + return False + if self.vm.monitor.protocol == "qmp": + return bool(self.vm.monitor.get_event("BLOCK_JOB_COMPLETED")) + return True + + def wait_for_finished(self): + """ + waiting until block job finished + """ + params = self.parser_test_args() + timeout = params.get("wait_timeout") + finished = utils_misc.wait_for(self.job_finished, timeout=timeout) + if not finished: + raise error.TestFail("Job not finished in %s seconds" % timeout) + logging.info("Block job done.") + + def action_after_finished(self): + """ + run steps after block job done; + """ + params = self.parser_test_args() + # if block job cancelled, no need to wait it; + if params["wait_finished"] == "yes": + self.wait_for_finished() + return self.do_steps("after_finished") + + def is_steady(self): + """ + check block job is steady status or not; + """ + params = self.parser_test_args() + info = self.get_status() + ret = bool(info and info["len"] == info["offset"]) + if self.vm.monitor.protocol == "qmp": + if params.get("check_event", "no") == "yes": + ret &= bool(self.vm.monitor.get_event("BLOCK_JOB_READY")) + return ret + + def wait_for_steady(self): + """ + check block job status, utils timeout; if still not go + into steady status, raise TestFail exception; + """ + params = self.parser_test_args() + timeout = params.get("wait_timeout") + if self.vm.monitor.protocol == "qmp": + self.vm.monitor.clear_event("BLOCK_JOB_READY") + steady = utils_misc.wait_for(self.is_steady, first=3.0, + step=3.0, timeout=timeout) + if not steady: + raise error.TestFail("Wait mirroring job ready " + "timeout in %ss" % timeout) + + def action_before_steady(self): + """ + run steps before job in steady status; + """ + return self.do_steps("before_steady") + + def action_when_steady(self): + """ + run steps when job in steady status; + """ + self.wait_for_steady() + return self.do_steps("when_steady") + def action_before_cleanup(self): """ run steps before job in steady status; diff --git a/qemu/tests/drive_mirror.py b/qemu/tests/drive_mirror.py index 9a413dc2884a289db20f98b5de944f673d5b76e1..976f9c679f75497d24ff17778d0ccea2caa74d51 100644 --- a/qemu/tests/drive_mirror.py +++ b/qemu/tests/drive_mirror.py @@ -134,65 +134,11 @@ class DriveMirror(block_copy.BlockCopy): params = self.parser_test_args() target_format = params["image_format"] timeout = params["reopen_timeout"] - - def is_opened(): - try: - device = self.vm.get_block({"file": self.target_image}) - ret = (device == self.device) - if self.vm.monitor.protocol == "qmp": - ret &= bool(self.vm.monitor.get_event("BLOCK_JOB_COMPLETED")) - return ret - except Exception: - return False - error.context("reopen new target image", logging.info) if self.vm.monitor.protocol == "qmp": self.vm.monitor.clear_event("BLOCK_JOB_COMPLETED") self.vm.block_reopen(self.device, self.target_image, target_format) - opened = utils_misc.wait_for(is_opened, first=3.0, timeout=timeout) - if not opened: - msg = "Target image not used,wait timeout in %ss" % timeout - raise error.TestFail(msg) - - def is_steady(self): - """ - check block device mirroring job is steady status or not; - """ - params = self.parser_test_args() - info = self.get_status() - ret = bool(info and info["len"] == info["offset"]) - if self.vm.monitor.protocol == "qmp": - if params.get("check_event", "no") == "yes": - ret &= bool(self.vm.monitor.get_event("BLOCK_JOB_READY")) - return ret - - def wait_for_steady(self): - """ - check block device mirroring status, utils timeout; if still not go - into steady status, raise TestFail exception; - """ - params = self.parser_test_args() - timeout = params.get("wait_timeout") - if self.vm.monitor.protocol == "qmp": - self.vm.monitor.clear_event("BLOCK_JOB_READY") - steady = utils_misc.wait_for(self.is_steady, first=3.0, - step=3.0, timeout=timeout) - if not steady: - raise error.TestFail("Wait mirroring job ready " - "timeout in %ss" % timeout) - - def action_before_steady(self): - """ - run steps before job in steady status; - """ - return self.do_steps("before_steady") - - def action_when_steady(self): - """ - run steps when job in steady status; - """ - self.wait_for_steady() - return self.do_steps("when_steady") + self.wait_for_finished() def action_after_reopen(self): """