From 64f0b1b1142ccddaabdc0bb168695b59ed60e504 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Fri, 9 Nov 2018 17:44:10 +0100 Subject: [PATCH] iperf3: Fix parsing of incorrect json from iperf3 Change-Id: I759d99857c17de061e6d7c1ae1c38f6b15172131 --- src/osmo_gsm_tester/iperf3.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/osmo_gsm_tester/iperf3.py b/src/osmo_gsm_tester/iperf3.py index 8141fea9..e1ed6ffc 100644 --- a/src/osmo_gsm_tester/iperf3.py +++ b/src/osmo_gsm_tester/iperf3.py @@ -24,6 +24,17 @@ from . import log, util, process, pcap_recorder DEFAULT_SRV_PORT = 5003 + +def iperf3_result_to_json(file): + with open(file) as f: + # Sometimes iperf3 provides 2 dictionaries, the 2nd one being an error about being interrupted (by us). + # json parser doesn't support (raises exception) parsing several dictionaries at a time (not a valid json object). + # We are only interested in the first dictionary, the regular results one: + d = f.read().split("\n}\n")[0] + "\n}\n" + data = json.loads(d) + return data + + class IPerf3Server(log.Origin): def __init__(self, suite_run, ip_address): @@ -55,9 +66,7 @@ class IPerf3Server(log.Origin): self.suite_run.stop_process(self.process) def get_results(self): - with open(self.log_file) as f: - data = json.load(f) - return data + return iperf3_result_to_json(self.log_file) def addr(self): return self.ip_address.get('addr') @@ -100,8 +109,6 @@ class IPerf3Client(log.Origin): return self.get_results() def get_results(self): - with open(self.log_file) as f: - data = json.load(f) - return data + return iperf3_result_to_json(self.log_file) # vim: expandtab tabstop=4 shiftwidth=4