python3.5 subprocess.check_output() doesn't support encoding argument

Bug #1847574 reported by Hua Zhang
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Graylog Charm
Fix Released
Undecided
Unassigned
Snap Layer
Fix Released
Undecided
Unassigned

Bug Description

The command 'juju deploy cs:graylog-39 --config channel=3/stable --series xenial graylog2' will produce the following errors.

File "/var/lib/juju/agents/unit-graylog2-0/charm/reactive/graylog.py", line 95, in refresh_graylog
cur_snap = new_snap = snap.get_installed_version(SNAP_NAME)
File "lib/charms/layer/snap.py", line 256, in get_installed_version
return subprocess.check_output(cmd, encoding='utf-8').partition(
File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
**kwargs).stdout
File "/usr/lib/python3.5/subprocess.py", line 693, in run
with Popen(*popenargs, **kwargs) as process:
TypeError: __init__() got an unexpected keyword argument 'encoding'

but the command 'juju deploy cs:graylog-39 --config channel=3/stable --series bionic graylog' won't.

xenial uses python3.5 as default, while bionic uses python3.6 as default.
and I found the function check_output doesn't have the encoding argument in python3.5 according to the doc [1].

So after changing L256 of /var/lib/juju/agents/unit-graylog2-0/charm/lib/charms/layer/snap.py, graylog charm run well again.

from

return subprocess.check_output(cmd, encoding='utf-8').partition(
'installed:')[-1].split()[0]

to

return subprocess.check_output(cmd).decode('utf-8').partition(
'installed:')[-1].split()[0]

and above change can also run well in python3.6, so I think we should make this change to be compatible with python3.5 and python3.6 at the same time.

[1] https://docs.python.org/3.5/library/subprocess.html

Tags: sts

Related branches

Hua Zhang (zhhuabj)
description: updated
Hua Zhang (zhhuabj)
tags: added: sts
Changed in layer-snap:
status: New → In Progress
Stuart Bishop (stub)
Changed in layer-snap:
status: In Progress → Fix Released
Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Confirmed fixed in graylog/40

Stuart Bishop (stub)
Changed in graylog-charm:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.