Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions cloudinit/cmd/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,11 @@ def load_userdata(ud_file_path):

@returns: String of uncompressed userdata if possible, otherwise bytes.
"""
bdata = util.load_file(ud_file_path, decode=False)
try:
return util.load_file(ud_file_path)
return bdata.decode('utf-8')
except UnicodeDecodeError:
encoded_data = util.load_file(ud_file_path, decode=False)
try:
return util.decomp_gzip(encoded_data, quiet=False)
except util.DecompressionError:
return encoded_data
return util.decomp_gzip(bdata, quiet=False, decode=True)


def handle_args(name, args):
Expand Down
5 changes: 0 additions & 5 deletions cloudinit/cmd/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ def test_handle_args_root_fallsback_to_instance_data(self, caplog, tmpdir):
('ud'.encode('utf-8'), 'ud', 'vd'.encode('utf-8'), 'vd'),
(_gzip_data(b'ud'), 'ud', _gzip_data(b'vd'), 'vd'),
(_gzip_data('ud'.encode('utf-8')), 'ud', _gzip_data(b'vd'), 'vd'),
(_gzip_data(b'ud') + b'invalid', 'ci-b64:',
_gzip_data(b'vd') + b'invalid', 'ci-b64:'),
# non-utf-8 encodable content
('hi mom'.encode('utf-16'), 'ci-b64://5oAGkAIABtAG8AbQA=',
'hi pops'.encode('utf-16'), 'ci-b64://5oAGkAIABwAG8AcABzAA=='),
)
)
def test_handle_args_root_processes_user_data(
Expand Down