Skip to content
Snippets Groups Projects

CI: Improve error handling in Iperf3 JSON analysis functions

Merged Jaroslava Fiedlerova requested to merge ci-iperf3-json-fix into develop
+ 20
26
@@ -95,25 +95,26 @@ def Iperf_ComputeTime(args):
raise Exception('Iperf time not found!')
return int(result.group('iperf_time'))
def Iperf_analyzeV3TCPJson(filename, iperf_tcp_rate_target):
def get_JSON(filename):
try:
with open(filename) as file:
filename = json.load(file)
except FileNotFoundError:
return (False, 'JSON log file not present')
except json.JSONDecodeError:
json_file = json.load(file)
except FileNotFoundError as e:
return (False, f'JSON log file not found: {e}')
except json.JSONDecodeError as e:
if (os.path.getsize(filename)==0):
return (False, 'JSON log file is empty')
return (False, 'Could not decode JSON log file')
return (False, f'Could not decode JSON log file: {e}')
except Exception as e:
return (False, f'Unexpected error: {str(e)}')
return (False, f'Unexpected error: {e}')
return (True, json_file)
def Iperf_analyzeV3TCPJson(filename, iperf_tcp_rate_target):
try:
sender_bitrate = round(filename['end']['streams'][0]['sender']['bits_per_second']/1000000,2)
receiver_bitrate = round(filename['end']['streams'][0]['receiver']['bits_per_second']/1000000,2)
except Exception as e:
return (False, 'Could not compute Iperf3 bitrate!')
return (False, f'Could not compute Iperf3 bitrate: {e}')
snd_msg = f'Sender Bitrate : {sender_bitrate} Mbps'
rcv_msg = f'Receiver Bitrate : {receiver_bitrate} Mbps'
success = True
@@ -126,26 +127,13 @@ def Iperf_analyzeV3TCPJson(filename, iperf_tcp_rate_target):
return(success, f'{snd_msg}\n{rcv_msg}')
def Iperf_analyzeV3BIDIRJson(filename):
try:
with open(filename) as file:
filename = json.load(file)
except FileNotFoundError:
return (False, 'JSON log file not present')
except json.JSONDecodeError:
if (os.path.getsize(filename)==0):
return (False, 'JSON log file is empty')
return (False, 'Could not decode JSON log file')
except Exception as e:
return (False, f'Unexpected error: {str(e)}')
try:
sender_bitrate_ul = round(filename['end']['streams'][0]['sender']['bits_per_second']/1000000,2)
receiver_bitrate_ul = round(filename['end']['streams'][0]['receiver']['bits_per_second']/1000000,2)
sender_bitrate_dl = round(filename['end']['streams'][1]['sender']['bits_per_second']/1000000,2)
receiver_bitrate_dl = round(filename['end']['streams'][1]['receiver']['bits_per_second']/1000000,2)
except Exception as e:
return (False, 'Could not compute BIDIR bitrate!')
return (False, f'Could not compute BIDIR bitrate: {e}')
msg = f'Sender Bitrate DL : {sender_bitrate_dl} Mbps\n'
msg += f'Receiver Bitrate DL : {receiver_bitrate_dl} Mbps\n'
msg += f'Sender Bitrate UL : {sender_bitrate_ul} Mbps\n'
@@ -830,10 +818,16 @@ class OaiCiTest():
cmd_ue.run(f'rm /tmp/{client_filename}', reportNonZero=False)
if udpIperf:
status, msg = Iperf_analyzeV3UDP(client_filename, self.iperf_bitrate_threshold, self.iperf_packetloss_threshold, target_bitrate)
elif bidirIperf:
status, msg = Iperf_analyzeV3BIDIRJson(client_filename)
else:
status, msg = Iperf_analyzeV3TCPJson(client_filename, self.iperf_tcp_rate_target)
# check if collected JSON log is valid, function returns "valid" = indication of json validity and "report" = either valid JSON object or error message
valid, report = get_JSON(client_filename)
if bidirIperf and valid:
status, msg = Iperf_analyzeV3BIDIRJson(report)
elif not bidirIperf and valid:
status, msg = Iperf_analyzeV3TCPJson(report, self.iperf_tcp_rate_target)
else:
status = False
msg = report
logging.info(f'\u001B[1;37;45m iperf result for {ue_header}\u001B[0m')
for l in msg.split('\n'):
Loading