guest: Fix adding a parsed device to a built guest
This commit is contained in:
parent
71d7e20811
commit
10e608e9dd
|
@ -38,6 +38,7 @@
|
|||
</interface>
|
||||
<graphics type="sdl" display=":3.4" xauth="/tmp/.Xauthority"/>
|
||||
<console type="pty"/>
|
||||
<sound model="pcspk"/>
|
||||
<interface type="network">
|
||||
<source network="default"/>
|
||||
<mac address="1A:2A:3A:4A:5A:6A"/>
|
||||
|
|
|
@ -756,6 +756,9 @@ class XMLParseTest(unittest.TestCase):
|
|||
guest.remove_device(adddev)
|
||||
guest.add_device(adddev)
|
||||
|
||||
guest.add_device(virtinst.VirtualAudio(conn,
|
||||
parsexml="""<sound model='pcspk'/>"""))
|
||||
|
||||
self._alter_compare(guest.get_xml_config(), outfile)
|
||||
|
||||
def testChangeKVMMedia(self):
|
||||
|
|
|
@ -212,8 +212,8 @@ class Guest(XMLBuilder):
|
|||
@param set_defaults: Whether to set defaults for the device
|
||||
"""
|
||||
self._track_device(dev)
|
||||
self._add_child(dev)
|
||||
self._recalculate_device_xpaths()
|
||||
self._add_child(dev)
|
||||
|
||||
def _track_device(self, dev):
|
||||
self._devices.append(dev)
|
||||
|
|
|
@ -795,9 +795,19 @@ class XMLBuilder(object):
|
|||
specified path
|
||||
"""
|
||||
if not dev._xmlstate.is_build:
|
||||
newnode = libxml2.parseDoc(dev.get_xml_config()).children
|
||||
_build_xpath_node(self._xmlstate.xml_ctx,
|
||||
dev.get_root_xpath(), newnode)
|
||||
if not dev.get_root_xpath():
|
||||
raise RuntimeError("programming error: must set device "
|
||||
"root xpath before add_child")
|
||||
orig_xpath = dev.get_root_xpath()
|
||||
dev.set_root_xpath(None)
|
||||
xml = dev.get_xml_config()
|
||||
dev.set_root_xpath(orig_xpath)
|
||||
|
||||
use_xpath = orig_xpath.rsplit("/", 1)[0]
|
||||
newnode = libxml2.parseDoc(xml).children
|
||||
_build_xpath_node(self._xmlstate.xml_ctx, use_xpath, newnode)
|
||||
dev.set_root_xpath(orig_xpath)
|
||||
|
||||
dev._xmlstate._parse(None, self._xmlstate.xml_node)
|
||||
|
||||
def _remove_child(self, dev):
|
||||
|
|
Loading…
Reference in New Issue