From 89f7f07398e8219656fa7e25f7b1a32692b280a9 Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Thu, 26 Jan 2017 16:00:38 -0800 Subject: Bugfix: write_json_to_file: use json.dump with files In python3 file objects automatically handle encoding to utf-8 and expect string, not bytes, so use regular json.dump() with the file object We should only use dump_as_bytes to replace json.dumps(), not to replace json.dump() This fixes Python3 issue: Traceback (most recent call last): File "yardstick/main.py", line 52, in main() File "yardstick/main.py", line 49, in main YardstickCLI().main(sys.argv[1:]) File "yardstick/yardstick/cmd/cli.py", line 167, in main self._dispath_func_notask() File "yardstick/yardstick/cmd/cli.py", line 145, in _dispath_func_notask func(CONF.category) File "yardstick/yardstick/cmd/commands/task.py", line 48, in do_start self._init_result_file() File "yardstick/yardstick/cmd/commands/task.py", line 57, in _init_result_file write_json_to_file(consts.DEFAULT_OUTPUT_FILE, data) File "yardstick/yardstick/common/utils.py", line 152, in write_json_to_file write_file(path, jsonutils.dump_as_bytes(data), mode) File "yardstick/yardstick/common/utils.py", line 157, in write_file f.write(data) TypeError: write() argument must be str, not bytes Change-Id: I573419be25d8fa1f015e1507730ba66c05f86686 Signed-off-by: Ross Brattain --- yardstick/common/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'yardstick/common/utils.py') diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py index 473bbf540..174ac0a5a 100644 --- a/yardstick/common/utils.py +++ b/yardstick/common/utils.py @@ -149,7 +149,8 @@ def get_neutron_client(): def write_json_to_file(path, data, mode='w'): - write_file(path, jsonutils.dump_as_bytes(data), mode) + with open(path, mode) as f: + jsonutils.dump(data, f) def write_file(path, data, mode='w'): -- cgit 1.2.3-korg