xmlbuilder: Ensure top level XML objects always end with a newline

This commit is contained in:
Cole Robinson 2013-09-19 13:48:28 -04:00
parent 99a50de53e
commit cb06f7eb3d
2 changed files with 6 additions and 6 deletions

View File

@ -171,7 +171,7 @@ class XMLParseTest(unittest.TestCase):
rmfeat = guest.cpu.features[3]
guest.cpu.remove_feature(rmfeat)
self.assertEquals(rmfeat.get_xml_config(),
"""<feature name="foo" policy="bar"/>""")
"""<feature name="foo" policy="bar"/>\n""")
guest.cpu.add_feature("addfeature")
check = self._make_checker(guest.numatune)
@ -303,8 +303,8 @@ class XMLParseTest(unittest.TestCase):
self._alter_compare(guest.get_xml_config(), outfile)
def testSingleDisk(self):
xml = ("""<disk type="file" device="disk"><source file="/a.img"/>"""
"""<target dev="hda" bus="ide"/></disk>""")
xml = ("""<disk type="file" device="disk"><source file="/a.img"/>\n"""
"""<target dev="hda" bus="ide"/></disk>\n""")
d = virtinst.VirtualDisk(conn, parsexml=xml)
self._set_and_check(d, "target", "hda", "hdb")
self.assertEquals(xml.replace("hda", "hdb"), d.get_xml_config())

View File

@ -1018,9 +1018,9 @@ class XMLBuilder(object):
if ret == xmlstub:
ret = ""
if (ret and
self._xmlstate.root_name == "domain" and
not ret.endswith("\n")):
# Ensure top level XML object always ends with a newline, just
# for back compat and readability
if (ret and not self.get_root_xpath() and not ret.endswith("\n")):
ret += "\n"
return ret