xmlbuilder: Remove order_elements hack
This commit is contained in:
parent
510d28e33b
commit
326731cfc5
|
@ -26,9 +26,11 @@
|
|||
<mac address="22:22:33:44:55:67"/>
|
||||
<source bridge="foobr0"/>
|
||||
</interface>
|
||||
|
||||
<interface type="bridge">
|
||||
<mac address="22:22:33:44:55:68"/>
|
||||
</interface>
|
||||
|
||||
<input type="mouse" bus="ps2"/>
|
||||
<graphics type="sdl" display=":3.4" xauth="/tmp/.Xauthority"/>
|
||||
<console type="pty"/>
|
||||
|
|
|
@ -1011,14 +1011,14 @@ class TestXMLConfig(unittest.TestCase):
|
|||
g.add_device(dev1)
|
||||
|
||||
dev2 = virtinst.VirtualNetworkInterface(g.conn,
|
||||
parsexml=dev1.get_xml_config())
|
||||
parsexml=dev1.get_xml_config().strip("\n"))
|
||||
dev2.source = None
|
||||
dev2.source = "foobr0"
|
||||
dev2.macaddr = "22:22:33:44:55:67"
|
||||
g.add_device(dev2)
|
||||
|
||||
dev3 = virtinst.VirtualNetworkInterface(g.conn,
|
||||
parsexml=dev1.get_xml_config())
|
||||
parsexml=dev1.get_xml_config().strip("\n"))
|
||||
dev3.source = None
|
||||
dev3.macaddr = "22:22:33:44:55:68"
|
||||
g.add_device(dev3)
|
||||
|
|
|
@ -139,9 +139,6 @@ _TARGET_PROPS = ["file", "dev", "dir"]
|
|||
|
||||
|
||||
class VirtualDisk(VirtualDevice):
|
||||
# pylint: disable=W0622
|
||||
# Redefining built-in 'type', but it matches the XML so keep it
|
||||
|
||||
virtual_device_type = VirtualDevice.VIRTUAL_DEV_DISK
|
||||
|
||||
DRIVER_FILE = "file"
|
||||
|
@ -391,9 +388,12 @@ class VirtualDisk(VirtualDevice):
|
|||
|
||||
|
||||
|
||||
_XML_ELEMENT_ORDER = ["driver", "source", "target"]
|
||||
_XML_PROP_ORDER = ["target", "bus", "type", "device",
|
||||
"driver_name", "driver_type"]
|
||||
_XML_PROP_ORDER = [
|
||||
"type", "device",
|
||||
"driver_name", "driver_type",
|
||||
"driver_cache", "driver_io", "error_policy",
|
||||
"_xmlpath", "target", "bus",
|
||||
]
|
||||
|
||||
def __init__(self, conn, parsexml=None, parsexmlnode=None):
|
||||
VirtualDevice.__init__(self, conn, parsexml, parsexmlnode)
|
||||
|
|
|
@ -198,7 +198,9 @@ class VirtualNetworkInterface(VirtualDevice):
|
|||
raise RuntimeError(msg)
|
||||
|
||||
|
||||
_XML_ELEMENT_ORDER = ["source", "mac", "target", "model"]
|
||||
_XML_PROP_ORDER = [
|
||||
"bridge", "network", "source_dev", "source_mode",
|
||||
"macaddr", "target_dev", "model"]
|
||||
|
||||
type = XMLProperty(xpath="./@type",
|
||||
default_cb=lambda s: s.TYPE_BRIDGE)
|
||||
|
|
|
@ -593,10 +593,8 @@ class XMLBuilder(object):
|
|||
return xmlstr
|
||||
return "\n".join((" " * level + l) for l in xmlstr.splitlines())
|
||||
|
||||
# Specify a list of tag values here and we will arrange them when
|
||||
# outputing XML. They will be put before every other element. This
|
||||
# is strictly to keep test suite happy.
|
||||
_XML_ELEMENT_ORDER = []
|
||||
# Order that we should apply values to the XML. Keeps XML generation
|
||||
# consistent with what the test suite expects.
|
||||
_XML_PROP_ORDER = []
|
||||
|
||||
# Root element name of this function, used to populate a default
|
||||
|
@ -693,7 +691,6 @@ class XMLBuilder(object):
|
|||
finally:
|
||||
self._xml_fixup_relative_xpath = False
|
||||
|
||||
ret = self._order_xml_elements(ret)
|
||||
return self._cleanup_xml(ret)
|
||||
|
||||
|
||||
|
@ -840,35 +837,3 @@ class XMLBuilder(object):
|
|||
self._xml_ctx = None
|
||||
self._proporder = origproporder
|
||||
self._propstore = origpropstore
|
||||
|
||||
|
||||
def _order_xml_elements(self, xml):
|
||||
# This whole thing is reeeally hacky but it saves us some
|
||||
# unittest churn.
|
||||
if not self._XML_ELEMENT_ORDER:
|
||||
return xml
|
||||
|
||||
split = xml.splitlines()
|
||||
if len(split) < 3:
|
||||
return xml
|
||||
|
||||
head = split[0]
|
||||
end = split[-1]
|
||||
split = split[1:-1]
|
||||
|
||||
baseindent = 0
|
||||
for i in head:
|
||||
if i != " ":
|
||||
break
|
||||
baseindent += 1
|
||||
|
||||
neworder = []
|
||||
for prio in reversed(self._XML_ELEMENT_ORDER):
|
||||
tag = "%s<%s " % ((baseindent + 2) * " ", prio)
|
||||
for idx in range(len(split)):
|
||||
if split[idx].startswith(tag):
|
||||
neworder.insert(0, split.pop(idx))
|
||||
break
|
||||
neworder += split
|
||||
|
||||
return "\n".join([head] + neworder + [end])
|
||||
|
|
Loading…
Reference in New Issue