virt-manager/b08647c2-xmlbuilder-05.patch
Charles Arnold 494e2d1303 - fate##319621 - KVM: Provide SMBIOS info to KVM virtual machines
d8a0a788-xmlbuilder-01.patch
  559e813b-xmlbuilder-02.patch
  a931a1a6-xmlbuilder-03.patch
  835ddc5f-xmlbuilder-04.patch
  b08647c2-xmlbuilder-05.patch
  b31c0b44-Add-classes-for-defining-SMBios-information.patch
  a3206f89-Add-the-sysinfo-option.patch

OBS-URL: https://build.opensuse.org/package/show/Virtualization/virt-manager?expand=0&rev=329
2016-09-08 16:20:24 +00:00

64 lines
2.0 KiB
Diff

References: fate#319621
Subject: xmlbuilder: Handle setting conditional xpaths correctly
From: Cole Robinson crobinso@redhat.com Mon Jul 18 14:40:58 2016 -0400
Date: Mon Jul 18 14:46:50 2016 -0400:
Git: b08647c2f277e463971ae1e4430aaed28a4619f3
So if xml=<foo> and xpath=./bar[@baz='foo'] and val=XXX, xmlbuilder
previously would generate XML
<foo>
<bar>XXX</bar>
</foo>
But now generates the expected
<foo>
<bar baz='foo'/>XXX</bar>
</foo>
No users yet, but they are incoming
Index: virt-manager-1.4.0/virtinst/xmlbuilder.py
===================================================================
--- virt-manager-1.4.0.orig/virtinst/xmlbuilder.py
+++ virt-manager-1.4.0/virtinst/xmlbuilder.py
@@ -167,6 +167,16 @@ def _build_xpath_node(ctx, xpath):
And the node pointing to @baz will be returned, for the caller to
do with as they please.
+
+ There's also special handling to ensure that setting
+ xpath=./bar[@baz='foo']/frob will create
+
+ <bar baz='foo'>
+ <frob></frob>
+ </bar>
+
+ Even if <bar> didn't exist before. So we fill in the dependent property
+ expression values
"""
def _handle_node(nodename, parentnode, parentpath):
# If the passed xpath snippet (nodename) exists, return the node
@@ -209,6 +219,19 @@ def _build_xpath_node(ctx, xpath):
for nodename in xpath.split("/"):
parentnode, parentpath = _handle_node(nodename, parentnode, parentpath)
+ # Check if the xpath snippet had an '=' expression in it, example:
+ #
+ # ./foo[@bar='baz']
+ #
+ # If so, we also want to set <foo bar='baz'/>, so that setting
+ # this XML element works as expected in this case.
+ if "[" not in nodename or "=" not in nodename:
+ continue
+
+ propname, val = nodename.split("[")[1].strip("]").split("=")
+ propobj, ignore = _handle_node(propname, parentnode, parentpath)
+ propobj.setContent(val.strip("'"))
+
return parentnode