Skip to content

Commit

Permalink
Fix the py35 issue with json not accepting bytestrings (#387)
Browse files Browse the repository at this point in the history
So Python 3.6+ is magic, in that it will accept any str type
(str or bytes) in the json.loads() method.  Unfortunately, xenial
(py35) doesn't have this feature.  This patch correctly handles the
check_output output for the enabled_manager_modules() function.
  • Loading branch information
ajkavanagh authored and Liam Young committed Oct 14, 2019
1 parent 5dfcd05 commit 62eb4ce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions charmhelpers/contrib/storage/linux/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ def enabled_manager_modules():
cmd = ['ceph', 'mgr', 'module', 'ls']
try:
modules = check_output(cmd)
if six.PY3:
modules = modules.decode('UTF-8')
except CalledProcessError as e:
log("Failed to list ceph modules: {}".format(e), WARNING)
return []
Expand Down
2 changes: 1 addition & 1 deletion tests/contrib/storage/test_linux_ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _patch(self, method):
setattr(self, method, mock)

def test_enabled_manager_modules(self):
self.check_output.return_value = '{"enabled_modules": []}'
self.check_output.return_value = b'{"enabled_modules": []}'
ceph_utils.enabled_manager_modules()
self.check_output.assert_called_once_with(['ceph', 'mgr', 'module', 'ls'])

Expand Down

0 comments on commit 62eb4ce

Please sign in to comment.