network script fails on 12.04.5 if python3 is not installed
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Checkbox Provider - Base |
Fix Released
|
High
|
Jeff Lane |
Bug Description
This was seen on a test using 12.04.5. The network test throws a traceback as seen below:
Traceback (most recent call last):
File "/tmp/nest-
sys.
File "/tmp/nest-
return args.func(args)
File "/tmp/nest-
if not can_ping(
File "/tmp/nest-
stdout=
AttributeError: 'module' object has no attribute 'DEVNULL'
The line in question is this:
check_call(["ping", "-I", the_interface, "-c", "1", test_target],
So I tried that out using ipython3 and ipython2 (on a 14.04.1 machine)
ipython3:
bladernr@klaatu:~$ ipython3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
<SNIP>
In [4]: subprocess.
Out[4]: 0
And now the same on ipython2:
bladernr@klaatu:~$ ipython
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
<SNIP>
In [1]: import subprocess
In [2]: subprocess.
-------
AttributeError Traceback (most recent call last)
<ipython-
----> 1 subprocess.
AttributeError: 'module' object has no attribute 'DEVNULL'
So this is an issue with the script apparently running in python2?
Looking at the script itself, it explicitly calls python3:
#!/usr/bin/env python3
Not sure what exactly is the cause here though :(
Related branches
- Daniel Manrique (community): Approve
- Zygmunt Krynicki (community): Approve
-
Diff: 66 lines (+13/-8)1 file modifiedproviders/plainbox-provider-checkbox/bin/network (+13/-8)
- Pierre Equoy: Approve
-
Diff: 99 lines (+8/-8)8 files modifiedcheckbox-ng/checkbox_ng/__init__.py (+1/-1)
checkbox-ng/setup.py (+1/-1)
checkbox-support/setup.py (+1/-1)
plainbox/plainbox/__init__.py (+1/-1)
plainbox/setup.py (+1/-1)
providers/plainbox-provider-checkbox/manage.py (+1/-1)
providers/plainbox-provider-resource-generic/manage.py (+1/-1)
providers/plainbox-provider-sru/manage.py (+1/-1)
Changed in plainbox-provider-checkbox: | |
assignee: | nobody → Jeff Lane (bladernr) |
status: | Triaged → In Progress |
Changed in plainbox-provider-checkbox: | |
status: | In Progress → Fix Committed |
milestone: | none → 0.16 |
Changed in plainbox-provider-checkbox: | |
status: | Fix Committed → Fix Released |
The cause is that subprocess.DEVNULL is not defined on 12.04.5's python 3.2.3 ;( Per the documentation:
subprocess.DEVNULL
Special value that can be used as the stdin, stdout or stderr argument to Popen and indicates that the special file os.devnull will be used.
New in version 3.3.
Also, behold:
ubuntu@ precise- p3-test: ~$ python3
Python 3.2.3 (default, Feb 27 2014, 21:31:18)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.DEVNULL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'DEVNULL'
>>>
To contrast, on 14.04:
roadmr@blackdog:~$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.DEVNULL
-3
>>>
So work to do: figure out a way to replace subprocess.DEVNULL that's compatible with 3.2. Maybe:
try:
null = subprocess.DEVNULL
except AttributeError:
# oops, on 3.2
null = os.devnull
subprocess. check_call( ["ping" , "-I", "eth0", "-c", "1", "192.168.0.10"], stdout=null, stderr=null)
I'm not sure if the semantics of using os.devnull (which seems to be what subprocess.DEVNULL does) are the same as simply using os.devnull; optionally, the integer value of subprocess.DEVNULL is -3, so we could simply assign that in the "except" block, but I worry that the rest of the code interpreting that value is also not present on 3.2.
Anyway, a simple way to reproduce this for me was to create a precise lxc container and install python3 in that, maybe it will come in handy:
sudo lxc-create -n precise-python3 -t ubuntu -- -r precise
sudo lxc-start -d -n precise-python3
sudo lxc-attach -n precise-python3