From b18187194d0846dc7f100ee65faf595c5e0bb3f2 Mon Sep 17 00:00:00 2001 From: Haijiao Zhao Date: Fri, 15 Jan 2021 15:58:33 +0800 Subject: [PATCH] XMLElementList: create parent xpath if not exists It fails if trying to assign an XMLElementList if its parent xpath not exists. This commit will try to create the missing parent xpath. Signed-off-by: Haijiao Zhao --- virttest/libvirt_xml/accessors.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/virttest/libvirt_xml/accessors.py b/virttest/libvirt_xml/accessors.py index 768d7192e9..43367f2f50 100644 --- a/virttest/libvirt_xml/accessors.py +++ b/virttest/libvirt_xml/accessors.py @@ -786,7 +786,12 @@ def __call__(self, value): # Allow other classes to generate parent structure parent = self.xmltreefile().find(self.parent_xpath) if parent is None: - raise xcepts.LibvirtXMLNotFoundError + # Create parent xpath if not exists + self.xmltreefile().create_by_xpath(self.parent_xpath) + parent = self.xmltreefile().find(self.parent_xpath) + if parent is None: + raise xcepts.LibvirtXMLNotFoundError( + 'Parent xpath %s not found.' % self.parent_xpath) # Remove existing by calling accessor method, allowing # any "untouchable" or "filtered" elements (by marshal) # to be ignored and left as-is.