New issue 59 by snmp1612342: netaddr 0.7.4-1 fails to load when imported by
a PowerDNS coprocess.
http://code.google.com/p/netaddr/issues/detail?id=59
What steps will reproduce the problem?
1. running a python script using netaddr as a PowerDNS coprocess
2.
3.
What is the expected output? What do you see instead?
it runs fine from the shell...
root@mandelbrot:~# python
Python 2.6.6 (r266:84292, Aug 29 2010, 19:11:12)
[GCC 4.4.5 20100824 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import netaddr
however when triggered via powerdns...
import _ssl # builtin
# /usr/lib/pymodules/python2.6/netaddr/strategy/ipv6.pyc matches
/usr/lib/pymodules/python2.6/netaddr/strategy/ipv6.py
import netaddr.strategy.ipv6 # precompiled from
/usr/lib/pymodules/python2.6/netaddr/strategy/ipv6.pyc
Traceback (most recent call last):
File "/etc/powerdns/pdns-ipv6-reverse-backend.py", line 47, in <module>
import netaddr
File "/usr/lib/pymodules/python2.6/netaddr/__init__.py", line 18, in
<module>
from netaddr.ip import IPAddress, IPNetwork, IPRange,
all_matching_cidrs, \
File "/usr/lib/pymodules/python2.6/netaddr/ip/__init__.py", line 1876, in
<module>
IPV6_LOOPBACK = IPAddress('::1')
File "/usr/lib/pymodules/python2.6/netaddr/ip/__init__.py", line 262, in
__init__
self.value = addr
File "/usr/lib/pymodules/python2.6/netaddr/ip/__init__.py", line 278, in
_set_value
self._value = module.str_to_int(value)
File "/usr/lib/pymodules/python2.6/netaddr/strategy/ipv4.py", line 100,
in str_to_int
if hasattr(addr, 'lower') and _platform.system() == 'Windows':
File "/usr/lib/python2.6/platform.py", line 1295, in system
return uname()[0]
File "/usr/lib/python2.6/platform.py", line 1262, in uname
processor = _syscmd_uname('-p','')
File "/usr/lib/python2.6/platform.py", line 1019, in _syscmd_uname
rc = f.close()
nothing fancy going on before import netaddr.
What version of the product are you using? On what operating system?
ii python-netaddr 0.7.4-1
manipulation of various common network
address notations
hi pdns 3.0-pre-1
extremely powerful and versatile nameserver
hi pdns-backend-mysql 3.0-pre-1
MySQL backend for pDNS
hi pdns-backend-pipe 3.0-pre-1
pipe/coprocess backend for pDNS
root@mandelbrot:~# cat /etc/debian_version
squeeze/sid
root@mandelbrot:~# uname -p
unknown
root@mandelbrot:~# uname -a
Linux mandelbrot 2.6.32-3-vserver-686 #1 SMP Thu Feb 25 08:13:24 UTC 2010
i686 GNU/Linux
Please provide any additional information below.
-> http://doc.powerdns.com/pipebackend-dynamic-resolution.html
def str_to_int(addr):
"""
@param addr: An IPv4 dotted decimal address in string form.
@return: The equivalent unsigned integer for a given IPv4 address.
"""
if addr == '':
raise AddrFormatError('Empty strings are not supported!')
try:
return _struct.unpack('>I', _inet_aton(addr))[0]
except:
# Windows platform workaround.
if hasattr(addr, 'lower') and _platform.system() == 'Windows':
if addr.lower() == '0xffffffff':
return 0xffffffff
raise AddrFormatError('%r is not a valid IPv4 address string!' \
% addr)
well i'm simply not sure if you should rely on the platform module there.
i am pretty sure that i am not running a windows system though
i just commented out your dodgy windows platform workaround if clause and
now it works
and no, i am still not running windows. ;-)
Comment #2 on issue 59 by drkjam: netaddr 0.7.4-1 fails to load when
imported by a PowerDNS coprocess.
http://code.google.com/p/netaddr/issues/detail?id=59
Looks like the shell out to uname -p isn't working through PowerDNS.
Can you try using sys.platform == 'win32' for me instead to let me know how
that goes?
If it's OK I'll make this change for the next release.
PS - I'll also move the call outside of this function so it only gets
invoked once on module import!
Next release is fine for me ofc.
Sorry for calling the if dodgy btw.
sys.platform is read-only i fear.
-> http://docs.python.org/library/sys.html#sys.platform
"For Unix systems, this is the lowercased OS name as returned by uname -s
with the first part of the version as returned by uname -r appended,
e.g. 'sunos5' or 'linux2', at the time when Python was built. "
pythonroot@mandelbrot:~# python
Python 2.6.6 (r266:84292, Aug 29 2010, 19:11:12)
[GCC 4.4.5 20100824 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.platform
'linux2'
>>> sys.platform == 'win32'
False
>>> sys.platform
'linux2'
as for PowerDNS:
import sys, os
import re
import syslog
import time
so=sys.platform == 'win32'
print >> sys.stderr, "so returned:", so
print >> sys.stderr, "sys.platform:", sys.platform
import netaddr
gave:
so returned: False
sys.platform: linux2
a
try:
f=os.popen('uname -p 2>/dev/null')
print >> sys.stderr, f.read()
except (AttributeError,os.error):
print >> sys.stderr, "well this did not work with os.error"
returns
"unknown
"
Comment #4 on issue 59 by drkjam: netaddr 0.7.4-1 fails to load when
imported by a PowerDNS coprocess.
http://code.google.com/p/netaddr/issues/detail?id=59
Should now be fixed in 0.7.x branch on github available here :-
http://github.com/drkjam/netaddr
Please test and let me know if all looks good.