From 1b44adb6a76bd5b9f8265d5fc1ce1ac7ff84af69 Mon Sep 17 00:00:00 2001 From: Hu Shuai Date: Wed, 26 Jul 2023 14:51:11 +0800 Subject: [PATCH] Update func set_graphics_attr The current set_graphics_attr() can only handle the situation where the graphics device itself exists in the original xmltree. Update the func so that it can also handle the situation where the graphics does not exist in the original xmltree. Signed-off-by: Hu Shuai --- virttest/libvirt_xml/vm_xml.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/virttest/libvirt_xml/vm_xml.py b/virttest/libvirt_xml/vm_xml.py index cacf4ed614..725205d6d4 100755 --- a/virttest/libvirt_xml/vm_xml.py +++ b/virttest/libvirt_xml/vm_xml.py @@ -1614,7 +1614,11 @@ def set_graphics_attr(vm_name, attr, index=0, virsh_instance=base.virsh): """ vmxml = VMXML.new_from_inactive_dumpxml( vm_name, virsh_instance=virsh_instance) - graphic = vmxml.xmltreefile.find('devices').findall('graphics') + devices = vmxml.xmltreefile.find('devices') + graphic = devices.findall('graphics') + if not graphic: + graphic = [xml_utils.ElementTree.SubElement(devices, 'graphics')] + graphic[0].set('type', 'vnc') for key in attr: LOG.debug("Set %s='%s'" % (key, attr[key])) graphic[index].set(key, attr[key])