Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libvirt_vmxml: new param for not raising error #3716

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions virttest/utils_libvirt/libvirt_vmxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def check_guest_xml(vm_name, pat_in_dumpxml, option='', status_error=False):
raise exceptions.TestFail(msg)


def check_guest_xml_by_xpaths(vmxml, xpaths_text):
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 All @@ -66,20 +66,30 @@ def check_guest_xml_by_xpaths(vmxml, xpaths_text):
{'element_attrs': [".//memory[@unit='KiB']", ..., valuenn], 'text': 'aaa'}
{'element_attrs': ["./os/bootmenu[@enable='yes']", ..., valuenn]}
]
:param ignore_status: boolean, True to raise an exception when not matched
False to not raise an exception when not matched
:return: boolean, True when matched, False when not matched
"""
for xpath_text in xpaths_text:
elem_attrs_list = xpath_text['element_attrs']
elem_text = xpath_text.get('text', '')
for one_elem_attr in elem_attrs_list:
matches = vmxml.xmltreefile.findall(one_elem_attr)
if not matches:
raise exceptions.TestFail("XML did not match xpath: %s" % one_elem_attr)
if ignore_status:
return False
else:
raise exceptions.TestFail("XML did not match xpath: %s" % one_elem_attr)
if elem_text and any([True for x in matches if x.text != elem_text]):
raise exceptions.TestFail("XML did not match text '%s' "
"for the xpath '%s'" % (elem_text,
one_elem_attr))
if ignore_status:
return False
else:
raise exceptions.TestFail("XML did not match text '%s' "
"for the xpath '%s'" % (elem_text,
one_elem_attr))
LOG.debug("Matched the xpaths '%s' with text '%s'" % (elem_attrs_list,
elem_text))
return True


def remove_vm_devices_by_type(vm, device_type):
Expand Down