From 35072357d8294230fad5633c6643a7a839eb89c6 Mon Sep 17 00:00:00 2001 From: Juliana Rodrigueiro Date: Thu, 11 Mar 2021 14:37:51 +0100 Subject: [PATCH] Fix decoding on "get_cnf --json" 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 | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/src/arnied_wrapper.py b/src/arnied_wrapper.py index 713958f..73b242a 100644 --- a/src/arnied_wrapper.py +++ b/src/arnied_wrapper.py @@ -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) -- 1.7.1