Change in osmo-gsm-tester[master]: iperf3: Fix parsing of incorrect json from iperf3

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Mon Nov 12 09:14:19 UTC 2018


Pau Espin Pedrol has submitted this change and it was merged. ( https://gerrit.osmocom.org/11712 )

Change subject: iperf3: Fix parsing of incorrect json from iperf3
......................................................................

iperf3: Fix parsing of incorrect json from iperf3

Change-Id: I759d99857c17de061e6d7c1ae1c38f6b15172131
---
M src/osmo_gsm_tester/iperf3.py
1 file changed, 13 insertions(+), 6 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



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

-- 
To view, visit https://gerrit.osmocom.org/11712
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I759d99857c17de061e6d7c1ae1c38f6b15172131
Gerrit-Change-Number: 11712
Gerrit-PatchSet: 2
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181112/130b09d4/attachment.htm>


More information about the gerrit-log mailing list