xmlbuilder: Make embedded device XML print correctly
If you call get_xml() on a device that's part of a Guest class, the last element has correct indent but not the first element. Steal the indent from the last element and prepend it to the returned XML Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
2e7b7745aa
commit
68ca651d85
|
@ -11,7 +11,7 @@
|
|||
</devices>
|
||||
</domain>
|
||||
|
||||
<interface type="user">
|
||||
<interface type="user">
|
||||
<mac address="00:11:22:33:44:55"/>
|
||||
<model type="e1000"/>
|
||||
</interface>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</devices>
|
||||
</domain>
|
||||
|
||||
<interface type="user">
|
||||
<interface type="user">
|
||||
<mac address="00:11:22:33:44:55"/>
|
||||
<model type="e1000"/>
|
||||
</interface>
|
||||
|
|
|
@ -1030,11 +1030,11 @@ def testXMLBuilderCoverage():
|
|||
xml = conn.lookupByName("test-for-virtxml").XMLDesc(0)
|
||||
guest = virtinst.Guest(conn, parsexml=xml)
|
||||
|
||||
assert guest.features.get_xml().startswith("<features")
|
||||
assert guest.clock.get_xml().startswith("<clock")
|
||||
assert guest.features.get_xml().startswith(" <features")
|
||||
assert guest.clock.get_xml().startswith(" <clock")
|
||||
assert guest.seclabels[0].get_xml().startswith("<seclabel")
|
||||
assert guest.cpu.get_xml().startswith("<cpu")
|
||||
assert guest.os.get_xml().startswith("<os")
|
||||
assert guest.cpu.get_xml().startswith(" <cpu")
|
||||
assert guest.os.get_xml().startswith(" <os")
|
||||
assert guest.cpu.get_xml_id() == "./cpu"
|
||||
assert guest.cpu.get_xml_idx() == 0
|
||||
assert guest.get_xml_id() == "."
|
||||
|
|
|
@ -586,7 +586,14 @@ class XMLBuilder(object):
|
|||
self._add_parse_bits(xmlapi)
|
||||
ret = xmlapi.get_xml(self._xmlstate.make_abs_xpath("."))
|
||||
|
||||
if ret and not ret.endswith("\n"):
|
||||
if not ret:
|
||||
return ret
|
||||
|
||||
lastline = ret.rstrip().splitlines()[-1]
|
||||
if not ret.startswith(" ") and lastline.startswith(" "):
|
||||
ret = lastline.split("<")[0] + ret
|
||||
|
||||
if not ret.endswith("\n"):
|
||||
ret += "\n"
|
||||
return ret
|
||||
|
||||
|
|
Loading…
Reference in New Issue