[Libvirt-cim] [PATCH] [TEST] .#2 add a try..except to get_value_xpath()

zli at linux.vnet.ibm.com zli at linux.vnet.ibm.com
Wed Apr 9 10:36:32 UTC 2008


# HG changeset patch
# User Zhengang Li <lizg at cn.ibm.com>
# Date 1207737380 -28800
# Node ID fb3e043e7425a319730e6e11d05ee031ce4ab1ca
# Parent  262153788503c8b10c76c77719bba081df9a7b88
[TEST] .#2 add a try..except to get_value_xpath()

A 'None' return is more elegant than a pure exception error.

Use logger.error
typo fix. :)

Signed-off-by: Zhengang Li <lizg at cn.ibm.com>

diff -r 262153788503 -r fb3e043e7425 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Tue Apr 08 17:58:44 2008 +0530
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Wed Apr 09 18:36:20 2008 +0800
@@ -115,7 +115,12 @@ class XMLClass:
         return self.xdoc.toprettyxml()
 
     def get_value_xpath(self, xpathStr):
-        node = self.get_node(xpathStr)
+        try:
+            node = self.get_node(xpathStr)
+        except LookUpError:
+            logger.error('Zero or multiple node found')
+            return None
+
         if node.nodeType == Node.ATTRIBUTE_NODE:
             return node.value
         if node.nodeType == Node.TEXT_NODE:




More information about the Libvirt-cim mailing list