From d532c609f0e677f48f2122c24102c6fd449c78af Mon Sep 17 00:00:00 2001 From: nanli Date: Wed, 3 Apr 2024 17:54:00 +0800 Subject: [PATCH] fix snapshot case to use appropirate get snap state function no need to use the new created function: virsh.snapshot_status Signed-off-by: nanli --- ...tus.cfg => revert_snap_based_on_state.cfg} | 18 +++--- ...tatus.py => revert_snap_based_on_state.py} | 55 ++++++++++++------- 2 files changed, 45 insertions(+), 28 deletions(-) rename libvirt/tests/cfg/snapshot/{revert_snap_based_on_status.cfg => revert_snap_based_on_state.cfg} (55%) rename libvirt/tests/src/snapshot/{revert_snap_based_on_status.py => revert_snap_based_on_state.py} (51%) diff --git a/libvirt/tests/cfg/snapshot/revert_snap_based_on_status.cfg b/libvirt/tests/cfg/snapshot/revert_snap_based_on_state.cfg similarity index 55% rename from libvirt/tests/cfg/snapshot/revert_snap_based_on_status.cfg rename to libvirt/tests/cfg/snapshot/revert_snap_based_on_state.cfg index c5eec301d7..aabdc2c963 100644 --- a/libvirt/tests/cfg/snapshot/revert_snap_based_on_status.cfg +++ b/libvirt/tests/cfg/snapshot/revert_snap_based_on_state.cfg @@ -1,19 +1,19 @@ -- snapshot_revert.snap_and_domain_status: - type = revert_snap_based_on_status +- snapshot_revert.snap_and_domain_state: + type = revert_snap_based_on_state start_vm = no snap_name = 's1' func_supported_since_libvirt_ver = (9, 10, 0) - variants : + variants: - snap_running: - snap_status = "running" - expected_status = "${snap_status}" + snap_state = "running" + expected_state = "${snap_state}" snap_options = " %s --memspec snapshot=external,file=/tmp/mem.s1 --diskspec vda,snapshot=external,file=/tmp/vda.s1" - snap_shutoff: - snap_status = "shutoff" - expected_status = "shut off" + snap_state = "shutoff" + expected_state = "shut off" snap_options = " %s --diskspec vda,snapshot=external,file=/tmp/vda.s1" variants: - vm_running: - vm_status = "running" + vm_state = "running" - vm_shutoff: - vm_status = "shut off" + vm_state = "shut off" diff --git a/libvirt/tests/src/snapshot/revert_snap_based_on_status.py b/libvirt/tests/src/snapshot/revert_snap_based_on_state.py similarity index 51% rename from libvirt/tests/src/snapshot/revert_snap_based_on_status.py rename to libvirt/tests/src/snapshot/revert_snap_based_on_state.py index 2fcad459af..04b55d6b89 100644 --- a/libvirt/tests/src/snapshot/revert_snap_based_on_status.py +++ b/libvirt/tests/src/snapshot/revert_snap_based_on_state.py @@ -11,47 +11,64 @@ from virttest import virsh from virttest.libvirt_xml import vm_xml from virttest.utils_test import libvirt +from virttest.utils_libvirt import libvirt_misc from provider.snapshot import snapshot_base def run(test, params, env): """ - Revert snapshots based on different domain status. + Revert snapshots based on different domain state. """ + + def get_snap_state(vm_name): + """ + Get list of snapshots state of domain. + + :param vm_name: name of domain + :return: dict of snapshot names and snapshot state, + e.g.: get {'s1': 'running', 's2': 'running'} + """ + result = virsh.command("snapshot-list %s" % vm_name, + **virsh_dargs).stdout_text.strip() + state_dict = libvirt_misc.convert_to_dict( + result, r"(\S*) *\d+.* \d*:\d*:\d* .\d* *(\S*)") + test.log.debug("Get snap name and state dict is :%s", state_dict) + return state_dict + def run_test(): """ - Revert snapshots based on different domain status. + Revert snapshots based on different domain state. """ test.log.info("TEST_STEP1: Prepare a snap.") - if snap_status == "running": + if snap_state == "running": virsh.start(vm_name, **virsh_dargs) vm.wait_for_login().close() virsh.snapshot_create_as(vm_name, snap_options % snap_name, **virsh_dargs) - status_result = virsh.snapshot_status(vm_name, **virsh_dargs) - if status_result[snap_name] != snap_status: - test.fail("%s status should be '%s' instead of '%s'" % ( - snap_name, snap_status, status_result[snap_name])) + state_result = get_snap_state(vm_name) + if state_result[snap_name] != snap_state: + test.fail("%s state should be '%s' instead of '%s'" % ( + snap_name, snap_state, state_result[snap_name])) else: - test.log.debug("Check snap status '%s' is correct" % snap_status) + test.log.debug("Check snap state '%s' is correct" % snap_state) - test.log.info("TEST_STEP2: Set domain status.") - if vm_status.replace(' ', '') != snap_status: - if vm_status == "shut off": + test.log.info("TEST_STEP2: Set domain state.") + if vm_state.replace(' ', '') != snap_state: + if vm_state == "shut off": virsh.destroy(vm_name, **virsh_dargs) - elif vm_status == "running": + elif vm_state == "running": virsh.start(vm_name, **virsh_dargs) vm.wait_for_login().close() test.log.info("TEST_STEP3: Revert the snapshot") virsh.snapshot_revert(vm_name, snap_name, **virsh_dargs) - test.log.info("TEST_STEP5: Check expected domain status") - if not libvirt.check_vm_state(vm_name, expected_status): - test.fail("VM status should be '%s' after reverting." % expected_status) + test.log.info("TEST_STEP5: Check expected domain state") + if not libvirt.check_vm_state(vm_name, expected_state): + test.fail("VM state should be '%s' after reverting." % expected_state) else: - test.log.debug("Check vm status '%s' is correct", expected_status) + test.log.debug("Check vm state '%s' is correct", expected_state) def teardown_test(): """ @@ -68,9 +85,9 @@ def teardown_test(): virsh_dargs = {"debug": True, "ignore_status": True} snap_name = params.get("snap_name") snap_options = params.get("snap_options") - snap_status = params.get("snap_status") - vm_status = params.get("vm_status") - expected_status = params.get("expected_status") + snap_state = params.get("snap_state") + vm_state = params.get("vm_state") + expected_state = params.get("expected_state") test_obj = snapshot_base.SnapshotTest(vm, test, params) try: