Commit 5f684d7f authored by Jaroslava Fiedlerova's avatar Jaroslava Fiedlerova

Improve error handling in Iperf_analyzeV3TCPJson()

parent 0ed8fb72
...@@ -96,19 +96,11 @@ def Iperf_ComputeTime(args): ...@@ -96,19 +96,11 @@ def Iperf_ComputeTime(args):
return int(result.group('iperf_time')) return int(result.group('iperf_time'))
def Iperf_analyzeV3TCPJson(filename, iperf_tcp_rate_target): def Iperf_analyzeV3TCPJson(filename, iperf_tcp_rate_target):
if (not os.path.isfile(filename)):
return (False, 'Iperf3 TCP: Log file not present')
if (os.path.getsize(filename)==0):
return (False, 'Iperf3 TCP: Log file is empty')
with open(filename) as file:
filename = json.load(file)
try: try:
sender_bitrate = round(filename['end']['streams'][0]['sender']['bits_per_second']/1000000,2) with open(filename) as f:
receiver_bitrate = round(filename['end']['streams'][0]['receiver']['bits_per_second']/1000000,2) results = json.load(f)
except Exception as e: sender_bitrate = round(results['end']['streams'][0]['sender']['bits_per_second'] / 1000000, 2)
return (False, 'Could not compute Iperf3 bitrate!') receiver_bitrate = round(results['end']['streams'][0]['receiver']['bits_per_second'] / 1000000, 2)
snd_msg = f'Sender Bitrate : {sender_bitrate} Mbps' snd_msg = f'Sender Bitrate : {sender_bitrate} Mbps'
rcv_msg = f'Receiver Bitrate : {receiver_bitrate} Mbps' rcv_msg = f'Receiver Bitrate : {receiver_bitrate} Mbps'
success = True success = True
...@@ -119,6 +111,11 @@ def Iperf_analyzeV3TCPJson(filename, iperf_tcp_rate_target): ...@@ -119,6 +111,11 @@ def Iperf_analyzeV3TCPJson(filename, iperf_tcp_rate_target):
else: else:
rcv_msg += f" (target : {iperf_tcp_rate_target} Mbps)" rcv_msg += f" (target : {iperf_tcp_rate_target} Mbps)"
return(success, f'{snd_msg}\n{rcv_msg}') return(success, f'{snd_msg}\n{rcv_msg}')
except KeyError as e:
e_msg = results.get('error', f'error report not found in {filename}')
return (False, f'While parsing Iperf3 results: missing key {e}, {e_msg}')
except Exception as e:
return (False, f'While parsing Iperf3 results: generic exception: {e}')
def Iperf_analyzeV3BIDIRJson(filename): def Iperf_analyzeV3BIDIRJson(filename):
if (not os.path.isfile(filename)): if (not os.path.isfile(filename)):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment