From 3e8a85b029bc24416e17930d14800f840aadc39c Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Thu, 30 Sep 2021 23:36:27 -0400 Subject: [PATCH] Load benchmark results as JSON Load the JSON at the API side instead of client side, because that's what the API doc says it is and it just makes more sense. --- api-daemon/pvcapid/benchmark.py | 4 +++- client-cli/pvc/cli_lib/ceph.py | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/api-daemon/pvcapid/benchmark.py b/api-daemon/pvcapid/benchmark.py index dcec62a1..4c896aa6 100755 --- a/api-daemon/pvcapid/benchmark.py +++ b/api-daemon/pvcapid/benchmark.py @@ -78,6 +78,8 @@ def close_database(conn, cur, failed=False): def list_benchmarks(job=None): + from json import loads + if job is not None: query = "SELECT * FROM {} WHERE job = %s;".format('storage_benchmarks') args = (job, ) @@ -93,7 +95,7 @@ def list_benchmarks(job=None): benchmark_data = dict() benchmark_data['id'] = benchmark['id'] benchmark_data['job'] = benchmark['job'] - benchmark_data['benchmark_result'] = benchmark['result'] + benchmark_data['benchmark_result'] = loads(benchmark['result']) # Append the new data to our actual output structure data.append(benchmark_data) close_database(conn, cur) diff --git a/client-cli/pvc/cli_lib/ceph.py b/client-cli/pvc/cli_lib/ceph.py index 2f8b1ddc..5162ddf5 100644 --- a/client-cli/pvc/cli_lib/ceph.py +++ b/client-cli/pvc/cli_lib/ceph.py @@ -19,7 +19,6 @@ # ############################################################################### -import json import math from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor @@ -1479,12 +1478,12 @@ def format_list_benchmark(config, benchmark_information): if benchmark['benchmark_result'] == 'Running': continue - benchmark_data = json.loads(benchmark['benchmark_result']) + benchmark_data = benchmark['benchmark_result'] benchmark_bandwidth = dict() benchmark_iops = dict() for test in ["seq_read", "seq_write", "rand_read_4K", "rand_write_4K"]: - benchmark_data = json.loads(benchmark['benchmark_result']) + benchmark_data = benchmark['benchmark_result'] benchmark_bandwidth[test] = format_bytes_tohuman(int(benchmark_data[test]['overall']['bandwidth']) * 1024) benchmark_iops[test] = format_ops_tohuman(int(benchmark_data[test]['overall']['iops'])) @@ -1558,7 +1557,7 @@ def format_list_benchmark(config, benchmark_information): benchmark_bandwidth = dict() benchmark_iops = dict() for test in ["seq_read", "seq_write", "rand_read_4K", "rand_write_4K"]: - benchmark_data = json.loads(benchmark['benchmark_result']) + benchmark_data = benchmark['benchmark_result'] benchmark_bandwidth[test] = format_bytes_tohuman(int(benchmark_data[test]['overall']['bandwidth']) * 1024) benchmark_iops[test] = format_ops_tohuman(int(benchmark_data[test]['overall']['iops'])) @@ -1595,7 +1594,7 @@ def format_info_benchmark(config, benchmark_information): if benchmark_information[0]['benchmark_result'] == "Running": return "Benchmark test is still running." - benchmark_details = json.loads(benchmark_information[0]['benchmark_result']) + benchmark_details = benchmark_information[0]['benchmark_result'] # Format a nice output; do this line-by-line then concat the elements at the end ainformation = []