[oe-commits] [openembedded-core] 02/10: oeqa/core/case.py: Encode binary data of log

git at git.openembedded.org git at git.openembedded.org
Fri Sep 27 12:40:02 UTC 2019


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 20531dc0b8f76a6e37cc856f36cd94077b6aba50
Author: Nathan Rossi <nathan at nathanrossi.com>
AuthorDate: Fri Sep 27 05:31:08 2019 +0000

    oeqa/core/case.py: Encode binary data of log
    
    Do not decode the log content into a string only to re-encode it as
    binary data again. Some logs might un-intentionally contain bytes that
    do not decode as utf-8, as such preserve the log file content as it was
    on disk.
    
    Handle the decoding on the resulttool side, but also handle the failure
    to decode the data.
    
    Signed-off-by: Nathan Rossi <nathan at nathanrossi.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oeqa/core/case.py            | 4 ++--
 scripts/lib/resulttool/resultutils.py | 6 +++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/meta/lib/oeqa/core/case.py b/meta/lib/oeqa/core/case.py
index 180635a..aae451f 100644
--- a/meta/lib/oeqa/core/case.py
+++ b/meta/lib/oeqa/core/case.py
@@ -59,7 +59,7 @@ class OEPTestResultTestCase:
     """
     @staticmethod
     def _compress_log(log):
-        logdata = log.encode("utf-8")
+        logdata = log.encode("utf-8") if isinstance(log, str) else log
         logdata = zlib.compress(logdata)
         logdata = base64.b64encode(logdata).decode("utf-8")
         return {"compressed" : logdata}
@@ -80,7 +80,7 @@ class OEPTestResultTestCase:
         if log is not None:
             sections[section]["log"] = self._compress_log(log)
         elif logfile is not None:
-            with open(logfile, "r") as f:
+            with open(logfile, "rb") as f:
                 sections[section]["log"] = self._compress_log(f.read())
 
         if duration is not None:
diff --git a/scripts/lib/resulttool/resultutils.py b/scripts/lib/resulttool/resultutils.py
index 177fb25..7cb85a6 100644
--- a/scripts/lib/resulttool/resultutils.py
+++ b/scripts/lib/resulttool/resultutils.py
@@ -126,7 +126,11 @@ def decode_log(logdata):
         if "compressed" in logdata:
             data = logdata.get("compressed")
             data = base64.b64decode(data.encode("utf-8"))
-            return zlib.decompress(data).decode("utf-8")
+            data = zlib.decompress(data)
+            try:
+                return data.decode("utf-8")
+            except UnicodeDecodeError:
+                return data
     return None
 
 def ptestresult_get_log(results, section):

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list