Skip to content

Commit

Permalink
XMLElementList: create parent xpath if not exists
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
chloerh committed Jan 15, 2021
1 parent 480f90c commit b181871
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion virttest/libvirt_xml/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b181871

Please sign in to comment.