Commit 89aad980 authored by Jaroslava Fiedlerova's avatar Jaroslava Fiedlerova

Merge remote-tracking branch 'origin/ci-iperf3-json-fix' into integration_2024_w31

parents 0a5e8b76 12229ef5
...@@ -96,45 +96,44 @@ def Iperf_ComputeTime(args): ...@@ -96,45 +96,44 @@ 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)): try:
return (False, 'Iperf3 TCP: Log file not present') with open(filename) as f:
if (os.path.getsize(filename)==0): results = json.load(f)
return (False, 'Iperf3 TCP: Log file is empty') sender_bitrate = round(results['end']['streams'][0]['sender']['bits_per_second'] / 1000000, 2)
receiver_bitrate = round(results['end']['streams'][0]['receiver']['bits_per_second'] / 1000000, 2)
with open(filename) as file: except json.JSONDecodeError as e:
filename = json.load(file) return (False, f'Could not decode JSON log file {filename}: {e}')
try: except KeyError as e:
sender_bitrate = round(filename['end']['streams'][0]['sender']['bits_per_second']/1000000,2) e_msg = results.get('error', f'error report not found in {filename}')
receiver_bitrate = round(filename['end']['streams'][0]['receiver']['bits_per_second']/1000000,2) return (False, f'While parsing Iperf3 results: missing key {e}, {e_msg}')
except Exception as e: except Exception as e:
return (False, 'Could not compute Iperf3 bitrate!') return (False, f'While parsing Iperf3 results: exception: {e}')
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
if (iperf_tcp_rate_target is not None): if iperf_tcp_rate_target is not None:
if (int(receiver_bitrate) < int(iperf_tcp_rate_target)): success = float(receiver_bitrate) >= float(iperf_tcp_rate_target)
rcv_msg += f" (too low! < {iperf_tcp_rate_target} Mbps)" if success:
success = False rcv_msg += f" (target: {iperf_tcp_rate_target})"
else: else:
rcv_msg += f" (target : {iperf_tcp_rate_target} Mbps)" rcv_msg += f" (too low! < {iperf_tcp_rate_target})"
return(success, f'{snd_msg}\n{rcv_msg}') return(success, f'{snd_msg}\n{rcv_msg}')
def Iperf_analyzeV3BIDIRJson(filename): def Iperf_analyzeV3BIDIRJson(filename):
if (not os.path.isfile(filename)): try:
return (False, 'Iperf3 Bidir TCP: Log file not present') with open(filename) as f:
if (os.path.getsize(filename)==0): results = json.load(f)
return (False, 'Iperf3 Bidir TCP: Log file is empty') sender_bitrate_ul = round(results['end']['streams'][0]['sender']['bits_per_second'] / 1000000, 2)
receiver_bitrate_ul = round(results['end']['streams'][0]['receiver']['bits_per_second'] / 1000000, 2)
with open(filename) as file: sender_bitrate_dl = round(results['end']['streams'][1]['sender']['bits_per_second'] / 1000000, 2)
filename = json.load(file) receiver_bitrate_dl = round(results['end']['streams'][1]['receiver']['bits_per_second'] / 1000000, 2)
try: except json.JSONDecodeError as e:
sender_bitrate_ul = round(filename['end']['streams'][0]['sender']['bits_per_second']/1000000,2) return (False, f'Could not decode JSON log file: {e}')
receiver_bitrate_ul = round(filename['end']['streams'][0]['receiver']['bits_per_second']/1000000,2) except KeyError as e:
sender_bitrate_dl = round(filename['end']['streams'][1]['sender']['bits_per_second']/1000000,2) e_msg = results.get('error', f'error report not found in {filename}')
receiver_bitrate_dl = round(filename['end']['streams'][1]['receiver']['bits_per_second']/1000000,2) return (False, f'While parsing Iperf3 results: missing key {e}, {e_msg}')
except Exception as e: except Exception as e:
return (False, 'Could not compute BIDIR bitrate!') return (False, f'While parsing Iperf3 results: exception: {e}')
msg = f'Sender Bitrate DL : {sender_bitrate_dl} Mbps\n' msg = f'Sender Bitrate DL : {sender_bitrate_dl} Mbps\n'
msg += f'Receiver Bitrate DL : {receiver_bitrate_dl} Mbps\n' msg += f'Receiver Bitrate DL : {receiver_bitrate_dl} Mbps\n'
......
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