diff --git a/virttest/libvirt_xml/vm_xml.py b/virttest/libvirt_xml/vm_xml.py index bd91d2ce3a..e5ac32ca1a 100644 --- a/virttest/libvirt_xml/vm_xml.py +++ b/virttest/libvirt_xml/vm_xml.py @@ -554,14 +554,8 @@ def del_controller(self, controller_type=None): :return: None if deleting all controllers """ - all_controllers = self.xmltreefile.findall("devices/controller") - del_controllers = [] - for controller in all_controllers: - if controller.get("type") != controller_type: - continue - del_controllers.append(controller) - # no seclabel tag found in xml. + del_controllers = self.get_controllers(controller_type=controller_type) if del_controllers == []: logging.debug("Controller %s for this domain does not " "exist" % controller_type) @@ -569,6 +563,21 @@ def del_controller(self, controller_type=None): for controller in del_controllers: self.xmltreefile.remove(controller) + def get_controllers(self, controller_type=None): + """ + Get controllers according controller type + + :param controller_type: type of controllers need to get + :return: controller list + """ + all_controllers = self.xmltreefile.findall("devices/controller") + type_controllers = [] + for controller in all_controllers: + if controller.get("type") != controller_type: + continue + type_controllers.append(controller) + return type_controllers + class VMXML(VMXMLBase):