UnitSentry.file_contents() breaks for non-utf8 files

Bug #1456504 reported by Björn Tillenius
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Amulet
New
Undecided
Unassigned

Bug Description

If you try to get a binary file using UnitSentry.file_contents, if will break with a
UnicodeDecodeError, since it always tried to decode the contents using UTF-8.

Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/usr/lib/python3.4/unittest/case.py", line 574, in run
    testMethod()
  File "/home/bjorn/projects/landscape-charm/trunk/tests/basic/test_service.py", line 126, in test_error_pages
    haproxy_path + http_code + ".http", "haproxy/0"),
  File "/home/bjorn/projects/landscape-charm/trunk/tests/helpers.py", line 94, in get_file
    return unit_sentry.file_contents(path)
  File "/usr/lib/python3/dist-packages/amulet/sentry.py", line 81, in file_contents
    output, return_code = self._run('cat {}'.format(filename))
  File "/usr/lib/python3/dist-packages/amulet/sentry.py", line 118, in _run
    return output.decode('utf8'), p.returncode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 72: invalid start byte

There should be a way to get binary files as well as text files.

Tags: landscape
tags: added: landscape
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.