From 5853dd1ef3c522a975f9685250b1b3e85588f738 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Sat, 25 May 2019 09:38:40 +0200 Subject: Set utf-8 in decode and encode calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It eases backporting in iruya and hunter as a few logs can't be decoded as ascii [1]. [1] https://build.opnfv.org/ci/job/functest-opnfv-functest-vnf-iruya-juju_epc-run/56/console Change-Id: I52a6f9a25130cbf62e8ce3b9972064ab73177665 Signed-off-by: Cédric Ollivier --- functest/opnfv_tests/openstack/rally/rally.py | 18 +++++++++--------- .../opnfv_tests/openstack/refstack/refstack.py | 2 +- functest/opnfv_tests/openstack/shaker/shaker.py | 4 ++-- functest/opnfv_tests/openstack/tempest/tempest.py | 22 +++++++++++----------- functest/opnfv_tests/openstack/vmtp/vmtp.py | 6 +++--- 5 files changed, 26 insertions(+), 26 deletions(-) (limited to 'functest/opnfv_tests/openstack') diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py index 08e4a36c1..6dfdabec8 100644 --- a/functest/opnfv_tests/openstack/rally/rally.py +++ b/functest/opnfv_tests/openstack/rally/rally.py @@ -166,7 +166,7 @@ class RallyBase(singlevm.VmReady2): stdout=subprocess.PIPE, stderr=subprocess.STDOUT) deployment_uuid = proc.stdout.readline().rstrip() - return deployment_uuid.decode() + return deployment_uuid.decode("utf-8") @staticmethod def create_rally_deployment(environ=None): @@ -191,18 +191,18 @@ class RallyBase(singlevm.VmReady2): '--deployment', str(getattr(config.CONF, 'rally_deployment_name'))] output = subprocess.check_output(cmd) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) except subprocess.CalledProcessError: pass cmd = ['rally', 'deployment', 'create', '--fromenv', '--name', str(getattr(config.CONF, 'rally_deployment_name'))] output = subprocess.check_output(cmd, env=environ) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) cmd = ['rally', 'deployment', 'check'] output = subprocess.check_output(cmd) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) return RallyBase.get_verifier_deployment_id() @staticmethod @@ -240,7 +240,7 @@ class RallyBase(singlevm.VmReady2): taskid_re = re.compile('^Task +(.*): started$') for line in cmd_raw.splitlines(True): line = line.strip() - match = taskid_re.match(line.decode()) + match = taskid_re.match(line.decode("utf-8")) if match: return match.group(1) return None @@ -399,7 +399,7 @@ class RallyBase(singlevm.VmReady2): cmd = (["rally", "task", "detailed", "--uuid", task_id]) LOGGER.debug('running command: %s', cmd) output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) # save report as JSON report_json_name = '{}.json'.format(test_name) @@ -408,7 +408,7 @@ class RallyBase(singlevm.VmReady2): "--out", report_json_dir]) LOGGER.debug('running command: %s', cmd) output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) json_results = open(report_json_dir).read() self._append_summary(json_results, test_name) @@ -608,7 +608,7 @@ class RallyBase(singlevm.VmReady2): "--to", file_name] LOGGER.debug('running command: %s', cmd) output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) @staticmethod def verify_report(file_name, uuid, export_type="html"): @@ -624,7 +624,7 @@ class RallyBase(singlevm.VmReady2): "--uuid", uuid, "--to", file_name] LOGGER.debug('running command: %s', cmd) output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) def clean(self): """Cleanup of OpenStack resources. Should be called on completion.""" diff --git a/functest/opnfv_tests/openstack/refstack/refstack.py b/functest/opnfv_tests/openstack/refstack/refstack.py index 5e06c8c07..a58efcf99 100644 --- a/functest/opnfv_tests/openstack/refstack/refstack.py +++ b/functest/opnfv_tests/openstack/refstack/refstack.py @@ -52,7 +52,7 @@ class Refstack(tempest.TempestCommon): yaml_data2 = "" for line in output.splitlines(): try: - grp = re.search(r'^([^\[]*)(\[.*\])\n*$', line.decode()) + grp = re.search(r'^([^\[]*)(\[.*\])\n*$', line.decode("utf-8")) yaml_data2 = "{}\n{}: {}".format( yaml_data2, grp.group(1), grp.group(2)) except Exception: # pylint: disable=broad-except diff --git a/functest/opnfv_tests/openstack/shaker/shaker.py b/functest/opnfv_tests/openstack/shaker/shaker.py index 51ac88ae0..1ee669ce3 100644 --- a/functest/opnfv_tests/openstack/shaker/shaker.py +++ b/functest/opnfv_tests/openstack/shaker/shaker.py @@ -113,8 +113,8 @@ class Shaker(singlevm.SingleVm2): self.shaker_timeout, self.image.name, self.flavor.name, self.fip.floating_ip_address, self.ext_net.id, env.get('NAMESERVER'))) - self.__logger.info("output:\n%s", stdout.read().decode()) - self.__logger.info("error:\n%s", stderr.read().decode()) + self.__logger.info("output:\n%s", stdout.read().decode("utf-8")) + self.__logger.info("error:\n%s", stderr.read().decode("utf-8")) if not os.path.exists(self.res_dir): os.makedirs(self.res_dir) try: diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py index 69f7c2958..831f732d1 100644 --- a/functest/opnfv_tests/openstack/tempest/tempest.py +++ b/functest/opnfv_tests/openstack/tempest/tempest.py @@ -142,8 +142,8 @@ class TempestCommon(singlevm.VmReady2): stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in proc.stdout: - LOGGER.info(line.decode().rstrip()) - new_line = line.decode().replace(' ', '').split('|') + LOGGER.info(line.decode("utf-8").rstrip()) + new_line = line.decode("utf-8").replace(' ', '').split('|') if 'Tests' in new_line: break if 'Testscount' in new_line: @@ -175,7 +175,7 @@ class TempestCommon(singlevm.VmReady2): '--force'] try: output = subprocess.check_output(cmd) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) except subprocess.CalledProcessError: pass @@ -184,7 +184,7 @@ class TempestCommon(singlevm.VmReady2): '--name', str(getattr(config.CONF, 'tempest_verifier_name')), '--type', 'tempest', '--system-wide'] output = subprocess.check_output(cmd) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) return TempestCommon.get_verifier_id() @staticmethod @@ -199,7 +199,7 @@ class TempestCommon(singlevm.VmReady2): stdout=subprocess.PIPE, stderr=subprocess.STDOUT) verifier_uuid = proc.stdout.readline().rstrip() - return verifier_uuid.decode() + return verifier_uuid.decode("utf-8") @staticmethod def get_verifier_repo_dir(verifier_id): @@ -320,7 +320,7 @@ class TempestCommon(singlevm.VmReady2): cmd = ['rally', 'verify', 'configure-verifier', '--reconfigure', '--id', str(getattr(config.CONF, 'tempest_verifier_name'))] output = subprocess.check_output(cmd) - LOGGER.info("%s\n%s", " ".join(cmd), output.decode()) + LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8")) LOGGER.debug("Looking for tempest.conf file...") tempest_conf_file = os.path.join(deployment_dir, "tempest.conf") @@ -347,7 +347,7 @@ class TempestCommon(singlevm.VmReady2): cmd = "(cd {0}; stestr list '{1}' >{2} 2>/dev/null)".format( self.verifier_repo_dir, testr_mode, self.list) output = subprocess.check_output(cmd, shell=True) - LOGGER.info("%s\n%s", cmd, output.decode()) + LOGGER.info("%s\n%s", cmd, output.decode("utf-8")) os.remove('/etc/tempest.conf') def apply_tempest_blacklist(self): @@ -403,12 +403,12 @@ class TempestCommon(singlevm.VmReady2): with proc.stdout: for line in iter(proc.stdout.readline, b''): - if re.search(r"\} tempest\.", line.decode()): + if re.search(r"\} tempest\.", line.decode("utf-8")): LOGGER.info(line.rstrip()) - elif re.search(r'(?=\(UUID=(.*)\))', line.decode()): + elif re.search(r'(?=\(UUID=(.*)\))', line.decode("utf-8")): self.verification_id = re.search( - r'(?=\(UUID=(.*)\))', line.decode()).group(1) - f_stdout.write(line.decode()) + r'(?=\(UUID=(.*)\))', line.decode("utf-8")).group(1) + f_stdout.write(line.decode("utf-8")) proc.wait() f_stdout.close() diff --git a/functest/opnfv_tests/openstack/vmtp/vmtp.py b/functest/opnfv_tests/openstack/vmtp/vmtp.py index 71bda467a..f47884861 100644 --- a/functest/opnfv_tests/openstack/vmtp/vmtp.py +++ b/functest/opnfv_tests/openstack/vmtp/vmtp.py @@ -104,7 +104,7 @@ class Vmtp(singlevm.VmReady2): if not os.path.exists(self.res_dir): os.makedirs(self.res_dir) cmd = ['vmtp', '-sc'] - output = subprocess.check_output(cmd).decode() + output = subprocess.check_output(cmd).decode("utf-8") self.__logger.info("%s\n%s", " ".join(cmd), output) with open(self.config, "w+") as conf: vmtp_conf = yaml.full_load(output) @@ -146,12 +146,12 @@ class Vmtp(singlevm.VmReady2): cmd = ['vmtp', '-d', '--json', '{}/vmtp.json'.format(self.res_dir), '-c', self.config] output = subprocess.check_output( - cmd, stderr=subprocess.STDOUT, env=new_env).decode() + cmd, stderr=subprocess.STDOUT, env=new_env).decode("utf-8") self.__logger.info("%s\n%s", " ".join(cmd), output) cmd = ['vmtp_genchart', '-c', '{}/vmtp.html'.format(self.res_dir), '{}/vmtp.json'.format(self.res_dir)] output = subprocess.check_output( - cmd, stderr=subprocess.STDOUT).decode() + cmd, stderr=subprocess.STDOUT).decode("utf-8") self.__logger.info("%s\n%s", " ".join(cmd), output) with open('{}/vmtp.json'.format(self.res_dir), 'r') as res_file: self.details = json.load(res_file) -- cgit 1.2.3-korg