Maintained by: NLnet Labs

[Unbound-users] issue with pythonmodule

Tom Hendrikx
Mon Aug 8 21:39:38 CEST 2011


On 22/07/11 13:10, Tom Hendrikx wrote:
> On 22/07/11 05:07, Paul Wouters wrote:
>> On Fri, 22 Jul 2011, Tom Hendrikx wrote:
>>
>>> ImportError: No module named unboundmodule
>>
>>
>>> After some debugging I realised that unbound is unable to find the
>>> unboundmodule.py file that is placed in
>>> /usr/lib64/python2.7/site-packages. I was able to temporarily resolve
>>> this by adding a symlink to the python file in /etc/unbound/, but this
>>> is of course a hack.
>>>
>>> Since the file is placed in /usr/lib64/python2.7/site-packages/ by the
>>> Makefile, it looks as if there is no special adaption done by the distro
>>> package. This is why I am asking my question here first ;)
>>
>> Thanks for reporting this.
>>
>> I can confirm this problem is present in the fedora/rhel/centos package.
>> Though for me, on x86_64 it is placed in:
>>
>> /usr/lib/python2.7/site-packages/unboundmodule.py
>>
>> I can confirm linking it in /etc/unbound resolves this.
>>
>> I changed the %configure from using  --with-pythonmodule to use:
>>
>>      --with-pythonmodule=%{python_sitearch}
>>
>> which expands to:
>>
>>     --with-pythonmodule=/usr/lib64/python2.7/site-packages
>>
>> but it seems unbound still places the files in the wrong location when
>> running "make install" and places the sitearch files in the sitelib
>> directory
>>
>> Makefile.inc shows:
>>
>>         $(INSTALL) -c -m 644 pythonmod/unboundmodule.py
>> $(DESTDIR)$(PYTHON_SITE_PKG)/unboundmodule.py
>>
>> PYTHON_SITE_PKG is set to:
>>
>>  python -c "import distutils.sysconfig; print
>> distutils.sysconfig.get_python_lib(0,0);"
>> /usr/lib/python2.7/site-packages
>>
>> However, the unbound daemon does not seem to look there......
>>
>> Note that /usr/lib/python2.7/site-packages/_unbound.so.2.12.0 also seems
>> to be in the 32 instead of
>> the 64 bit location....
> 
> I'm no expert on this, but AFAIK, the /usr/lib/ contents depends on the
> arch of the host (i.e. on x86_64 it will contain 64-bit libraries).On
> gentoo x86_64, there are /usr/lib32 and /usr/lib64 locations, with
> /usr/lib being a symlink to the latter.
> 
> Unbound searching in /usr/lib/ would work for me, and seems reasonable.
> 
>>
>> A grep shows me :
>>
>> [paul at bofh unbound-1.4.12rc1]$ grep get_python_lib *
>> acx_python.m4:                        print '-L' + get_python_lib(0,1), \
>> acx_python.m4:                        '-L' +
>> os.path.dirname(get_python_lib(0,1)), \
>> acx_python.m4:                        print
>> distutils.sysconfig.get_python_lib(0,0);"`
>> configure:                        print '-L' + get_python_lib(0,1), \
>> configure:                        '-L' +
>> os.path.dirname(get_python_lib(0,1)), \
>> configure:                        print
>> distutils.sysconfig.get_python_lib(0,0);
>>
>> The first argument to get_python_lib is a boolean for plat_specific=
>> If I change that to 1, then it seems the files are installed in their
>> right locations:
>>
>> [root at bofh unbound]# rpm -ql unbound-python
>> /usr/lib64/python2.7/site-packages/_unbound.so
>> /usr/lib64/python2.7/site-packages/_unbound.so.2
>> /usr/lib64/python2.7/site-packages/_unbound.so.2.12.0
>> /usr/lib64/python2.7/site-packages/unbound.py
>> /usr/lib64/python2.7/site-packages/unbound.pyc
>> /usr/lib64/python2.7/site-packages/unbound.pyo
>> /usr/lib64/python2.7/site-packages/unboundmodule.py
>> /usr/lib64/python2.7/site-packages/unboundmodule.pyc
>> /usr/lib64/python2.7/site-packages/unboundmodule.pyo
>>
>> but it seems the python module still fails to initialise:
>>
>> Jul 21 22:59:47 libunbound[846:0] notice: init module 1: python
>> Traceback (most recent call last):
>>   File "<string>", line 1, in <module>
>> ImportError: No module named unboundmodule
>> Jul 21 22:59:47 libunbound[846:0] error: pythonmod: cannot initialize
>> core module: unboundmodule.py
>> Jul 21 22:59:47 libunbound[846:0] error: module init for module python
>> failed
>> resolve error: initialization failure
>>
>> The search path in strace of unbound-host shows:
>>
>> [root at bofh unbound]# grep unboundmodule out
>> stat("/usr/lib64/python2.7/unboundmodule", 0x7fff16839290) = -1 ENOENT
>> (No such file or directory)
>> open("/usr/lib64/python2.7/unboundmodule.so", O_RDONLY) = -1 ENOENT (No
>> such file or directory)
>> open("/usr/lib64/python2.7/unboundmodulemodule.so", O_RDONLY) = -1
>> ENOENT (No such file or directory)
>> open("/usr/lib64/python2.7/unboundmodule.py", O_RDONLY) = -1 ENOENT (No
>> such file or directory)
>> open("/usr/lib64/python2.7/unboundmodule.pyc", O_RDONLY) = -1 ENOENT (No
>> such file or directory)
>> stat("/usr/lib64/python2.7/plat-linux2/unboundmodule", 0x7fff16839290) =
>> -1 ENOENT (No such file or directory)
>> open("/usr/lib64/python2.7/plat-linux2/unboundmodule.so", O_RDONLY) = -1
>> ENOENT (No such file or directory)
>> open("/usr/lib64/python2.7/plat-linux2/unboundmodulemodule.so",
>> O_RDONLY) = -1 ENOENT (No such file or directory)
>> open("/usr/lib64/python2.7/plat-linux2/unboundmodule.py", O_RDONLY) = -1
>> ENOENT (No such file or directory)
>> open("/usr/lib64/python2.7/plat-linux2/unboundmodule.pyc", O_RDONLY) =
>> -1 ENOENT (No such file or directory)
>> stat("/usr/lib64/python2.7/lib-dynload/unboundmodule", 0x7fff16839290) =
>> -1 ENOENT (No such file or directory)
>> open("/usr/lib64/python2.7/lib-dynload/unboundmodule.so", O_RDONLY) = -1
>> ENOENT (No such file or directory)
>> open("/usr/lib64/python2.7/lib-dynload/unboundmodulemodule.so",
>> O_RDONLY) = -1 ENOENT (No such file or directory)
>> open("/usr/lib64/python2.7/lib-dynload/unboundmodule.py", O_RDONLY) = -1
>> ENOENT (No such file or directory)
>> open("/usr/lib64/python2.7/lib-dynload/unboundmodule.pyc", O_RDONLY) =
>> -1 ENOENT (No such file or directory)
>> stat("./unboundmodule", 0x7fff16839290) = -1 ENOENT (No such file or
>> directory)
>> open("./unboundmodule.so", O_RDONLY)    = -1 ENOENT (No such file or
>> directory)
>> open("./unboundmodulemodule.so", O_RDONLY) = -1 ENOENT (No such file or
>> directory)
>> open("./unboundmodule.py", O_RDONLY)    = -1 ENOENT (No such file or
>> directory)
>> open("./unboundmodule.pyc", O_RDONLY)   = -1 ENOENT (No such file or di
>>
>> and then finally /etc/unbound/
>>
>> I'm not sure yet why it is not searching in
>> /usr/lib64/python2.7/site-packages/ first
>>
>> I also think that the value for --with-pythonmodule seems to be lost
>> during make install
>>
> 
> I agree this is the problem: unbound never checks the site-packages/
> directory. I did the same tests here, even with passing the correct path
> to ./configure using --with-pythonmodule, but unbound never goes there.
> 
> Passing the path to --with-pythonmodule is undocumented (as far as
> ./configure --help concerns), but since make install seems to figure out
> the (correct?) install location in site-packages/,  it seems to me that
> passing in the path to ./configure is not really necessary. But it would
> be logical that the rest of the unbound package would use this path too
> when needed, which is currently not the case.
> 

I did some more research on this and I think I found the culprit.
Attached is a patch against unbound 1.4.12 that adds the site-packages
dir to the search path when initialising the python module.

With this patch, things Work For Me (tm) :)

--
Regards
	Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pythonmod_check_site-packages_dir.patch
Type: text/x-patch
Size: 549 bytes
Desc: not available
URL: <http://unbound.nlnetlabs.nl/pipermail/unbound-users/attachments/20110808/a2d14d1a/attachment.bin>