[Libvirt-cim] Problem of Python dependancies

Daniel Veillard veillard at redhat.com
Fri Aug 14 08:00:19 UTC 2009


  Hi,

trying to run the testsuite as checkout from hg today on a Fedora 11
box I got the following error:

[root at paphio cimtest]# CIM_NS=root/virt CIM_USER=root CIM_PASS=xxxxxx
./runtests libvirt-cim -v KVM -i  localhost
Starting test suite: libvirt-cim
Traceback (most recent call last):
  File "main.py", line 41, in <module>
    from XenKvmLib.common_util import create_netpool_conf,
destroy_netpool, \
  File "./lib/XenKvmLib/common_util.py", line 29, in <module>
    from XenKvmLib.test_xml import *
  File "./lib/XenKvmLib/test_xml.py", line 32, in <module>
    from xml import xpath
ImportError: cannot import name xpath

 Looking at suites/libvirt-cim/lib/XenKvmLib/test_xml.py
it seems to try to use the native xml support of Python

from xml import xpath
from xml.dom import minidom, Node

to implement:

------------------------------------------------
def get_value_xpath(xmlStr, xpathStr):
    xmldoc = minidom.parseString(xmlStr)
    nodes = xpath.Evaluate(xpathStr, xmldoc.documentElement)

    if len(nodes) != 1:
        raise LookupError('Zero or multiple xpath results found!')

    node = nodes[0]
    if node.nodeType == Node.ATTRIBUTE_NODE:
        return node.value
    if node.nodeType == Node.TEXT_NODE:
        return node.toxml()
    if node.nodeType == Node.ELEMENT_NODE:
        ret = ''
        for child in node.childNodes:
            ret = ret + child.toxml()
        return ret
--------------------------------------------------

 Then get_value_xpath() is used in the module to poke various values.
First it's not really optimal, the XML should probably be parsed once
but the performance impact is really neglectible :-)

  Is there a workaround to have that code run on a standard Fedora 11
setup or did I missed anything ?

  I wonder if there are other uses of xml::xpath in the regression
suite. In any case it might be a good idea to use libxml2 bindings
instead since libvirt uses libxml2 it's not likely to be a problem
and would avoid this kind of Python XML portability problems. I may
even provide the trivial patch to replace that fragment of code (but
if there is many other use of python xml code in the test suite, that's
a different matter :-)

  thanks,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the Libvirt-cim mailing list