Skip to content
Commits on Source (6)
......@@ -9,6 +9,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- No release planned at the moment.
## [1.0.2] - 2020-06-09
### Fixed
- Initial version assumed that the ping command puts the packet loss info last. Now we search by keyword in order to parse the ping command on Raspbian OS.
## [1.0.1] - 2020-06-08
### Changed
......@@ -27,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- First release of the software.
[0.0.1]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/v0.0.1
[1.0.0]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/v1.0.0
[1.0.1]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/v1.0.1
\ No newline at end of file
[0.0.1]: https://pypi.org/project/network-statistics-service/0.0.1/
[1.0.0]: https://pypi.org/project/network-statistics-service/1.0.0/
[1.0.1]: https://pypi.org/project/network-statistics-service/1.0.1/
[1.0.2]: https://pypi.org/project/network-statistics-service/1.0.2/
\ No newline at end of file
......@@ -29,9 +29,13 @@ class LatencyStatisticUtils(object):
stats = {}
try:
stats['Loss'] = float(packet_loss_row.split(",")[-1].strip().split()[0][:-1])
return stats
except (IndexError, ValueError) as error:
packet_loss_comma_split = packet_loss_row.split(",")
for info in packet_loss_comma_split:
if "packet loss" in info:
stats['Loss'] = float(info.strip().split()[0][:-1])
return stats
raise CommandOutputFormatException("Could not find packet loss information in latency statistics.")
except (ValueError) as error:
raise CommandOutputFormatException("Ping command output for the packet loss row was not of expected format.\nUnderlaying error: " + str(error))
@staticmethod
......
......@@ -11,6 +11,13 @@ class LatencyStatisticUtilsTest(unittest.TestCase):
actual_output = LatencyStatisticUtils._LatencyStatisticUtils__get_packet_loss_from_command_output(given_input)
self.assertEqual(expected_output, actual_output)
def test_get_packet_loss_from_command_output_complete_input_rasp_version(self):
given_input = '3 packets transmitted, 3 packets received, 0.0% packet loss, time 4006ms'
expected_output = {'Loss': 0}
actual_output = LatencyStatisticUtils._LatencyStatisticUtils__get_packet_loss_from_command_output(given_input)
self.assertEqual(expected_output, actual_output)
def test_get_packet_loss_from_command_output_wrong_input(self):
given_input = 'Some error occured.'
......