Skip to content

Commit

Permalink
Merge pull request avocado-framework#3941 from nanli1/add_function_fo…
Browse files Browse the repository at this point in the history
…r_check_audit_log_and_check_guest_machine_type

add function check_guest_machine_type and check_audit_log
  • Loading branch information
chloerh authored Jul 12, 2024
2 parents 3f6af08 + d52e97c commit 72898b4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
24 changes: 24 additions & 0 deletions virttest/utils_libvirt/libvirt_vmxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <type arch='x86_64' machine='pc-q35-rhel8.2.0'>hvm</type> 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
Expand Down
13 changes: 13 additions & 0 deletions virttest/utils_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 72898b4

Please sign in to comment.