Change in vdsm[master]: vdsm: refactor has_channel using etree
mpolednik at redhat.com
mpolednik at redhat.com
Wed Sep 3 13:55:11 UTC 2014
Martin Polednik has uploaded a new change for review.
Change subject: vdsm: refactor has_channel using etree
......................................................................
vdsm: refactor has_channel using etree
has_channel is a helper function currently located in vmxml,
which decides whether channel with given name exists 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: Ie35718b7abc8cb2aea75afc1bd3b939bae68903f
Signed-off-by: Martin Polednik <mpolednik at redhat.com>
---
M tests/vmTests.py
M vdsm/virt/vmxml.py
2 files changed, 23 insertions(+), 5 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/02/32402/1
diff --git a/tests/vmTests.py b/tests/vmTests.py
index 6f01e4e..6dd0230 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -118,6 +118,7 @@
return 1
+ at expandPermutations
class TestVm(TestCaseBase):
PCI_ADDR = \
@@ -479,6 +480,22 @@
domxml._appendAgentDevice(path, name)
self.assertXML(domxml.dom, channelXML, 'devices/channel')
+ @permutations([[True], [False]])
+ def testHasChannel(self, expected):
+ path = '/tmp/channel-socket'
+ name = 'org.linux-kvm.port.0'
+ domxml = vmxml.Domain(self.conf, self.log, caps.Architecture.X86_64)
+
+ if expected:
+ domxml._appendAgentDevice(path, name)
+
+ ret = vmxml.has_channel(domxml.dom.toprettyxml(),
+ 'org.linux-kvm.port.0')
+ if expected:
+ self.assertTrue(ret)
+ else:
+ self.assertFalse(ret)
+
def testInputXMLX86_64(self):
expectedXMLs = [
"""<input bus="ps2" type="mouse"/>""",
diff --git a/vdsm/virt/vmxml.py b/vdsm/virt/vmxml.py
index f3d942b..4171c5c 100644
--- a/vdsm/virt/vmxml.py
+++ b/vdsm/virt/vmxml.py
@@ -22,6 +22,7 @@
from operator import itemgetter
import xml.dom
import xml.dom.minidom
+import xml.etree.ElementTree as etree
from vdsm import constants
from vdsm import utils
@@ -30,14 +31,14 @@
def has_channel(domXML, name):
- domObj = xml.dom.minidom.parseString(domXML)
- devices = domObj.getElementsByTagName('devices')
+ domObj = etree.fromstring(domXML)
+ devices = domObj.findall('devices')
if len(devices) == 1:
- for chan in devices[0].getElementsByTagName('channel'):
- targets = chan.getElementsByTagName('target')
+ for chan in devices[0].findall('channel'):
+ targets = chan.findall('target')
if len(targets) == 1:
- if targets[0].getAttribute('name') == name:
+ if targets[0].attrib['name'] == name:
return True
return False
--
To view, visit http://gerrit.ovirt.org/32402
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie35718b7abc8cb2aea75afc1bd3b939bae68903f
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Martin Polednik <mpolednik at redhat.com>
More information about the vdsm-patches
mailing list