diff --git a/ironic_python_agent/tests/unit/test_utils.py b/ironic_python_agent/tests/unit/test_utils.py index 92a1a27e5..0fc3de941 100644 --- a/ironic_python_agent/tests/unit/test_utils.py +++ b/ironic_python_agent/tests/unit/test_utils.py @@ -27,6 +27,7 @@ import mock from oslo_concurrency import processutils from oslo_serialization import base64 from oslotest import base as test_base +import six import testtools from ironic_python_agent import errors @@ -385,6 +386,7 @@ class TestUtils(testtools.TestCase): contents = b'Squidward Tentacles' io_dict = {'fake-name': io.BytesIO(bytes(contents))} data = utils.gzip_and_b64encode(io_dict=io_dict) + self.assertIsInstance(data, six.text_type) res = io.BytesIO(base64.decode_as_bytes(data)) with tarfile.open(fileobj=res) as tar: diff --git a/ironic_python_agent/utils.py b/ironic_python_agent/utils.py index ddfe25caf..f09512707 100644 --- a/ironic_python_agent/utils.py +++ b/ironic_python_agent/utils.py @@ -383,7 +383,7 @@ def gzip_and_b64encode(io_dict=None, file_list=None): tar.add(f) fp.seek(0) - return base64.encode_as_bytes(fp.getvalue()) + return base64.encode_as_text(fp.getvalue()) def collect_system_logs(journald_max_lines=None): diff --git a/releasenotes/notes/fix-bytes-json-serializable-collected-logs-ad61022b287dc3e2.yaml b/releasenotes/notes/fix-bytes-json-serializable-collected-logs-ad61022b287dc3e2.yaml new file mode 100644 index 000000000..a959ca813 --- /dev/null +++ b/releasenotes/notes/fix-bytes-json-serializable-collected-logs-ad61022b287dc3e2.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - JSON serialization of logs collected for ironic-python-agent. + In python3 logs were encoded as byte strings, which can't be serialized. + Make sure that logs are encoded as text for both py2.7 and py3. See + https://bugs.launchpad.net/ironic-python-agent/+bug/1668533 for details.