iperf3: Fix parsing of incorrect json from iperf3
Change-Id: I759d99857c17de061e6d7c1ae1c38f6b15172131
diff --git a/src/osmo_gsm_tester/iperf3.py b/src/osmo_gsm_tester/iperf3.py
index 8141fea..e1ed6ff 100644
--- a/src/osmo_gsm_tester/iperf3.py
+++ b/src/osmo_gsm_tester/iperf3.py
@@ -24,6 +24,17 @@
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 @@
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 @@
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