Merge lp:~thedac/charm-helpers/lp1691881 into lp:charm-helpers

Proposed by David Ames
Status: Merged
Merged at revision: 749
Proposed branch: lp:~thedac/charm-helpers/lp1691881
Merge into: lp:charm-helpers
Diff against target: 16 lines (+3/-1)
1 file modified
charmhelpers/contrib/network/ip.py (+3/-1)
To merge this branch: bzr merge lp:~thedac/charm-helpers/lp1691881
Reviewer Review Type Date Requested Status
Alex Kavanagh Approve
Chris MacNaughton (community) Approve
Review via email: mp+324891@code.launchpad.net

Description of the change

Decode subprocess output for python3 in ipv6 check

When using python3, the code encounters errors related to type mismatch.
subprocess requires an extra decode of return values to address this.

Partial-Bug: #1691881

To post a comment you must log in.
Revision history for this message
Chris MacNaughton (chris.macnaughton) wrote :

Looks good to me

review: Approve
Revision history for this message
Alex Kavanagh (ajkavanagh) wrote :

Won't this generate a u"" on Python 2? In which case, that's a change in behaviour for Python 2, as subprocess.check_output(...) returns a str rather than a unicode.

I reckon a check should be done with six.PY3 and only perform the decode(...) in that situation.

review: Needs Fixing
lp:~thedac/charm-helpers/lp1691881 updated
749. By David Ames

Only perform UTF-8 decode if python3

Revision history for this message
Alex Kavanagh (ajkavanagh) wrote :

LGTM - thanks for making the change.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/network/ip.py'
2--- charmhelpers/contrib/network/ip.py 2017-04-25 17:13:19 +0000
3+++ charmhelpers/contrib/network/ip.py 2017-06-01 15:53:15 +0000
4@@ -244,9 +244,11 @@
5 result = subprocess.check_output(
6 ['sysctl', 'net.ipv6.conf.all.disable_ipv6'],
7 stderr=subprocess.STDOUT)
8- return "net.ipv6.conf.all.disable_ipv6 = 1" in result
9 except subprocess.CalledProcessError:
10 return True
11+ if six.PY3:
12+ result = result.decode('UTF-8')
13+ return "net.ipv6.conf.all.disable_ipv6 = 1" in result
14
15
16 def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False,

Subscribers

People subscribed via source and target branches