diff --git a/libvirt/tests/cfg/save_and_restore/save_with_formats.cfg b/libvirt/tests/cfg/save_and_restore/save_with_formats.cfg index 37ea5245e1..702bbbda46 100644 --- a/libvirt/tests/cfg/save_and_restore/save_with_formats.cfg +++ b/libvirt/tests/cfg/save_and_restore/save_with_formats.cfg @@ -6,7 +6,12 @@ variants: - positive_test: status_error = no - save_formats = raw lzop gzip bzip2 xz + variants save_format: + - raw: + - lzop: + - gzip: + - bzip2: + - xz: - negative_test: status_error = yes variants save_format: diff --git a/libvirt/tests/src/save_and_restore/save_with_formats.py b/libvirt/tests/src/save_and_restore/save_with_formats.py index 8028048c69..0679390120 100644 --- a/libvirt/tests/src/save_and_restore/save_with_formats.py +++ b/libvirt/tests/src/save_and_restore/save_with_formats.py @@ -14,34 +14,41 @@ VIRSH_ARGS = {'debug': True, 'ignore_status': False} -def save_with_format(save_format, test, params, env): +def run(test, params, env): """ - Run virsh save with given format - - :param save_format: format to save with - :param test: test instance - :param params: test params - :param env: test env - :return: dict-type data of duration and image size + Test virsh save with different formats """ vm_name = params.get('main_vm') vm = env.get_vm(vm_name) + status_error = "yes" == params.get('status_error', 'no') + error_msg = params.get('error_msg', '') log_file = params.get('libvirtd_debug_file') + save_format = params.get('save_format') rand_id = '_' + utils_misc.generate_random_string(3) - save_path = f'/root/{vm_name}_{save_format}_{rand_id}.save' - - qemu_conf = utils_config.LibvirtQemuConfig() - libvirtd = utils_libvirtd.Libvirtd() - qemu_conf.save_image_format = save_format - libvirtd.restart() + save_path = f'/var/tmp/{vm_name}_{rand_id}.save' + check_cmd = params.get('check_cmd', '') + check_cmd = check_cmd.format(save_path) if check_cmd else check_cmd + vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) + bkxml = vmxml.copy() try: + qemu_conf = utils_config.LibvirtQemuConfig() + libvirtd = utils_libvirtd.Libvirtd() + qemu_conf.save_image_format = save_format + libvirtd.restart() + + vm.start() pid_ping, upsince = save_base.pre_save_setup(vm) + save_result = virsh.save(vm_name, save_path, debug=True) + libvirt.check_exit_status(save_result, status_error) + if status_error: + libvirt.check_result(save_result, error_msg) + return + duration = save_result.duration LOG.debug(f'Duration of {format}: {duration}') - img_size = int(utils_misc.get_image_info(save_path)['dsize']) LOG.debug(f'Image size of {format}: {img_size}') @@ -57,60 +64,6 @@ def save_with_format(save_format, test, params, env): save_base.post_save_check(vm, pid_ping, upsince) - return {'duration': duration, 'img_size': img_size} - - finally: - if os.path.exists(save_path): - os.remove(save_path) - qemu_conf.restore() - libvirtd.restart() - - -def run(test, params, env): - """ - Test virsh save with different formats and compare duration and image size - """ - vm_name = params.get('main_vm') - vm = env.get_vm(vm_name) - - status_error = "yes" == params.get('status_error', 'no') - error_msg = params.get('error_msg', '') - vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) - bkxml = vmxml.copy() - save_formats = params.get('save_formats', '').split() - rand_id = '_' + utils_misc.generate_random_string(3) - save_path = f'/var/tmp/{vm_name}_{rand_id}.save' - check_cmd = params.get('check_cmd', '') - check_cmd = check_cmd.format(save_path) if check_cmd else check_cmd - - try: - vm.start() - if not status_error: - save_info = {} - for save_format in save_formats: - save_info[save_format] = save_with_format(save_format, test, - params, env) - [LOG.debug(f"Duration of format {f} is {save_info[f]['duration']}") - for f in save_formats] - [LOG.debug(f"Image size of format {f} is {save_info[f]['img_size']}" - ) for f in save_formats] - duration_list = [save_info[f]['duration'] for f in save_formats] - if sorted(duration_list) != duration_list: - test.fail( - 'The order of time cost is not correct, please check log') - img_size_list = [save_info[f]['img_size'] for f in save_formats] - if sorted(img_size_list, reverse=True) != img_size_list: - test.fail( - 'The order of image size is not correct, please check log') - else: - save_format = params.get('save_format') - qemu_conf = utils_config.LibvirtQemuConfig() - libvirtd = utils_libvirtd.Libvirtd() - qemu_conf.save_image_format = save_format - libvirtd.restart() - save_result = virsh.save(vm_name, save_path, debug=True) - libvirt.check_result(save_result, error_msg) - finally: bkxml.sync() if 'qemu_conf' in locals(): diff --git a/provider/save/save_base.py b/provider/save/save_base.py index c39095a733..c003e3ee20 100644 --- a/provider/save/save_base.py +++ b/provider/save/save_base.py @@ -49,12 +49,13 @@ def post_save_check(vm, pid_ping, upsince): LOG.debug(session.cmd_output(f'ps -ef|grep ping')) session.close() + if upsince_restore != upsince: + raise exceptions.TestWarn(f'Uptime since {upsince_restore} is ' + f'incorrect, should be {upsince}') ping_cmd = 'ping 127.0.0.1' if ping_cmd not in proc_info: - raise Exception('Cannot find running ping command after save-restore.') - if upsince_restore != upsince: - raise Exception(f'Uptime since {upsince_restore} is incorrect,' - f'should be {upsince}') + raise exceptions.TestFail('Cannot find running ping command ' + 'after save-restore.') def check_ownership(path, uid, gid):