Skip to content

Commit

Permalink
[chores] Remove redundant else in guard clause
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed Jun 22, 2022
1 parent fe92071 commit 3918515
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions openwisp_monitoring/check/classes/iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ def check(self, store=True):
if not device_connection:
logger.warning(f'{device}: connection not properly set, Iperf skipped!')
return
device_connection.connect()
servers = self._get_iperf_servers(device.organization.id)
command = f'iperf3 -c {servers[0]} -J'
res, exit_code = device_connection.connector_instance.exec_command(
command, raise_unexpected_exit=False
)
if store and exit_code != 0:
self.store_result_fail()
device_connection.disconnect()
return
else:
device_connection.connect()
servers = self._get_iperf_servers(device.organization.id)
command = f'iperf3 -c {servers[0]} -J'
result_dict_tcp = self._get_iperf_result(res, mode='TCP')
# UDP
command = f'iperf3 -c {servers[0]} -u -J'
res, exit_code = device_connection.connector_instance.exec_command(
command, raise_unexpected_exit=False
)
Expand All @@ -37,22 +47,11 @@ def check(self, store=True):
device_connection.disconnect()
return
else:
result_dict_tcp = self._get_iperf_result(res, mode='TCP')
# UDP
command = f'iperf3 -c {servers[0]} -u -J'
res, exit_code = device_connection.connector_instance.exec_command(
command, raise_unexpected_exit=False
)
if store and exit_code != 0:
self.store_result_fail()
device_connection.disconnect()
return
else:
result_dict_udp = self._get_iperf_result(res, mode='UDP')
if store:
self.store_result({**result_dict_tcp, **result_dict_udp})
device_connection.disconnect()
return {**result_dict_tcp, **result_dict_udp}
result_dict_udp = self._get_iperf_result(res, mode='UDP')
if store:
self.store_result({**result_dict_tcp, **result_dict_udp})
device_connection.disconnect()
return {**result_dict_tcp, **result_dict_udp}

def _get_device_connection(self, device):
"""
Expand Down

0 comments on commit 3918515

Please sign in to comment.