Fix decoding on "get_cnf --json"
authorJuliana Rodrigueiro <juliana.rodrigueiro@intra2net.com>
Thu, 11 Mar 2021 13:37:51 +0000 (14:37 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 25 Mar 2021 09:52:29 +0000 (10:52 +0100)
The get_cnf command returns its output already in utf-8 when the
json switch is enabled. However the module cnfvar assumes that
raw data is always latin1, which is the case most of the time
when using arnied commands. This patch decodes the data, as we
know it is utf-8, before calling read_cnf_json.

Another caveat however, when the language locale is set to "C"
(which is currently the standard for avocado) before vm sessions
are started, every output (latin1 or utf-8) containing non ascii
characters will have those characters omitted (not garbled,
simply missing).

src/arnied_wrapper.py

index 713958f..73b242a 100644 (file)
@@ -472,6 +472,10 @@ def get_cnfvar(varname=None, instance=None, data=None, timeout=30, vm=None):
 
     # reading was successful, attempt to parse what we got
     try:
+        # The output from "get_cnf -j" is already utf-8. This contrast with
+        # the output of "get_cnf" (no json) which is latin1.
+        if isinstance(raw, bytes):
+            raw = raw.decode("utf-8")
         cnf = cnfvar.read_cnf_json(raw)
     except TypeError as exn:
         log.info("error \"%s\" parsing result of \"%s\"", exn, cmd_line)