Mark Wu has uploaded a new change for review. Change subject: Extract a method _getCapsXMLStr() to get capabilities from libvirt ......................................................................
Extract a method _getCapsXMLStr() to get capabilities from libvirt The new function _getCapsXMLStr() could be shared by _getCpuTopology() and _getEmulatedMachines(). And it also saves a libvirt call by memorizing the result. Change-Id: I004693d64c84479f150f05d348b2e843f48238a4 Signed-off-by: Mark Wu <[email protected]> --- M tests/capsTests.py M vdsm/caps.py 2 files changed, 10 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/31/9431/1 diff --git a/tests/capsTests.py b/tests/capsTests.py index 74ddda8..51d23ee 100644 --- a/tests/capsTests.py +++ b/tests/capsTests.py @@ -56,7 +56,7 @@ testPath = os.path.realpath(__file__) dirName = os.path.split(testPath)[0] path = os.path.join(dirName, "caps_libvirt.out") - t = caps.CpuTopology(path) + t = caps.CpuTopology(file(path).read()) self.assertEqual(t.threads(), 24) self.assertEqual(t.cores(), 12) self.assertEqual(t.sockets(), 2) diff --git a/vdsm/caps.py b/vdsm/caps.py index fdb06b1..4878f71 100644 --- a/vdsm/caps.py +++ b/vdsm/caps.py @@ -103,12 +103,15 @@ @utils.memoized +def _getCapsXMLStr(): + return libvirtconnection.get().getCapabilities() + + [email protected] def _getCpuTopology(capabilities): - if capabilities: - caps = minidom.parse(capabilities) - else: - c = libvirtconnection.get() - caps = minidom.parseString(c.getCapabilities()) + if capabilities is None: + capabilities = _getCapsXMLStr() + caps = minidom.parseString(capabilities) host = caps.getElementsByTagName('host')[0] cpu = host.getElementsByTagName('cpu')[0] cells = host.getElementsByTagName('cells')[0] @@ -123,8 +126,7 @@ @utils.memoized def _getEmulatedMachines(): - c = libvirtconnection.get() - caps = minidom.parseString(c.getCapabilities()) + caps = minidom.parseString(_getCapsXML()) guestTag = caps.getElementsByTagName('guest') # Guest element is missing if kvm modules are not loaded if len(guestTag) == 0: -- To view, visit http://gerrit.ovirt.org/9431 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I004693d64c84479f150f05d348b2e843f48238a4 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
