Martin Polednik has uploaded a new change for review. Change subject: vdsm: refactor all_channels using etree ......................................................................
vdsm: refactor all_channels using etree all_channels is a helper function currently located in vmxml that lists all channels specified in domain's xml. This patch refactors this function to use dom and adds simple test to verify it is acting as before. Change-Id: I8afeffe4a6373e8e6534f9c98b7bb844effaf565 Signed-off-by: Martin Polednik <[email protected]> --- M tests/vmTests.py M vdsm/virt/vmxml.py 2 files changed, 20 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/48/32448/1 diff --git a/tests/vmTests.py b/tests/vmTests.py index 33c944a..09e58c5 100644 --- a/tests/vmTests.py +++ b/tests/vmTests.py @@ -492,6 +492,21 @@ self.assertEqual(expected, vmxml.has_channel(domxml.dom.toprettyxml(), 'org.linux-kvm.port.0')) + def testAllChannels(self): + channels = {'org.linux-kvm.port.0': '/tmp/linux-socket', + 'org.redhat.port.0': '/tmp/redhat-socket', + 'org.dummy.port.0': '/tmp/dummy-socket', + 'org.dumb.port.0': '', + '': '/tmp/big-socket'} + + domxml = vmxml.Domain(self.conf, self.log, caps.Architecture.X86_64) + for name, path in channels.items(): + domxml._appendAgentDevice(path, name) + + for name, path in vmxml.all_channels(domxml.dom.toprettyxml()): + self.assertIn(name, channels) + self.assertEqual(path, channels[name]) + def testInputXMLX86_64(self): expectedXMLs = [ """<input bus="ps2" type="mouse"/>""", diff --git a/vdsm/virt/vmxml.py b/vdsm/virt/vmxml.py index 4171c5c..440ab37 100644 --- a/vdsm/virt/vmxml.py +++ b/vdsm/virt/vmxml.py @@ -45,16 +45,12 @@ def all_channels(domXML): - domObj = xml.dom.minidom.parseString(domXML) - for channel in domObj.childNodes[0]. \ - getElementsByTagName('devices')[0]. \ - getElementsByTagName('channel'): + domObj = etree.fromstring(domXML) + for channel in domObj.find('devices').findall('channel'): try: - name = channel.getElementsByTagName('target')[0].\ - getAttribute('name') - path = channel.getElementsByTagName('source')[0].\ - getAttribute('path') - except IndexError: + name = channel.find('target').attrib['name'] + path = channel.find('source').attrib['path'] + except KeyError: continue else: yield name, path -- To view, visit http://gerrit.ovirt.org/32448 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8afeffe4a6373e8e6534f9c98b7bb844effaf565 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Martin Polednik <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
