]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa/core/case.py: Encode binary data of log
authorNathan Rossi <nathan@nathanrossi.com>
Fri, 27 Sep 2019 05:31:08 +0000 (05:31 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 27 Sep 2019 12:35:26 +0000 (13:35 +0100)
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@nathanrossi.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/core/case.py
scripts/lib/resulttool/resultutils.py

index 180635ac6c66edc607828aa317d204caaa0a7c08..aae451fef2b46c986e92e356126a37c981d7fff6 100644 (file)
@@ -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:
index 177fb25f933b6aa0a360ce16c5473b3d6363a1c1..7cb85a6aa91ac17ebdaf022363b5d6bee17f0f7d 100644 (file)
@@ -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):