From d52e97cfef54bb5f5c34c5f21fd38909c7ddda52 Mon Sep 17 00:00:00 2001 From: nanli Date: Thu, 4 Jul 2024 15:39:06 +0800 Subject: [PATCH] add function check_guest_machine_type and check_audit_log need to add function Signed-off-by: nanli --- virttest/utils_libvirt/libvirt_vmxml.py | 24 ++++++++++++++++++++++++ virttest/utils_sys.py | 13 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/virttest/utils_libvirt/libvirt_vmxml.py b/virttest/utils_libvirt/libvirt_vmxml.py index dea0a20246..814687863f 100644 --- a/virttest/utils_libvirt/libvirt_vmxml.py +++ b/virttest/utils_libvirt/libvirt_vmxml.py @@ -57,6 +57,30 @@ def check_guest_xml(vm_name, pat_in_dumpxml, option="", status_error=False): raise exceptions.TestFail(msg) +def check_guest_machine_type(vmxml, expected_version="9.4.0"): + """ + Check guest machine type version + + :param vmxml: the guest xml. + :param expected_version: expected guest machine version, eg + if hvm exists, + which means expected_version is 8.2.0 + :return: True or False, the flag of checking successfully or not. + """ + actual_version = re.sub(r"[a-zA-Z]", "", vmxml.os.machine.split("-")[-1]) + LOG.debug("Got guest config machine is rhel{}, ".format(actual_version)) + + actual_list = actual_version.split(".") + expected_list = expected_version.split(".") + + for index in range(len(actual_list)): + if int(actual_list[index]) > int(expected_list[index]): + return True + elif int(actual_list[index]) < int(expected_list[index]): + return False + return True + + def check_guest_xml_by_xpaths(vmxml, xpaths_text, ignore_status=False): """ Check if the xml has elements/attributes/texts that match all xpaths and texts diff --git a/virttest/utils_sys.py b/virttest/utils_sys.py index 6987044ba7..7ce2584e37 100644 --- a/virttest/utils_sys.py +++ b/virttest/utils_sys.py @@ -10,6 +10,7 @@ from avocado.utils import process from virttest.utils_misc import cmd_status_output +from virttest.utils_test import libvirt LOG = logging.getLogger("avocado." + __name__) @@ -44,6 +45,18 @@ def check_dmesg_output(pattern, expect=True, session=None): return True +def check_audit_log(audit_cmd, match_pattern): + """ + Check expected match pattern in audit log. + + :param audit_cmd, the executing audit log cmd + :param match_pattern, the pattern to be checked in audit log. + """ + ausearch_result = process.run(audit_cmd, shell=True) + libvirt.check_result(ausearch_result, expected_match=match_pattern) + LOG.debug("Check audit log %s successfully." % match_pattern) + + def get_host_bridge_id(session=None): """ Get host bridge or root complex on a host