mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
fix and tests for unknown or unparsable errors
This commit is contained in:
@ -364,7 +364,7 @@ def _linux_parse(data):
|
||||
continue
|
||||
|
||||
# normal responses
|
||||
else:
|
||||
elif ' bytes from ' in line:
|
||||
try:
|
||||
line = line.replace('(', ' ').replace(')', ' ').replace('=', ' ')
|
||||
|
||||
@ -547,9 +547,10 @@ def _bsd_parse(data):
|
||||
continue
|
||||
|
||||
# normal response
|
||||
else:
|
||||
elif ' bytes from ' in line:
|
||||
try:
|
||||
line = line.replace(':', ' ').replace('=', ' ')
|
||||
|
||||
response = {
|
||||
'type': 'reply',
|
||||
'bytes': line.split()[0],
|
||||
@ -568,7 +569,7 @@ def _bsd_parse(data):
|
||||
continue
|
||||
|
||||
# ipv6 lines
|
||||
else:
|
||||
elif ' bytes from ' in line:
|
||||
try:
|
||||
line = line.replace(',', ' ').replace('=', ' ')
|
||||
response = {
|
||||
|
1
tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.json
vendored
Normal file
1
tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"destination_ip":"192.168.1.220","data_bytes":56,"pattern":null,"destination":"192.168.1.220","packets_transmitted":8,"packets_received":0,"packet_loss_percent":100.0,"duplicates":0,"responses":[{"type":"timeout","icmp_seq":0,"duplicate":false},{"type":"timeout","icmp_seq":1,"duplicate":false},{"type":"unparsable_line","unparsed_line":"92 bytes from fgt1.attlocal.net (192.168.1.220) Destination Network Unreachable"},{"type":"destination_host_unreachable","bytes":92,"response_ip":"192.168.1.220","vr":4,"hl":5,"tos":0,"len":21504,"id":11887,"flg":0,"off":0,"ttl":63,"pro":1,"cks":51248,"src":"192.168.1.221","dst":"192.168.1.220"},{"type":"unparsable_line","unparsed_line":"92 bytes from fgt1.attlocal.net (192.168.1.220) Weird error message"},{"type":"timeout","icmp_seq":2,"duplicate":false},{"type":"timeout","icmp_seq":3,"duplicate":false},{"type":"timeout","icmp_seq":4,"duplicate":false},{"type":"destination_host_unreachable","bytes":92,"response_ip":"192.168.1.220","vr":4,"hl":5,"tos":0,"len":21504,"id":40674,"flg":0,"off":0,"ttl":63,"pro":1,"cks":22461,"src":"192.168.1.221","dst":"192.168.1.220"},{"type":"destination_host_unreachable","bytes":92,"response_ip":"192.168.1.220","vr":4,"hl":5,"tos":0,"len":21504,"id":31035,"flg":0,"off":0,"ttl":63,"pro":1,"cks":32100,"src":"192.168.1.221","dst":"192.168.1.220"},{"type":"destination_host_unreachable","bytes":92,"response_ip":"192.168.1.220","vr":4,"hl":5,"tos":0,"len":21504,"id":53536,"flg":0,"off":0,"ttl":63,"pro":1,"cks":9599,"src":"192.168.1.221","dst":"192.168.1.220"},{"type":"timeout","icmp_seq":5,"duplicate":false},{"type":"timeout","icmp_seq":6,"duplicate":false}]}
|
35
tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.out
vendored
Normal file
35
tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.out
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
PING 192.168.1.220 (192.168.1.220): 56 data bytes
|
||||
Request timeout for icmp_seq 0
|
||||
Request timeout for icmp_seq 1
|
||||
92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Network Unreachable
|
||||
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
|
||||
4 5 00 5400 567b 0 0000 3f 01 a024 192.168.1.221 192.168.1.220
|
||||
|
||||
92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Host Unreachable
|
||||
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
|
||||
4 5 00 5400 2e6f 0 0000 3f 01 c830 192.168.1.221 192.168.1.220
|
||||
|
||||
92 bytes from fgt1.attlocal.net (192.168.1.220): Weird error message
|
||||
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
|
||||
4 5 00 5400 a1ed 0 0000 3f 01 54b2 192.168.1.221 192.168.1.220
|
||||
|
||||
Request timeout for icmp_seq 2
|
||||
Request timeout for icmp_seq 3
|
||||
Request timeout for icmp_seq 4
|
||||
92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Host Unreachable
|
||||
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
|
||||
4 5 00 5400 9ee2 0 0000 3f 01 57bd 192.168.1.221 192.168.1.220
|
||||
|
||||
92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Host Unreachable
|
||||
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
|
||||
4 5 00 5400 793b 0 0000 3f 01 7d64 192.168.1.221 192.168.1.220
|
||||
|
||||
92 bytes from fgt1.attlocal.net (192.168.1.220): Destination Host Unreachable
|
||||
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
|
||||
4 5 00 5400 d120 0 0000 3f 01 257f 192.168.1.221 192.168.1.220
|
||||
|
||||
Request timeout for icmp_seq 5
|
||||
Request timeout for icmp_seq 6
|
||||
|
||||
--- 192.168.1.220 ping statistics ---
|
||||
8 packets transmitted, 0 packets received, 100.0% packet loss
|
@ -160,6 +160,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip-unreachable.out'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping_ip_unreachable = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.out'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping_ip_unknown_errors = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping6-hostname-p.out'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping6_hostname_p = f.read()
|
||||
|
||||
@ -342,6 +345,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip-unreachable.json'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping_ip_unreachable_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping-ip-unknown-errors.json'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping_ip_unknown_errors_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping6-hostname-p.json'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping6_hostname_p_json = json.loads(f.read())
|
||||
|
||||
@ -667,6 +673,12 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ping.parse(self.osx_10_14_6_ping_ip_unreachable, quiet=True), self.osx_10_14_6_ping_ip_unreachable_json)
|
||||
|
||||
def test_ping_ip_unknown_errors_osx_10_14_6(self):
|
||||
"""
|
||||
Test 'ping <ip>' with unknown/unparsable errors on osx 10.14.6
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ping.parse(self.osx_10_14_6_ping_ip_unknown_errors, quiet=True), self.osx_10_14_6_ping_ip_unknown_errors_json)
|
||||
|
||||
def test_ping6_hostname_p_osx_10_14_6(self):
|
||||
"""
|
||||
Test 'ping6 <hostname> -p' on osx 10.14.6
|
||||
|
Reference in New Issue
Block a user